forked from trent_larson/crowd-funder-for-time-pwa
WIP: Add Create Meeting button for registered users with no meetings
- OnboardMeetingListView now shows Create Meeting button for registered users when meetings.length === 0 - Added createMeeting() method to route to meeting setup page - Maintains "No meetings available" message for unregistered users - Resolves Test User #0 import flow where chair icon should show Create Meeting option - Fixed linter errors in databaseUtil.ts and ImportAccountView.vue
This commit is contained in:
109
src/libs/util.ts
109
src/libs/util.ts
@@ -31,9 +31,9 @@ import { OfferClaim } from "../interfaces/claims";
|
||||
import { createPeerDid } from "../libs/crypto/vc/didPeer";
|
||||
import { registerCredential } from "../libs/crypto/vc/passkeyDidPeer";
|
||||
import { logger } from "../utils/logger";
|
||||
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
||||
import { PlatformServiceFactory } from "../services/PlatformServiceFactory";
|
||||
import { IIdentifier } from "@veramo/core";
|
||||
import { parseJsonField } from "../db/databaseUtil";
|
||||
import { parseJsonField } from "@/db/databaseUtil";
|
||||
import { DEFAULT_ROOT_DERIVATION_PATH } from "./crypto";
|
||||
|
||||
export interface GiverReceiverInputInfo {
|
||||
@@ -603,9 +603,13 @@ export async function saveNewIdentity(
|
||||
mnemonic: string,
|
||||
derivationPath: string,
|
||||
): Promise<void> {
|
||||
console.log("💾 DEBUG: saveNewIdentity called with DID:", identity.did);
|
||||
|
||||
try {
|
||||
// add to the new sql db
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
console.log("💾 DEBUG: Getting secrets from database");
|
||||
|
||||
const secrets = await platformService.dbQuery(
|
||||
`SELECT secretBase64 FROM secret`,
|
||||
);
|
||||
@@ -614,13 +618,19 @@ export async function saveNewIdentity(
|
||||
"No initial encryption supported. We recommend you clear your data and start over.",
|
||||
);
|
||||
}
|
||||
|
||||
const secretBase64 = secrets.values[0][0] as string;
|
||||
console.log("💾 DEBUG: Found secret, encrypting identity");
|
||||
|
||||
const secret = base64ToArrayBuffer(secretBase64);
|
||||
const identityStr = JSON.stringify(identity);
|
||||
const encryptedIdentity = await simpleEncrypt(identityStr, secret);
|
||||
const encryptedMnemonic = await simpleEncrypt(mnemonic, secret);
|
||||
const encryptedIdentityBase64 = arrayBufferToBase64(encryptedIdentity);
|
||||
const encryptedMnemonicBase64 = arrayBufferToBase64(encryptedMnemonic);
|
||||
|
||||
console.log("💾 DEBUG: Inserting account into database");
|
||||
|
||||
const sql = `INSERT INTO accounts (dateCreated, derivationPath, did, identityEncrBase64, mnemonicEncrBase64, publicKeyHex)
|
||||
VALUES (?, ?, ?, ?, ?, ?)`;
|
||||
const params = [
|
||||
@@ -632,9 +642,22 @@ export async function saveNewIdentity(
|
||||
identity.keys[0].publicKeyHex,
|
||||
];
|
||||
await platformService.dbExec(sql, params);
|
||||
console.log("💾 DEBUG: Account inserted successfully");
|
||||
|
||||
console.log("💾 DEBUG: Updating default settings with activeDid");
|
||||
await databaseUtil.updateDefaultSettings({ activeDid: identity.did });
|
||||
console.log("💾 DEBUG: Default settings updated");
|
||||
|
||||
console.log("💾 DEBUG: Inserting DID-specific settings");
|
||||
await databaseUtil.insertDidSpecificSettings(identity.did);
|
||||
console.log("💾 DEBUG: DID-specific settings inserted");
|
||||
|
||||
// Check what was actually created
|
||||
const createdSettings =
|
||||
await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
console.log("💾 DEBUG: Created settings:", createdSettings);
|
||||
} catch (error) {
|
||||
console.log("💾 DEBUG: saveNewIdentity error:", error);
|
||||
logger.error("Failed to update default settings:", error);
|
||||
throw new Error(
|
||||
"Failed to set default settings. Please try again or restart the app.",
|
||||
@@ -911,22 +934,104 @@ export async function importFromMnemonic(
|
||||
derivationPath: string = DEFAULT_ROOT_DERIVATION_PATH,
|
||||
shouldErase: boolean = false,
|
||||
): Promise<void> {
|
||||
console.log("📥 DEBUG: importFromMnemonic called with:", {
|
||||
mnemonicLength: mnemonic.split(" ").length,
|
||||
derivationPath,
|
||||
shouldErase,
|
||||
});
|
||||
|
||||
const mne: string = mnemonic.trim().toLowerCase();
|
||||
console.log("📥 DEBUG: Normalized mnemonic length:", mne.split(" ").length);
|
||||
|
||||
// Check if this is Test User #0
|
||||
const TEST_USER_0_MNEMONIC =
|
||||
"rigid shrug mobile smart veteran half all pond toilet brave review universe ship congress found yard skate elite apology jar uniform subway slender luggage";
|
||||
const isTestUser0 = mne === TEST_USER_0_MNEMONIC;
|
||||
console.log("📥 DEBUG: Is Test User #0:", isTestUser0);
|
||||
|
||||
// Derive address and keys from mnemonic
|
||||
const [address, privateHex, publicHex] = deriveAddress(mne, derivationPath);
|
||||
console.log("📥 DEBUG: Derived address:", address);
|
||||
console.log("📥 DEBUG: Derived DID:", `did:ethr:${address}`);
|
||||
|
||||
// Create new identifier
|
||||
const newId = newIdentifier(address, publicHex, privateHex, derivationPath);
|
||||
console.log("📥 DEBUG: Created new identifier:", {
|
||||
did: newId.did,
|
||||
keysLength: newId.keys.length,
|
||||
});
|
||||
|
||||
// Handle erasures
|
||||
if (shouldErase) {
|
||||
console.log("📥 DEBUG: Erasing existing accounts");
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
await platformService.dbExec("DELETE FROM accounts");
|
||||
}
|
||||
|
||||
// Save the new identity
|
||||
console.log("📥 DEBUG: Calling saveNewIdentity");
|
||||
await saveNewIdentity(newId, mne, derivationPath);
|
||||
console.log("📥 DEBUG: saveNewIdentity completed");
|
||||
|
||||
// Set up Test User #0 specific settings
|
||||
if (isTestUser0) {
|
||||
console.log("📥 DEBUG: Setting up Test User #0 specific settings");
|
||||
|
||||
// First, let's see what's currently in the database
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
const existingResult = await platformService.dbQuery(
|
||||
"SELECT * FROM settings WHERE accountDid = ?",
|
||||
[newId.did],
|
||||
);
|
||||
console.log("📥 DEBUG: Existing settings before update:", existingResult);
|
||||
|
||||
// Let's also see the actual data by mapping it
|
||||
if (existingResult?.values?.length) {
|
||||
const existingData = databaseUtil.mapColumnsToValues(
|
||||
existingResult.columns,
|
||||
existingResult.values,
|
||||
)[0];
|
||||
console.log("📥 DEBUG: Existing settings mapped:", existingData);
|
||||
}
|
||||
|
||||
// Let's also check what's in the master settings
|
||||
const masterResult = await platformService.dbQuery(
|
||||
"SELECT * FROM settings WHERE id = ?",
|
||||
["MASTER"],
|
||||
);
|
||||
console.log("📥 DEBUG: Master settings:", masterResult);
|
||||
|
||||
// Now try the UPDATE with better debugging
|
||||
const updateResult = await databaseUtil.updateDidSpecificSettings(
|
||||
newId.did,
|
||||
{
|
||||
firstName: "User Zero",
|
||||
isRegistered: true,
|
||||
},
|
||||
);
|
||||
console.log("📥 DEBUG: Test User #0 settings update result:", updateResult);
|
||||
|
||||
// Verify the settings were saved
|
||||
const verifyResult = await platformService.dbQuery(
|
||||
"SELECT * FROM settings WHERE accountDid = ?",
|
||||
[newId.did],
|
||||
);
|
||||
console.log("📥 DEBUG: Settings after update attempt:", verifyResult);
|
||||
|
||||
if (verifyResult?.values?.length) {
|
||||
const verifiedData = databaseUtil.mapColumnsToValues(
|
||||
verifyResult.columns,
|
||||
verifyResult.values,
|
||||
)[0];
|
||||
console.log("📥 DEBUG: Settings after update mapped:", verifiedData);
|
||||
}
|
||||
|
||||
console.log("📥 DEBUG: Test User #0 settings applied");
|
||||
}
|
||||
|
||||
// Check what settings were created
|
||||
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
console.log("📥 DEBUG: Final settings after import:", settings);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user