Merge pull request 'fix(wallet): wire websocket config through module install' (#163) from fix/wallet-websocket-config into dev

Reviewed-on: #163
This commit is contained in:
padreug 2026-09-22 21:06:10 +00:00
commit 717e0bd8ae
2 changed files with 40 additions and 18 deletions

View file

@ -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<WebSocketConfig>
}
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)

View file

@ -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<WebSocketConfig> = {}) {
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) {