fix issue with cashu wallet always reinitializing

This commit is contained in:
Danny Morabito 2025-07-09 17:53:24 +02:00
parent 2d858727b0
commit 5089dc9365
Signed by: dannym
GPG key ID: 7CC8056A5A04557E

View file

@ -9,16 +9,13 @@ export default class PortalBtcWalletCashu {
private cashuTxns: CashuTxn[] = []; private cashuTxns: CashuTxn[] = [];
private proofs: Proof[] = []; private proofs: Proof[] = [];
private onBalanceUpdated: (() => void) | null = null; private onBalanceUpdated: (() => void) | null = null;
private mint = new CashuMint(PortalBtcWallet.MINT_URL);
private cashuWallet: CashuWallet = new CashuWallet(this.mint);
get txns() { get txns() {
return this.cashuTxns; return this.cashuTxns;
} }
get cashuWallet() {
const mint = new CashuMint(PortalBtcWallet.MINT_URL);
return new CashuWallet(mint);
}
get balance() { get balance() {
return this.proofs.reduce((sum, p) => sum + p.amount, 0); return this.proofs.reduce((sum, p) => sum + p.amount, 0);
} }
@ -66,6 +63,7 @@ export default class PortalBtcWalletCashu {
} }
async meltProofsToPayInvoice(invoice: string) { async meltProofsToPayInvoice(invoice: string) {
await this.cashuWallet.loadMint();
const meltQuote = await this.cashuWallet.createMeltQuote(invoice); const meltQuote = await this.cashuWallet.createMeltQuote(invoice);
const amountToMelt = meltQuote.amount + meltQuote.fee_reserve; const amountToMelt = meltQuote.amount + meltQuote.fee_reserve;
const { keep, send } = await this.cashuWallet.send( const { keep, send } = await this.cashuWallet.send(