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 { 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.
|
||||||
@@ -122,6 +128,7 @@ const MIGRATIONS = [
|
|||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
blobB64 TEXT
|
blobB64 TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS migrations (
|
CREATE TABLE IF NOT EXISTS migrations (
|
||||||
name TEXT PRIMARY KEY,
|
name TEXT PRIMARY KEY,
|
||||||
@@ -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(
|
||||||
|
|||||||
@@ -165,18 +165,26 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle both array and single object cases
|
// Handle both array and single object cases
|
||||||
let offerFulfill = null;
|
let offerFulfill = null;
|
||||||
|
|
||||||
if (Array.isArray(fulfills)) {
|
if (Array.isArray(fulfills)) {
|
||||||
// Find the Offer in the fulfills array
|
// Find the Offer in the fulfills array
|
||||||
offerFulfill = fulfills.find((item) => item["@type"] === "Offer");
|
offerFulfill = fulfills.find((item) => item["@type"] === "Offer");
|
||||||
@@ -184,14 +192,14 @@ export const extractOfferFulfillment = (fulfills: any): OfferFulfillment | null
|
|||||||
// fulfills is a single Offer object
|
// fulfills is a single Offer object
|
||||||
offerFulfill = fulfills;
|
offerFulfill = fulfills;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offerFulfill) {
|
if (offerFulfill) {
|
||||||
return {
|
return {
|
||||||
offerHandleId: offerFulfill.identifier,
|
offerHandleId: offerFulfill.identifier || "",
|
||||||
offerType: offerFulfill["@type"],
|
offerType: offerFulfill["@type"],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
// =================================================
|
// =================================================
|
||||||
|
|||||||
@@ -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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user