From 543b12bcdb715918307c8c22fa230e508e7c3ae1 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Wed, 16 Jul 2025 10:04:36 +0000 Subject: [PATCH] Remove databaseUtil dependency from PlatformServiceMixin - Replace $accountSettings method's databaseUtil import with self-contained implementation - Use existing $getMergedSettings method instead of retrieveSettingsForActiveAccount - Maintain all functionality including Electron-specific API server fixes - Eliminate circular dependency between PlatformServiceMixin and databaseUtil - Fix linting issues with proper formatting and trailing commas - PlatformServiceMixin now completely independent for migration process --- src/utils/PlatformServiceMixin.ts | 52 +++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/src/utils/PlatformServiceMixin.ts b/src/utils/PlatformServiceMixin.ts index 7a442093..678d1b74 100644 --- a/src/utils/PlatformServiceMixin.ts +++ b/src/utils/PlatformServiceMixin.ts @@ -617,19 +617,51 @@ export const PlatformServiceMixin = { did?: string, defaults: Settings = {}, ): Promise { - // Import the working retrieveSettingsForActiveAccount function - const { retrieveSettingsForActiveAccount } = await import( - "@/db/databaseUtil" - ); - try { - // Use the working function that properly merges settings - const settings = await retrieveSettingsForActiveAccount(); + // Get default settings first + const defaultSettings = await this.$getSettings( + MASTER_SETTINGS_KEY, + defaults, + ); - // Merge with any provided defaults - const mergedSettings = { ...defaults, ...settings }; + if (!defaultSettings) { + return defaults; + } - return mergedSettings; + // Determine which DID to use + const targetDid = did || defaultSettings.activeDid; + + // If no target DID, return default settings + if (!targetDid) { + return defaultSettings; + } + + // Get merged settings using existing method + const mergedSettings = await this.$getMergedSettings( + MASTER_SETTINGS_KEY, + targetDid, + defaultSettings, + ); + + // **ELECTRON-SPECIFIC FIX**: Force production API endpoints for Electron + // This ensures Electron doesn't use localhost development servers that might be saved in user settings + if (process.env.VITE_PLATFORM === "electron") { + // Import constants dynamically to get platform-specific values + const { DEFAULT_ENDORSER_API_SERVER } = await import( + "../constants/app" + ); + + mergedSettings.apiServer = DEFAULT_ENDORSER_API_SERVER; + + logger.debug( + `[Electron Settings] Forced API server to: ${DEFAULT_ENDORSER_API_SERVER}`, + ); + } + + // Merge with any provided defaults (these take highest precedence) + const finalSettings = { ...mergedSettings, ...defaults }; + + return finalSettings; } catch (error) { logger.error( "[PlatformServiceMixin] Error in $accountSettings:",