add balance updated event

This commit is contained in:
Danny Morabito 2025-07-09 13:07:38 +02:00
parent 0aec49b25b
commit 15202e5339
Signed by: dannym
GPG key ID: 7CC8056A5A04557E
2 changed files with 37 additions and 4 deletions

View file

@ -8,6 +8,7 @@ export default class PortalBtcWalletCashu {
private npubCash: NpubCash;
private cashuTxns: CashuTxn[] = [];
private proofs: Proof[] = [];
private onBalanceUpdated: (() => void) | null = null;
get txns() {
return this.cashuTxns;
@ -25,14 +26,14 @@ export default class PortalBtcWalletCashu {
constructor(
mnemonic: string,
private cashuStore: CashuStore,
private meltThreshold: number,
) {
this.npubCash = new NpubCash(mnemonic);
}
async init() {
async init(onBalanceUpdated: () => void) {
this.cashuTxns = await this.cashuStore.getTxns();
this.proofs = await this.cashuStore.getProofs();
this.onBalanceUpdated = onBalanceUpdated;
}
async redeemCashuQuotes() {
@ -52,6 +53,7 @@ export default class PortalBtcWalletCashu {
if (!proofs.done || typeof proofs.value === "undefined") return [];
this.proofs.push(...proofs.value);
await this.persistState();
this.onBalanceUpdated?.();
return proofs.value;
}
@ -83,6 +85,7 @@ export default class PortalBtcWalletCashu {
status: "complete",
});
await this.persistState();
this.onBalanceUpdated?.();
}
async redeemToken(token: string): Promise<void> {
@ -99,5 +102,6 @@ export default class PortalBtcWalletCashu {
status: "complete",
});
await this.persistState();
this.onBalanceUpdated?.();
}
}