Implement updateWalletBalance method in PaymentService and deprecate AuthService method

- Added updateWalletBalance method in PaymentService to handle wallet balance updates from WebSocket notifications, improving wallet management.
- Deprecated the existing updateWalletBalance method in AuthService, redirecting calls to the new PaymentService method for better consistency and maintainability.
- Updated WalletWebSocketService to utilize PaymentService for balance updates, ensuring accurate wallet state management.

These changes enhance the architecture of wallet balance handling and streamline the update process across services.
This commit is contained in:
padreug 2025-09-18 09:24:51 +02:00
parent 49e94a894c
commit f93058add2
3 changed files with 45 additions and 27 deletions

View file

@ -117,6 +117,39 @@ export class PaymentService extends BaseService {
return wallet?.inkey || null
}
/**
* Update wallet balance from WebSocket notifications
* @param balanceMsat - The new balance in millisatoshis
* @param walletId - Optional wallet ID (defaults to preferred wallet)
*/
updateWalletBalance(balanceMsat: number, walletId?: string): void {
if (!this.authService?.user?.value?.wallets?.length) {
this.debug('No wallets available to update')
return
}
// Determine which wallet to update
let walletToUpdate
if (walletId) {
walletToUpdate = this.authService.user.value.wallets.find((w: any) => w.id === walletId)
} else {
// Use preferred wallet if no ID specified
walletToUpdate = this.getPreferredWallet()
}
if (walletToUpdate) {
const oldBalance = walletToUpdate.balance_msat
walletToUpdate.balance_msat = balanceMsat
// Trigger reactivity in AuthService
this.authService.user.value = { ...this.authService.user.value }
this.debug(`Wallet ${walletToUpdate.id} balance updated: ${oldBalance} -> ${balanceMsat} msat (${Math.round(balanceMsat/1000)} sats)`)
} else {
this.debug(`Wallet ${walletId} not found for balance update`)
}
}
/**
* Generate QR code for Lightning payment request
*/