diff --git a/src/modules/wallet/index.ts b/src/modules/wallet/index.ts index 1dc1250..f2be67a 100644 --- a/src/modules/wallet/index.ts +++ b/src/modules/wallet/index.ts @@ -2,34 +2,18 @@ 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, type WebSocketConfig } from './services/WalletWebSocketService' +import { WalletWebSocketService } 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, 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. + async install(app: App) { + // Create service instances const walletService = new WalletService() - const walletWebSocketService = new WalletWebSocketService( - options?.config?.websocket ?? {} - ) + const walletWebSocketService = new WalletWebSocketService() // 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 1285a8b..5b332d0 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' -export interface WebSocketConfig { +interface WebSocketConfig { enabled: boolean reconnectDelay: number maxReconnectAttempts: number @@ -13,14 +13,6 @@ export 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', @@ -35,16 +27,12 @@ export class WalletWebSocketService extends BaseService { private stabilityTimer: NodeJS.Timeout | null = null private usingPollingFallback = false private consecutiveFailures = 0 - 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 } + private config: WebSocketConfig = { + enabled: true, + reconnectDelay: 1000, + maxReconnectAttempts: 5, + fallbackToPolling: true, + pollingInterval: 10000 // 10 seconds } // Service dependencies (auto-injected by BaseService) @@ -69,7 +57,13 @@ export class WalletWebSocketService extends BaseService { walletService: !!this.walletService }) - console.log('WalletWebSocketService: Config', this.config) + // 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) // Only proceed if WebSocket is enabled if (!this.config.enabled) {