Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check payment state after melt error #229

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/stores/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,11 @@ export const useWalletStore = defineStore("wallet", {
try {
// proof management
const serializedSendProofs = proofsStore.serializeProofs(sendProofs);
if (serializedSendProofs == null) {
throw new Error("could not serialize proofs.");
}
proofsStore.setReserved(sendProofs, true);
await this.addOutgoingPendingInvoiceToHistory(quote, serializedSendProofs || undefined)
await this.addOutgoingPendingInvoiceToHistory(quote, serializedSendProofs);

// NUT-08 blank outputs for change
const counter = this.keysetCounter(keysetId);
Expand Down Expand Up @@ -702,22 +705,30 @@ export const useWalletStore = defineStore("wallet", {
);
mintStore.addProofs(changeProofs);
}
if (serializedSendProofs != null) {
tokenStore.addPaidToken({
amount: -amount_paid,
serializedProofs: serializedSendProofs,
unit: mintStore.activeUnit,
mint: mintStore.activeMintUrl,
});
}

tokenStore.addPaidToken({
amount: -amount_paid,
serializedProofs: serializedSendProofs,
unit: mintStore.activeUnit,
mint: mintStore.activeMintUrl,
});

this.updateInvoiceInHistory(quote, { status: "paid", amount: -amount_paid })

this.payInvoiceData.invoice = { sat: 0, memo: "", bolt11: "" };
this.payInvoiceData.show = false;
return data;
} catch (error: any) {
if (isUnloading) {
// NOTE: An error is thrown when the user exits the app while the payment is in progress.
// do not handle the error if the user exits the app
return;
throw error;
}
// get quote and check state
const mintQuote = await mintStore.activeMint().api.checkMeltQuote(quote.quote);
if (mintQuote.state == MeltQuoteState.PAID || mintQuote.state == MeltQuoteState.PENDING) {
console.log("### melt: error, but quote is paid or pending. not rolling back.");
throw error;
}
// roll back proof management and keyset counter
proofsStore.setReserved(sendProofs, false);
Expand Down
Loading