Browse Source

fix: from merge

pull/188/head
Matthew Raymer 1 week ago
parent
commit
f55ef85981
  1. 28
      src/db-sql/migration.ts
  2. 12
      src/libs/util.ts
  3. 20
      src/utils/PlatformServiceMixin.ts
  4. 2
      src/views/ClaimView.vue
  5. 2
      src/views/ConfirmGiftView.vue

28
src/db-sql/migration.ts

@ -6,6 +6,12 @@ import { DEFAULT_ENDORSER_API_SERVER } from "@/constants/app";
import { arrayBufferToBase64 } from "@/libs/crypto"; import { arrayBufferToBase64 } from "@/libs/crypto";
import { logger } from "@/utils/logger"; 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 // Generate a random secret for the secret table
// It's not really secure to maintain the secret next to the user's data. // It's not really secure to maintain the secret next to the user's data.
@ -123,6 +129,7 @@ const MIGRATIONS = [
blobB64 TEXT blobB64 TEXT
); );
CREATE TABLE IF NOT EXISTS migrations ( CREATE TABLE IF NOT EXISTS migrations (
name TEXT PRIMARY KEY, name TEXT PRIMARY KEY,
applied_at TEXT NOT NULL DEFAULT (datetime('now')) applied_at TEXT NOT NULL DEFAULT (datetime('now'))
@ -177,25 +184,28 @@ export async function runMigrations<T>(
try { try {
// Check if we have accounts but no active selection // Check if we have accounts but no active selection
const accountsResult = await sqlQuery("SELECT COUNT(*) FROM accounts"); const accountsResult = await sqlQuery("SELECT COUNT(*) FROM accounts");
const accountsCount = accountsResult const accountsCount =
? (accountsResult.values?.[0]?.[0] as number) accountsResult && (accountsResult as DatabaseResult).values
: 0; ? ((accountsResult as DatabaseResult).values?.[0]?.[0] as number)
: 0;
const activeResult = await sqlQuery( const activeResult = await sqlQuery(
"SELECT activeDid FROM active_identity WHERE id = 1", "SELECT activeDid FROM active_identity WHERE id = 1",
); );
const activeDid = activeResult const activeDid =
? (activeResult.values?.[0]?.[0] as string) activeResult && (activeResult as DatabaseResult).values
: null; ? ((activeResult as DatabaseResult).values?.[0]?.[0] as string)
: null;
if (accountsCount > 0 && (!activeDid || activeDid === "")) { if (accountsCount > 0 && (!activeDid || activeDid === "")) {
logger.info("[Migration] Auto-selecting first account as active"); logger.info("[Migration] Auto-selecting first account as active");
const firstAccountResult = await sqlQuery( const firstAccountResult = await sqlQuery(
"SELECT did FROM accounts ORDER BY dateCreated, did LIMIT 1", "SELECT did FROM accounts ORDER BY dateCreated, did LIMIT 1",
); );
const firstAccountDid = firstAccountResult const firstAccountDid =
? (firstAccountResult.values?.[0]?.[0] as string) firstAccountResult && (firstAccountResult as DatabaseResult).values
: null; ? ((firstAccountResult as DatabaseResult).values?.[0]?.[0] as string)
: null;
if (firstAccountDid) { if (firstAccountDid) {
await sqlExec( await sqlExec(

12
src/libs/util.ts

@ -165,11 +165,19 @@ export interface OfferFulfillment {
offerType: string; offerType: string;
} }
interface FulfillmentItem {
"@type": string;
identifier?: string;
[key: string]: unknown;
}
/** /**
* Extract offer fulfillment information from the fulfills field * Extract offer fulfillment information from the fulfills field
* Handles both array and single object cases * 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) { if (!fulfills) {
return null; return null;
} }
@ -187,7 +195,7 @@ export const extractOfferFulfillment = (fulfills: any): OfferFulfillment | null
if (offerFulfill) { if (offerFulfill) {
return { return {
offerHandleId: offerFulfill.identifier, offerHandleId: offerFulfill.identifier || "",
offerType: offerFulfill["@type"], offerType: offerFulfill["@type"],
}; };
} }

20
src/utils/PlatformServiceMixin.ts

@ -749,7 +749,7 @@ export const PlatformServiceMixin = {
const result = await this.$dbQuery( const result = await this.$dbQuery(
"SELECT did FROM accounts ORDER BY dateCreated, did", "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<string[]> Array of account DIDs
*/
async $getAllAccountDids(): Promise<string[]> {
try {
const accounts = await this.$query<Account>("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) // TEMP TABLE METHODS (for temporary storage)
// ================================================= // =================================================

2
src/views/ClaimView.vue

@ -734,7 +734,7 @@ export default class ClaimView extends Vue {
*/ */
extractOfferFulfillment() { extractOfferFulfillment() {
this.detailsForGiveOfferFulfillment = libsUtil.extractOfferFulfillment( this.detailsForGiveOfferFulfillment = libsUtil.extractOfferFulfillment(
this.detailsForGive?.fullClaim?.fulfills this.detailsForGive?.fullClaim?.fulfills,
); );
} }

2
src/views/ConfirmGiftView.vue

@ -724,7 +724,7 @@ export default class ConfirmGiftView extends Vue {
*/ */
private extractOfferFulfillment() { private extractOfferFulfillment() {
this.giveDetailsOfferFulfillment = libsUtil.extractOfferFulfillment( this.giveDetailsOfferFulfillment = libsUtil.extractOfferFulfillment(
this.giveDetails?.fullClaim?.fulfills this.giveDetails?.fullClaim?.fulfills,
); );
} }

Loading…
Cancel
Save