forked from jsnbuchanan/crowd-funder-for-time-pwa
fix: from merge
This commit is contained in:
@@ -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.
|
||||
@@ -123,6 +129,7 @@ const MIGRATIONS = [
|
||||
blobB64 TEXT
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS migrations (
|
||||
name TEXT PRIMARY KEY,
|
||||
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
@@ -177,25 +184,28 @@ export async function runMigrations<T>(
|
||||
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(
|
||||
|
||||
@@ -165,11 +165,19 @@ 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;
|
||||
}
|
||||
@@ -187,7 +195,7 @@ export const extractOfferFulfillment = (fulfills: any): OfferFulfillment | null
|
||||
|
||||
if (offerFulfill) {
|
||||
return {
|
||||
offerHandleId: offerFulfill.identifier,
|
||||
offerHandleId: offerFulfill.identifier || "",
|
||||
offerType: offerFulfill["@type"],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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<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)
|
||||
// =================================================
|
||||
|
||||
@@ -734,7 +734,7 @@ export default class ClaimView extends Vue {
|
||||
*/
|
||||
extractOfferFulfillment() {
|
||||
this.detailsForGiveOfferFulfillment = libsUtil.extractOfferFulfillment(
|
||||
this.detailsForGive?.fullClaim?.fulfills
|
||||
this.detailsForGive?.fullClaim?.fulfills,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -724,7 +724,7 @@ export default class ConfirmGiftView extends Vue {
|
||||
*/
|
||||
private extractOfferFulfillment() {
|
||||
this.giveDetailsOfferFulfillment = libsUtil.extractOfferFulfillment(
|
||||
this.giveDetails?.fullClaim?.fulfills
|
||||
this.giveDetails?.fullClaim?.fulfills,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user