Compare commits
No commits in common. "717e0bd8aedd049e8ee30d57bd7fa5692c2adab8" and "cfc4e80e2484ede4c7fb030d5ed9298a36a8b99b" have entirely different histories.
717e0bd8ae
...
cfc4e80e24
2 changed files with 18 additions and 40 deletions
|
|
@ -2,34 +2,18 @@ import type { App } from 'vue'
|
||||||
import type { ModulePlugin } from '@/core/types'
|
import type { ModulePlugin } from '@/core/types'
|
||||||
import { container, SERVICE_TOKENS } from '@/core/di-container'
|
import { container, SERVICE_TOKENS } from '@/core/di-container'
|
||||||
import WalletService from './services/WalletService'
|
import WalletService from './services/WalletService'
|
||||||
import { WalletWebSocketService, type WebSocketConfig } from './services/WalletWebSocketService'
|
import { WalletWebSocketService } from './services/WalletWebSocketService'
|
||||||
import { WalletPage, SendDialog, ReceiveDialog, WalletTransactions } from './components'
|
import { WalletPage, SendDialog, ReceiveDialog, WalletTransactions } from './components'
|
||||||
|
|
||||||
export interface WalletModuleConfig {
|
|
||||||
defaultReceiveAmount?: number
|
|
||||||
maxReceiveAmount?: number
|
|
||||||
apiConfig?: { baseUrl?: string }
|
|
||||||
websocket?: Partial<WebSocketConfig>
|
|
||||||
}
|
|
||||||
|
|
||||||
export const walletModule: ModulePlugin = {
|
export const walletModule: ModulePlugin = {
|
||||||
name: 'wallet',
|
name: 'wallet',
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
dependencies: ['base'],
|
dependencies: ['base'],
|
||||||
|
|
||||||
async install(app: App, options?: { config?: WalletModuleConfig }) {
|
async install(app: App) {
|
||||||
// Create service instances.
|
// 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 walletService = new WalletService()
|
||||||
const walletWebSocketService = new WalletWebSocketService(
|
const walletWebSocketService = new WalletWebSocketService()
|
||||||
options?.config?.websocket ?? {}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Register services in DI container BEFORE initialization
|
// Register services in DI container BEFORE initialization
|
||||||
container.provide(SERVICE_TOKENS.WALLET_SERVICE, walletService)
|
container.provide(SERVICE_TOKENS.WALLET_SERVICE, walletService)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { eventBus } from '@/core/event-bus'
|
||||||
import type { Ref } from 'vue'
|
import type { Ref } from 'vue'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
|
||||||
export interface WebSocketConfig {
|
interface WebSocketConfig {
|
||||||
enabled: boolean
|
enabled: boolean
|
||||||
reconnectDelay: number
|
reconnectDelay: number
|
||||||
maxReconnectAttempts: number
|
maxReconnectAttempts: number
|
||||||
|
|
@ -13,14 +13,6 @@ export interface WebSocketConfig {
|
||||||
pollingInterval: number
|
pollingInterval: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_WEBSOCKET_CONFIG: WebSocketConfig = {
|
|
||||||
enabled: true,
|
|
||||||
reconnectDelay: 1000,
|
|
||||||
maxReconnectAttempts: 5,
|
|
||||||
fallbackToPolling: true,
|
|
||||||
pollingInterval: 10000 // 10 seconds
|
|
||||||
}
|
|
||||||
|
|
||||||
export class WalletWebSocketService extends BaseService {
|
export class WalletWebSocketService extends BaseService {
|
||||||
protected readonly metadata = {
|
protected readonly metadata = {
|
||||||
name: 'WalletWebSocketService',
|
name: 'WalletWebSocketService',
|
||||||
|
|
@ -35,16 +27,12 @@ export class WalletWebSocketService extends BaseService {
|
||||||
private stabilityTimer: NodeJS.Timeout | null = null
|
private stabilityTimer: NodeJS.Timeout | null = null
|
||||||
private usingPollingFallback = false
|
private usingPollingFallback = false
|
||||||
private consecutiveFailures = 0
|
private consecutiveFailures = 0
|
||||||
private config: WebSocketConfig
|
private config: WebSocketConfig = {
|
||||||
|
enabled: true,
|
||||||
/**
|
reconnectDelay: 1000,
|
||||||
* @param config Partial overrides from the wallet module's `app.config.ts`,
|
maxReconnectAttempts: 5,
|
||||||
* forwarded by the module's `install()`. Anything omitted falls back to
|
fallbackToPolling: true,
|
||||||
* `DEFAULT_WEBSOCKET_CONFIG`.
|
pollingInterval: 10000 // 10 seconds
|
||||||
*/
|
|
||||||
constructor(config: Partial<WebSocketConfig> = {}) {
|
|
||||||
super()
|
|
||||||
this.config = { ...DEFAULT_WEBSOCKET_CONFIG, ...config }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Service dependencies (auto-injected by BaseService)
|
// Service dependencies (auto-injected by BaseService)
|
||||||
|
|
@ -69,7 +57,13 @@ export class WalletWebSocketService extends BaseService {
|
||||||
walletService: !!this.walletService
|
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
|
// Only proceed if WebSocket is enabled
|
||||||
if (!this.config.enabled) {
|
if (!this.config.enabled) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue