Fix last wallet not returning new invoice

This commit is contained in:
ekzyis 2024-11-26 08:43:05 +01:00
parent 00f9e05dd7
commit 1f2b717da9

View File

@ -46,7 +46,7 @@ export function useWalletPayment () {
let walletError = new WalletAggregateError([]) let walletError = new WalletAggregateError([])
let walletInvoice = invoice let walletInvoice = invoice
for (const [index, wallet] of walletsWithPayments.entries()) { for (const wallet of walletsWithPayments) {
const controller = invoiceController(walletInvoice.id, invoiceHelper.isInvoice) const controller = invoiceController(walletInvoice.id, invoiceHelper.isInvoice)
try { try {
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
@ -58,18 +58,13 @@ export function useWalletPayment () {
.catch(reject) .catch(reject)
}) })
} catch (err) { } catch (err) {
// cancel invoice to make sure it cannot be paid later. // cancel invoice to make sure it cannot be paid later and create new invoice to retry.
// we only need to do this if payment was attempted which is not the case if the wallet is not enabled. // we only need to do this if payment was attempted which is not the case if the wallet is not enabled.
const paymentAttempt = err instanceof WalletPaymentError const paymentAttempt = err instanceof WalletPaymentError
if (paymentAttempt) { if (paymentAttempt) {
await invoiceHelper.cancel(walletInvoice) await invoiceHelper.cancel(walletInvoice)
// only create new invoice via retry if there is another wallet to try
const lastWallet = index === walletsWithPayments.length - 1
if (!lastWallet) {
walletInvoice = await invoiceHelper.retry(walletInvoice) walletInvoice = await invoiceHelper.retry(walletInvoice)
} }
}
// TODO: receiver fallbacks // TODO: receiver fallbacks
// //