add balance updated event
This commit is contained in:
parent
0aec49b25b
commit
15202e5339
2 changed files with 37 additions and 4 deletions
8
cashu.ts
8
cashu.ts
|
|
@ -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?.();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue