From f55ef859816765e9d9d6d24673c1f189e9d1cf9d Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Mon, 8 Sep 2025 11:38:51 +0000 Subject: [PATCH] fix: from merge --- src/db-sql/migration.ts | 28 +++++++++++++++++++--------- src/libs/util.ts | 20 ++++++++++++++------ src/utils/PlatformServiceMixin.ts | 20 +------------------- src/views/ClaimView.vue | 2 +- src/views/ConfirmGiftView.vue | 2 +- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/db-sql/migration.ts b/src/db-sql/migration.ts index 52cdd589..863254e4 100644 --- a/src/db-sql/migration.ts +++ b/src/db-sql/migration.ts @@ -6,6 +6,12 @@ import { DEFAULT_ENDORSER_API_SERVER } from "@/constants/app"; import { arrayBufferToBase64 } from "@/libs/crypto"; import { logger } from "@/utils/logger"; +// Database result interface for SQLite queries +interface DatabaseResult { + values?: unknown[][]; + [key: string]: unknown; +} + // Generate a random secret for the secret table // It's not really secure to maintain the secret next to the user's data. @@ -122,6 +128,7 @@ const MIGRATIONS = [ id TEXT PRIMARY KEY, blobB64 TEXT ); + CREATE TABLE IF NOT EXISTS migrations ( name TEXT PRIMARY KEY, @@ -177,25 +184,28 @@ export async function runMigrations( try { // Check if we have accounts but no active selection const accountsResult = await sqlQuery("SELECT COUNT(*) FROM accounts"); - const accountsCount = accountsResult - ? (accountsResult.values?.[0]?.[0] as number) - : 0; + const accountsCount = + accountsResult && (accountsResult as DatabaseResult).values + ? ((accountsResult as DatabaseResult).values?.[0]?.[0] as number) + : 0; const activeResult = await sqlQuery( "SELECT activeDid FROM active_identity WHERE id = 1", ); - const activeDid = activeResult - ? (activeResult.values?.[0]?.[0] as string) - : null; + const activeDid = + activeResult && (activeResult as DatabaseResult).values + ? ((activeResult as DatabaseResult).values?.[0]?.[0] as string) + : null; if (accountsCount > 0 && (!activeDid || activeDid === "")) { logger.info("[Migration] Auto-selecting first account as active"); const firstAccountResult = await sqlQuery( "SELECT did FROM accounts ORDER BY dateCreated, did LIMIT 1", ); - const firstAccountDid = firstAccountResult - ? (firstAccountResult.values?.[0]?.[0] as string) - : null; + const firstAccountDid = + firstAccountResult && (firstAccountResult as DatabaseResult).values + ? ((firstAccountResult as DatabaseResult).values?.[0]?.[0] as string) + : null; if (firstAccountDid) { await sqlExec( diff --git a/src/libs/util.ts b/src/libs/util.ts index 4116d0fc..8a30b6e3 100644 --- a/src/libs/util.ts +++ b/src/libs/util.ts @@ -165,18 +165,26 @@ export interface OfferFulfillment { offerType: string; } +interface FulfillmentItem { + "@type": string; + identifier?: string; + [key: string]: unknown; +} + /** * Extract offer fulfillment information from the fulfills field * Handles both array and single object cases */ -export const extractOfferFulfillment = (fulfills: any): OfferFulfillment | null => { +export const extractOfferFulfillment = ( + fulfills: FulfillmentItem | FulfillmentItem[] | null | undefined, +): OfferFulfillment | null => { if (!fulfills) { return null; } - + // Handle both array and single object cases let offerFulfill = null; - + if (Array.isArray(fulfills)) { // Find the Offer in the fulfills array offerFulfill = fulfills.find((item) => item["@type"] === "Offer"); @@ -184,14 +192,14 @@ export const extractOfferFulfillment = (fulfills: any): OfferFulfillment | null // fulfills is a single Offer object offerFulfill = fulfills; } - + if (offerFulfill) { return { - offerHandleId: offerFulfill.identifier, + offerHandleId: offerFulfill.identifier || "", offerType: offerFulfill["@type"], }; } - + return null; }; diff --git a/src/utils/PlatformServiceMixin.ts b/src/utils/PlatformServiceMixin.ts index ca7b5e24..c4ca4801 100644 --- a/src/utils/PlatformServiceMixin.ts +++ b/src/utils/PlatformServiceMixin.ts @@ -749,7 +749,7 @@ export const PlatformServiceMixin = { const result = await this.$dbQuery( "SELECT did FROM accounts ORDER BY dateCreated, did", ); - return result?.values?.map((row) => row[0] as string) || []; + return result?.values?.map((row: unknown[]) => row[0] as string) || []; }, /** @@ -1502,24 +1502,6 @@ export const PlatformServiceMixin = { } }, - /** - * Get all account DIDs - $getAllAccountDids() - * Retrieves all account DIDs from the accounts table - * @returns Promise Array of account DIDs - */ - async $getAllAccountDids(): Promise { - try { - const accounts = await this.$query("SELECT did FROM accounts"); - return accounts.map((account) => account.did); - } catch (error) { - logger.error( - "[PlatformServiceMixin] Error getting all account DIDs:", - error, - ); - return []; - } - }, - // ================================================= // TEMP TABLE METHODS (for temporary storage) // ================================================= diff --git a/src/views/ClaimView.vue b/src/views/ClaimView.vue index c72a0b24..ecace60c 100644 --- a/src/views/ClaimView.vue +++ b/src/views/ClaimView.vue @@ -734,7 +734,7 @@ export default class ClaimView extends Vue { */ extractOfferFulfillment() { this.detailsForGiveOfferFulfillment = libsUtil.extractOfferFulfillment( - this.detailsForGive?.fullClaim?.fulfills + this.detailsForGive?.fullClaim?.fulfills, ); } diff --git a/src/views/ConfirmGiftView.vue b/src/views/ConfirmGiftView.vue index 5c4f11fc..b5cae5e3 100644 --- a/src/views/ConfirmGiftView.vue +++ b/src/views/ConfirmGiftView.vue @@ -724,7 +724,7 @@ export default class ConfirmGiftView extends Vue { */ private extractOfferFulfillment() { this.giveDetailsOfferFulfillment = libsUtil.extractOfferFulfillment( - this.giveDetails?.fullClaim?.fulfills + this.giveDetails?.fullClaim?.fulfills, ); }