Skip to content
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
34 changes: 30 additions & 4 deletions app/features/send/cashu-send-quote-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,27 @@ export class CashuSendQuoteService {

const wallet = account.wallet;

return wallet.meltProofs(meltQuote, sendQuote.proofs, {
keysetId: sendQuote.keysetId,
counter: sendQuote.keysetCounter,
});
return wallet
.meltProofs(meltQuote, sendQuote.proofs, {
keysetId: sendQuote.keysetId,
counter: sendQuote.keysetCounter,
})
.catch(async (error) => {
// Initiate send should be idempotent: if meltProofs was already called once and did not fail,
// then the melt quote will be pending or paid.
const latestMeltQuote = await wallet.checkMeltQuote(sendQuote.quoteId);
if (latestMeltQuote.state !== MeltQuoteState.UNPAID) {
console.warn(
'Initiate send was called but melt quote is not unpaid',
{
sendQuote,
latestMeltQuote,
},
);
return latestMeltQuote;
}
throw error;
});
}

/**
Expand Down Expand Up @@ -428,6 +445,15 @@ export class CashuSendQuoteService {
throw new Error('Account does not match the quote account');
}

const latestMeltQuote = await account.wallet.checkMeltQuote(quote.quoteId);
if (latestMeltQuote.state !== MeltQuoteState.UNPAID) {
// Pending and paid melt quotes should not be failed because that means the send is in progress or has already been completed.
// If the mint fails to pay the melt quote, then the melt quote state will be changed to UNPAID again.
throw new Error(
`Cannot fail melt quote that is not unpaid. Current state for send quote ${quote.id}: ${latestMeltQuote.state}`,
);
}

const updatedAccountProofs = account.proofs.concat(quote.proofs);

await this.cashuSendRepository.fail({
Expand Down