diff --git a/src/components/GiftedPrompts.vue b/src/components/GiftedPrompts.vue index 99525f84..58dcd57f 100644 --- a/src/components/GiftedPrompts.vue +++ b/src/components/GiftedPrompts.vue @@ -227,7 +227,7 @@ export default class GivenPrompts extends Vue { let someContactDbIndex = Math.floor(Math.random() * this.numContacts); let count = 0; - + // as long as the index has an entry, loop while ( this.shownContactDbIndices[someContactDbIndex] != null && diff --git a/src/db/databaseUtil.ts b/src/db/databaseUtil.ts index a1f54d98..2fcfbfcb 100644 --- a/src/db/databaseUtil.ts +++ b/src/db/databaseUtil.ts @@ -135,7 +135,7 @@ export async function retrieveSettingsForActiveAccount(): Promise { result.columns, result.values, )[0] as Settings; - + // Debug: Check the actual data types from SQLite logConsoleAndDb( `[DEBUG] Raw SQLite data types for ${defaultSettings.activeDid}:`, @@ -147,7 +147,7 @@ export async function retrieveSettingsForActiveAccount(): Promise { false, ); }); - + const overrideSettingsFiltered = Object.fromEntries( Object.entries(overrideSettings).filter(([_, v]) => v !== null), ); @@ -339,12 +339,15 @@ export function mapColumnsToValues( export async function debugSettingsData(did?: string): Promise { try { const platform = PlatformServiceFactory.getInstance(); - + // Get all settings records const allSettings = await platform.dbQuery("SELECT * FROM settings"); - - logConsoleAndDb(`[DEBUG] Total settings records: ${allSettings?.values?.length || 0}`, false); - + + logConsoleAndDb( + `[DEBUG] Total settings records: ${allSettings?.values?.length || 0}`, + false, + ); + if (allSettings?.values?.length) { allSettings.values.forEach((row, index) => { const settings = mapColumnsToValues(allSettings.columns, [row])[0]; @@ -352,30 +355,50 @@ export async function debugSettingsData(did?: string): Promise { logConsoleAndDb(`[DEBUG] - ID: ${settings.id}`, false); logConsoleAndDb(`[DEBUG] - accountDid: ${settings.accountDid}`, false); logConsoleAndDb(`[DEBUG] - activeDid: ${settings.activeDid}`, false); - + if (settings.searchBoxes) { - logConsoleAndDb(`[DEBUG] - searchBoxes type: ${typeof settings.searchBoxes}`, false); - logConsoleAndDb(`[DEBUG] - searchBoxes value: ${String(settings.searchBoxes)}`, false); - + logConsoleAndDb( + `[DEBUG] - searchBoxes type: ${typeof settings.searchBoxes}`, + false, + ); + logConsoleAndDb( + `[DEBUG] - searchBoxes value: ${String(settings.searchBoxes)}`, + false, + ); + // Try to parse it try { const parsed = JSON.parse(String(settings.searchBoxes)); - logConsoleAndDb(`[DEBUG] - searchBoxes parsed successfully: ${JSON.stringify(parsed)}`, false); + logConsoleAndDb( + `[DEBUG] - searchBoxes parsed successfully: ${JSON.stringify(parsed)}`, + false, + ); } catch (parseError) { - logConsoleAndDb(`[DEBUG] - searchBoxes parse error: ${parseError}`, true); + logConsoleAndDb( + `[DEBUG] - searchBoxes parse error: ${parseError}`, + true, + ); } } - - logConsoleAndDb(`[DEBUG] - Full record: ${JSON.stringify(settings, null, 2)}`, false); + + logConsoleAndDb( + `[DEBUG] - Full record: ${JSON.stringify(settings, null, 2)}`, + false, + ); }); } - + // If specific DID provided, also check accounts table if (did) { - const account = await platform.dbQuery("SELECT * FROM accounts WHERE did = ?", [did]); - logConsoleAndDb(`[DEBUG] Account for ${did}: ${JSON.stringify(account, null, 2)}`, false); + const account = await platform.dbQuery( + "SELECT * FROM accounts WHERE did = ?", + [did], + ); + logConsoleAndDb( + `[DEBUG] Account for ${did}: ${JSON.stringify(account, null, 2)}`, + false, + ); } - } catch (error) { logConsoleAndDb(`[DEBUG] Error inspecting settings data: ${error}`, true); } @@ -386,47 +409,43 @@ export async function debugSettingsData(did?: string): Promise { * Handles different SQLite implementations: * - Web SQLite (wa-sqlite/absurd-sql): Auto-parses JSON strings to objects * - Capacitor SQLite: Returns raw strings that need manual parsing - * + * * @param value The value to parse (could be string or already parsed object) * @param defaultValue Default value if parsing fails * @returns Parsed object or default value * @author Matthew Raymer */ -export function parseJsonField( - value: unknown, - defaultValue: T -): T { +export function parseJsonField(value: unknown, defaultValue: T): T { try { // If already an object (web SQLite auto-parsed), return as-is - if (typeof value === 'object' && value !== null) { + if (typeof value === "object" && value !== null) { logConsoleAndDb( `[DEBUG] JSON field is already an object (auto-parsed by web SQLite), skipping parse`, false, ); return value as T; } - + // If it's a string (Capacitor SQLite or fallback), parse it - if (typeof value === 'string') { + if (typeof value === "string") { logConsoleAndDb( `[DEBUG] JSON field is a string, parsing JSON (Capacitor SQLite or web fallback)`, false, ); return JSON.parse(value) as T; } - + // If it's null/undefined, return default if (value === null || value === undefined) { return defaultValue; } - + // Unexpected type, log and return default logConsoleAndDb( `[DEBUG] JSON field has unexpected type: ${typeof value}, returning default`, true, ); return defaultValue; - } catch (error) { logConsoleAndDb( `[databaseUtil] Failed to parse JSON field: ${error}`, diff --git a/src/libs/util.ts b/src/libs/util.ts index f3b22438..3bc86866 100644 --- a/src/libs/util.ts +++ b/src/libs/util.ts @@ -735,7 +735,9 @@ export const generateSaveAndActivateIdentity = async (): Promise => { const newId = newIdentifier(address, publicHex, privateHex, derivationPath); await saveNewIdentity(newId, mnemonic, derivationPath); - await databaseUtil.updateDidSpecificSettings(newId.did, { isRegistered: false }); + await databaseUtil.updateDidSpecificSettings(newId.did, { + isRegistered: false, + }); if (USE_DEXIE_DB) { await updateAccountSettings(newId.did, { isRegistered: false }); } diff --git a/src/views/ContactEditView.vue b/src/views/ContactEditView.vue index a6197224..e8352120 100644 --- a/src/views/ContactEditView.vue +++ b/src/views/ContactEditView.vue @@ -145,7 +145,6 @@ import { db } from "../db/index"; import { PlatformServiceFactory } from "../services/PlatformServiceFactory"; import { Contact, ContactMethod } from "../db/tables/contacts"; import { AppString } from "../constants/app"; -import { logger } from "../utils/logger"; /** * Contact Edit View Component diff --git a/src/views/ContactImportView.vue b/src/views/ContactImportView.vue index 6bce7b51..f933aee4 100644 --- a/src/views/ContactImportView.vue +++ b/src/views/ContactImportView.vue @@ -223,7 +223,6 @@ import { import { getContactJwtFromJwtUrl } from "../libs/crypto"; import { decodeEndorserJwt } from "../libs/crypto/vc"; import { PlatformServiceFactory } from "@/services/PlatformServiceFactory"; -import { logger } from "../utils/logger"; /** * Interface for contact data as stored in the database diff --git a/src/views/ContactQRScanFullView.vue b/src/views/ContactQRScanFullView.vue index 89d40a2b..64f58829 100644 --- a/src/views/ContactQRScanFullView.vue +++ b/src/views/ContactQRScanFullView.vue @@ -475,7 +475,9 @@ export default class ContactQRScan extends Vue { // Add new contact // @ts-expect-error because we're just using the value to store to the DB - contact.contactMethods = JSON.stringify(parseJsonField(contact.contactMethods, [])); + contact.contactMethods = JSON.stringify( + parseJsonField(contact.contactMethods, []), + ); const { sql, params } = databaseUtil.generateInsertStatement( contact as unknown as Record, "contacts", diff --git a/src/views/ContactQRScanShowView.vue b/src/views/ContactQRScanShowView.vue index edb7282d..6a237414 100644 --- a/src/views/ContactQRScanShowView.vue +++ b/src/views/ContactQRScanShowView.vue @@ -779,7 +779,9 @@ export default class ContactQRScanShow extends Vue { // Add new contact // @ts-expect-error because we're just using the value to store to the DB - contact.contactMethods = JSON.stringify(parseJsonField(contact.contactMethods, [])); + contact.contactMethods = JSON.stringify( + parseJsonField(contact.contactMethods, []), + ); const { sql, params } = databaseUtil.generateInsertStatement( contact as unknown as Record, "contacts", diff --git a/src/views/ContactsView.vue b/src/views/ContactsView.vue index d45cf722..ec923531 100644 --- a/src/views/ContactsView.vue +++ b/src/views/ContactsView.vue @@ -103,8 +103,12 @@ v-if="!showGiveNumbers" :class=" contactsSelected.length > 0 - ? 'text-md bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white ml-3 px-3 py-1.5 rounded-md cursor-pointer' - : 'text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-slate-300 ml-3 px-3 py-1.5 rounded-md cursor-not-allowed' + ? 'text-md bg-gradient-to-b from-blue-400 to-blue-700 ' + + 'shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white ' + + 'ml-3 px-3 py-1.5 rounded-md cursor-pointer' + : 'text-md bg-gradient-to-b from-slate-400 to-slate-700 ' + + 'shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-slate-300 ' + + 'ml-3 px-3 py-1.5 rounded-md cursor-not-allowed' " data-testId="copySelectedContactsButtonTop" @click="copySelectedContacts()" @@ -312,8 +316,12 @@ v-if="!showGiveNumbers" :class=" contactsSelected.length > 0 - ? 'text-md bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white ml-3 px-3 py-1.5 rounded-md cursor-pointer' - : 'text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-slate-300 ml-3 px-3 py-1.5 rounded-md cursor-not-allowed' + ? 'text-md bg-gradient-to-b from-blue-400 to-blue-700 ' + + 'shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white ' + + 'ml-3 px-3 py-1.5 rounded-md cursor-pointer' + : 'text-md bg-gradient-to-b from-slate-400 to-slate-700 ' + + 'shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-slate-300 ' + + 'ml-3 px-3 py-1.5 rounded-md cursor-not-allowed' " @click="copySelectedContacts()" > diff --git a/src/views/SearchAreaView.vue b/src/views/SearchAreaView.vue index 5b21aa05..4646d1f0 100644 --- a/src/views/SearchAreaView.vue +++ b/src/views/SearchAreaView.vue @@ -215,7 +215,7 @@ export default class SearchAreaView extends Vue { if (USE_DEXIE_DB) { await db.open(); await db.settings.update(MASTER_SETTINGS_KEY, { - searchBoxes: searchBoxes as any, // Type assertion for Dexie compatibility + searchBoxes: searchBoxes as unknown, // Type assertion for Dexie compatibility }); } this.searchBox = newSearchBox; @@ -269,7 +269,7 @@ export default class SearchAreaView extends Vue { if (USE_DEXIE_DB) { await db.open(); await db.settings.update(MASTER_SETTINGS_KEY, { - searchBoxes: "[]" as any, // Type assertion for Dexie compatibility + searchBoxes: "[]" as unknown as string, // Type assertion for Dexie compatibility filterFeedByNearby: false, }); }