From 4ea72162ec09563ae4cfa548412ed6dc5b043647 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Fri, 22 Aug 2025 12:10:52 +0000 Subject: [PATCH] fix(active-identity): complete component migration to new Active Identity system Fixes gift recording functionality by migrating remaining components from legacy settings.activeDid to new $getActiveDid() method. Migration 004 dropped settings.activeDid column before all components were updated, causing validation failures in GiftedDialog, OfferDialog, and OnboardingDialog. Added comprehensive logging to $getActiveDid() method and HomeView initialization for debugging. Test "Check User 0 can register a random person" now passes consistently. - GiftedDialog, OfferDialog, OnboardingDialog use new Active Identity system - Enhanced logging in PlatformServiceMixin.$getActiveDid() method - Added debugging logs to HomeView component lifecycle - Fixed Playwright test navigation and element selectors --- src/components/GiftedDialog.vue | 7 +++- src/components/OfferDialog.vue | 3 +- src/components/OnboardingDialog.vue | 3 +- src/utils/PlatformServiceMixin.ts | 39 +++++++++++++++++++ src/views/HomeView.vue | 7 +++- test-playwright/active-identity-smoke.spec.ts | 4 +- 6 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/components/GiftedDialog.vue b/src/components/GiftedDialog.vue index 0b9cd16a..588ebd2a 100644 --- a/src/components/GiftedDialog.vue +++ b/src/components/GiftedDialog.vue @@ -218,7 +218,10 @@ export default class GiftedDialog extends Vue { try { const settings = await this.$settings(); this.apiServer = settings.apiServer || ""; - this.activeDid = settings.activeDid || ""; + // Use new façade method with legacy fallback + const retrievedActiveDid = await this.$getActiveDid(); + this.activeDid = retrievedActiveDid || ""; + logger.debug("[GiftedDialog] Set activeDid from new system:", this.activeDid); this.allContacts = await this.$contacts(); @@ -292,7 +295,9 @@ export default class GiftedDialog extends Vue { } async confirm() { + logger.debug("[GiftedDialog] confirm() called with activeDid:", this.activeDid); if (!this.activeDid) { + logger.error("[GiftedDialog] Validation failed - activeDid is empty/null:", this.activeDid); this.safeNotify.error( NOTIFY_GIFTED_DETAILS_NO_IDENTIFIER.message, TIMEOUTS.SHORT, diff --git a/src/components/OfferDialog.vue b/src/components/OfferDialog.vue index 81664088..31a5879d 100644 --- a/src/components/OfferDialog.vue +++ b/src/components/OfferDialog.vue @@ -175,7 +175,8 @@ export default class OfferDialog extends Vue { const settings = await this.$accountSettings(); this.apiServer = settings.apiServer || ""; - this.activeDid = settings.activeDid || ""; + // Use new façade method with legacy fallback + this.activeDid = (await this.$getActiveDid()) || ""; // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { diff --git a/src/components/OnboardingDialog.vue b/src/components/OnboardingDialog.vue index f6275f12..5f4a8716 100644 --- a/src/components/OnboardingDialog.vue +++ b/src/components/OnboardingDialog.vue @@ -270,7 +270,8 @@ export default class OnboardingDialog extends Vue { async open(page: OnboardPage) { this.page = page; const settings = await this.$accountSettings(); - this.activeDid = settings.activeDid || ""; + // Use new façade method with legacy fallback + this.activeDid = (await this.$getActiveDid()) || ""; this.isRegistered = !!settings.isRegistered; const contacts = await this.$getAllContacts(); diff --git a/src/utils/PlatformServiceMixin.ts b/src/utils/PlatformServiceMixin.ts index ccf56e63..85d4a7a6 100644 --- a/src/utils/PlatformServiceMixin.ts +++ b/src/utils/PlatformServiceMixin.ts @@ -979,13 +979,18 @@ export const PlatformServiceMixin = { */ async $getActiveDid(scope: string = DEFAULT_SCOPE): Promise { try { + logger.debug("[ActiveDid] Getting activeDid for scope:", scope); + // Try new active_identity table first const row = await this.$first( "SELECT active_did FROM active_identity WHERE scope = ? LIMIT 1", [scope], ); + logger.debug("[ActiveDid] New system result:", row?.active_did || "null"); + if (row?.active_did) { + logger.debug("[ActiveDid] Using new system value:", row.active_did); return row.active_did; } @@ -999,9 +1004,43 @@ export const PlatformServiceMixin = { "SELECT activeDid FROM settings WHERE id = ? LIMIT 1", [MASTER_SETTINGS_KEY], ); + + logger.debug("[ActiveDid] Legacy fallback result:", legacy?.activeDid || "null"); return legacy?.activeDid || null; } + logger.debug("[ActiveDid] No fallback available, returning null"); + + // Log current database state for debugging + try { + const activeIdentityCount = await this.$first<{count: number}>( + "SELECT COUNT(*) as count FROM active_identity" + ); + const settingsCount = await this.$first<{count: number}>( + "SELECT COUNT(*) as count FROM settings" + ); + const accountsCount = await this.$first<{count: number}>( + "SELECT COUNT(*) as count FROM accounts" + ); + + // Also check actual values + const activeIdentityValue = await this.$first<{active_did: string}>( + "SELECT active_did FROM active_identity WHERE scope = 'default' LIMIT 1" + ); + const settingsValue = await this.$first<{activeDid: string}>( + "SELECT activeDid FROM settings WHERE id = 1 LIMIT 1" + ); + const firstAccount = await this.$first<{did: string}>( + "SELECT did FROM accounts LIMIT 1" + ); + + logger.debug("[ActiveDid] Database state - active_identity:", activeIdentityCount?.count, "value:", activeIdentityValue?.active_did || "null"); + logger.debug("[ActiveDid] Database state - settings:", settingsCount?.count, "value:", settingsValue?.activeDid || "null"); + logger.debug("[ActiveDid] Database state - accounts:", accountsCount?.count, "first:", firstAccount?.did || "null"); + } catch (dbError) { + logger.debug("[ActiveDid] Could not log database state:", dbError); + } + return null; } catch (error) { logger.error("[PlatformServiceMixin] Error getting activeDid:", error); diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 5388f53e..dd1dceb0 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -454,6 +454,7 @@ export default class HomeView extends Vue { * Called automatically by Vue lifecycle system */ async mounted() { + logger.debug("[HomeView] mounted() starting"); try { await this.initializeIdentity(); // Settings already loaded in initializeIdentity() @@ -494,6 +495,7 @@ export default class HomeView extends Vue { * @throws Logs error if DID retrieval fails */ private async initializeIdentity() { + logger.debug("[HomeView] initializeIdentity() starting"); try { // Retrieve DIDs with better error handling try { @@ -539,7 +541,10 @@ export default class HomeView extends Vue { await this.ensureCorrectApiServer(); // Use new façade method with legacy fallback - this.activeDid = (await this.$getActiveDid()) || ""; + const retrievedActiveDid = await this.$getActiveDid(); + logger.debug("[HomeView] Retrieved activeDid:", retrievedActiveDid); + this.activeDid = retrievedActiveDid || ""; + logger.debug("[HomeView] Set activeDid to:", this.activeDid); // Load contacts with graceful fallback try { diff --git a/test-playwright/active-identity-smoke.spec.ts b/test-playwright/active-identity-smoke.spec.ts index 22afb05a..9648abf8 100644 --- a/test-playwright/active-identity-smoke.spec.ts +++ b/test-playwright/active-identity-smoke.spec.ts @@ -43,11 +43,11 @@ test.describe('Active Identity Migration - Smoke Test', () => { test('should load home page with active identity without errors', async ({ page }) => { // Navigate to home page (which uses our migrated activeDid logic) - await page.goto('./home'); + await page.goto('./'); await page.waitForLoadState('networkidle'); // Verify page loads without errors - await expect(page.locator('h1:has-text("Home")')).toBeVisible(); + await expect(page.locator('#ViewHeading')).toBeVisible(); // This test verifies that: // 1. HomeView.vue loads correctly with our migrated activeDid logic