fix issue with cashu
This commit is contained in:
parent
5089dc9365
commit
b194ace128
2 changed files with 20 additions and 14 deletions
11
cashu.ts
11
cashu.ts
|
@ -34,10 +34,11 @@ export default class PortalBtcWalletCashu {
|
|||
}
|
||||
|
||||
async redeemCashuQuotes() {
|
||||
const attempt = this.npubCash.tryRedeemUnredeemedCashuQuotes(
|
||||
const { proofs, quotes } = await this.npubCash
|
||||
.tryRedeemUnredeemedCashuQuotes(
|
||||
await this.cashuStore.getLastRedeemedCashuQuoteTimestamp(),
|
||||
);
|
||||
for await (const quote of attempt) {
|
||||
for (const quote of quotes) {
|
||||
this.cashuTxns.push({
|
||||
txId: `cashu-quote-${quote.quoteId}`,
|
||||
paymentType: "receive",
|
||||
|
@ -46,12 +47,10 @@ export default class PortalBtcWalletCashu {
|
|||
status: "complete",
|
||||
});
|
||||
}
|
||||
const proofs = await attempt.next();
|
||||
if (!proofs.done || typeof proofs.value === "undefined") return [];
|
||||
this.proofs.push(...proofs.value);
|
||||
this.proofs.push(...proofs);
|
||||
await this.persistState();
|
||||
this.onBalanceUpdated?.();
|
||||
return proofs.value;
|
||||
return proofs;
|
||||
}
|
||||
|
||||
async persistState() {
|
||||
|
|
19
npubCash.ts
19
npubCash.ts
|
@ -89,13 +89,20 @@ export default class NpubCash {
|
|||
);
|
||||
}
|
||||
|
||||
async *tryRedeemUnredeemedCashuQuotes(
|
||||
async tryRedeemUnredeemedCashuQuotes(
|
||||
latestRedeemedCashuQuoteTimestamp: number,
|
||||
) {
|
||||
const proofs: Proof[] = [];
|
||||
const quotes: NpubCashQuote[] = await this.getAllPaidQuotes(
|
||||
latestRedeemedCashuQuoteTimestamp,
|
||||
);
|
||||
const ret = {
|
||||
proofs: [] as Proof[],
|
||||
quotes: [] as {
|
||||
quoteId: string;
|
||||
amountSat: number;
|
||||
timestamp: number;
|
||||
}[],
|
||||
};
|
||||
for (const quote of quotes) {
|
||||
const mint = new CashuMint(quote.mintUrl);
|
||||
const wallet = new CashuWallet(mint);
|
||||
|
@ -107,18 +114,18 @@ export default class NpubCash {
|
|||
quote.amount,
|
||||
quote.quoteId,
|
||||
);
|
||||
proofs.push(...newProofs);
|
||||
ret.proofs.push(...newProofs);
|
||||
const amountReceived = newProofs.reduce(
|
||||
(sum, p) => sum + p.amount,
|
||||
0,
|
||||
);
|
||||
yield {
|
||||
ret.quotes.push({
|
||||
quoteId: quote.quoteId,
|
||||
amountSat: amountReceived,
|
||||
timestamp: quote.paidAt,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
return proofs;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue