From a62af8bd163dd7e4800be3500e7e86e206e49542 Mon Sep 17 00:00:00 2001 From: Padreug Date: Tue, 22 Sep 2026 22:44:26 +0200 Subject: [PATCH] fix(wallet): wire websocket config through module install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every websocket setting in `app.config.ts` was ignored. The service read `(window as any).appConfig`, which nothing in the codebase ever assigns, so the lookup was always undefined and the service silently ran on its own hardcoded defaults — including `VITE_WEBSOCKET_ENABLED`, which could not actually disable the websocket. The config was already being passed correctly: `src/wallet-app/app.ts` registers the module with `appConfig.modules.wallet`, and the plugin manager forwards it as `install(app, { config })`. The service just wasn't reading from there. It now takes the config through its constructor, merged over an exported `DEFAULT_WEBSOCKET_CONFIG`. Using install options rather than importing `@/app.config` directly matters here: the hub config no longer declares a wallet module at all (the wallet ships only as a standalone PWA), so a direct import would resolve to a config with no wallet section. Verified in the built bundle: `maxReconnectAttempts:3` from `src/wallet-app/app.config.ts` is present alongside the default of 5, and no `window.appConfig` read remains. --- src/modules/wallet/index.ts | 24 ++++++++++--- .../wallet/services/WalletWebSocketService.ts | 34 +++++++++++-------- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/modules/wallet/index.ts b/src/modules/wallet/index.ts index f2be67a..1dc1250 100644 --- a/src/modules/wallet/index.ts +++ b/src/modules/wallet/index.ts @@ -2,18 +2,34 @@ import type { App } from 'vue' import type { ModulePlugin } from '@/core/types' import { container, SERVICE_TOKENS } from '@/core/di-container' import WalletService from './services/WalletService' -import { WalletWebSocketService } from './services/WalletWebSocketService' +import { WalletWebSocketService, type WebSocketConfig } from './services/WalletWebSocketService' import { WalletPage, SendDialog, ReceiveDialog, WalletTransactions } from './components' +export interface WalletModuleConfig { + defaultReceiveAmount?: number + maxReceiveAmount?: number + apiConfig?: { baseUrl?: string } + websocket?: Partial +} + export const walletModule: ModulePlugin = { name: 'wallet', version: '1.0.0', dependencies: ['base'], - async install(app: App) { - // Create service instances + async install(app: App, options?: { config?: WalletModuleConfig }) { + // Create service instances. + // + // The WebSocket config is forwarded from the module registration + // (`pluginManager.register(walletModule, appConfig.modules.wallet)` in + // `src/wallet-app/app.ts`). The service previously tried to read + // `window.appConfig`, which nothing ever assigns, so it silently ran on + // its built-in defaults and every value in `app.config.ts` — including + // `VITE_WEBSOCKET_ENABLED` — was ignored. const walletService = new WalletService() - const walletWebSocketService = new WalletWebSocketService() + const walletWebSocketService = new WalletWebSocketService( + options?.config?.websocket ?? {} + ) // Register services in DI container BEFORE initialization container.provide(SERVICE_TOKENS.WALLET_SERVICE, walletService) diff --git a/src/modules/wallet/services/WalletWebSocketService.ts b/src/modules/wallet/services/WalletWebSocketService.ts index 5b332d0..1285a8b 100644 --- a/src/modules/wallet/services/WalletWebSocketService.ts +++ b/src/modules/wallet/services/WalletWebSocketService.ts @@ -5,7 +5,7 @@ import { eventBus } from '@/core/event-bus' import type { Ref } from 'vue' import { ref } from 'vue' -interface WebSocketConfig { +export interface WebSocketConfig { enabled: boolean reconnectDelay: number maxReconnectAttempts: number @@ -13,6 +13,14 @@ interface WebSocketConfig { pollingInterval: number } +const DEFAULT_WEBSOCKET_CONFIG: WebSocketConfig = { + enabled: true, + reconnectDelay: 1000, + maxReconnectAttempts: 5, + fallbackToPolling: true, + pollingInterval: 10000 // 10 seconds +} + export class WalletWebSocketService extends BaseService { protected readonly metadata = { name: 'WalletWebSocketService', @@ -27,12 +35,16 @@ export class WalletWebSocketService extends BaseService { private stabilityTimer: NodeJS.Timeout | null = null private usingPollingFallback = false private consecutiveFailures = 0 - private config: WebSocketConfig = { - enabled: true, - reconnectDelay: 1000, - maxReconnectAttempts: 5, - fallbackToPolling: true, - pollingInterval: 10000 // 10 seconds + private config: WebSocketConfig + + /** + * @param config Partial overrides from the wallet module's `app.config.ts`, + * forwarded by the module's `install()`. Anything omitted falls back to + * `DEFAULT_WEBSOCKET_CONFIG`. + */ + constructor(config: Partial = {}) { + super() + this.config = { ...DEFAULT_WEBSOCKET_CONFIG, ...config } } // Service dependencies (auto-injected by BaseService) @@ -57,13 +69,7 @@ export class WalletWebSocketService extends BaseService { walletService: !!this.walletService }) - // Load config from app config if available - const appConfig = (window as any).appConfig - if (appConfig?.modules?.wallet?.config?.websocket) { - this.config = { ...this.config, ...appConfig.modules.wallet.config.websocket } - } - - console.log('WalletWebSocketService: Config loaded', this.config) + console.log('WalletWebSocketService: Config', this.config) // Only proceed if WebSocket is enabled if (!this.config.enabled) { -- 2.55.0