Return last attempted invoice in canceled state
This commit is contained in:
parent
7e25e29507
commit
b1cdd953a0
|
@ -42,9 +42,8 @@ export function usePaidMutation (mutation,
|
|||
walletError = null
|
||||
if (err instanceof WalletError) {
|
||||
walletError = err
|
||||
// wallet payment error handling always creates a new invoice to retry
|
||||
// unless no wallet was even able to attempt a payment
|
||||
if (err.newInvoice) walletInvoice = err.newInvoice
|
||||
// get the last invoice that was attempted but failed and was canceled
|
||||
if (err.invoice) walletInvoice = err.invoice
|
||||
}
|
||||
|
||||
const invoiceError = err instanceof InvoiceCanceledError || err instanceof InvoiceExpiredError
|
||||
|
@ -62,6 +61,7 @@ export function usePaidMutation (mutation,
|
|||
}
|
||||
}
|
||||
|
||||
walletInvoice = await invoiceHelper.retry(walletInvoice)
|
||||
return await waitForQrPayment(walletInvoice, walletError, { persistOnNavigate, waitFor })
|
||||
}, [waitForWalletPayment, waitForQrPayment, invoiceHelper])
|
||||
|
||||
|
|
|
@ -54,10 +54,10 @@ export class WalletsNotAvailableError extends WalletConfigurationError {
|
|||
}
|
||||
|
||||
export class WalletAggregateError extends WalletError {
|
||||
constructor (errors, newInvoice) {
|
||||
constructor (errors, invoice) {
|
||||
super('WalletAggregateError')
|
||||
this.name = 'WalletAggregateError'
|
||||
this.errors = errors
|
||||
this.newInvoice = newInvoice
|
||||
this.invoice = invoice
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,20 +33,22 @@ export function useWalletPayment () {
|
|||
}, {})
|
||||
|
||||
const walletsWithPayments = useMemo(() => {
|
||||
return wallets.map(wallet => {
|
||||
const logger = loggers[wallet.def.name]
|
||||
return {
|
||||
...wallet,
|
||||
sendPayment: sendPayment(wallet, logger)
|
||||
}
|
||||
})
|
||||
return wallets
|
||||
.filter(wallet => canSend(wallet))
|
||||
.map(wallet => {
|
||||
const logger = loggers[wallet.def.name]
|
||||
return {
|
||||
...wallet,
|
||||
sendPayment: sendPayment(wallet, logger)
|
||||
}
|
||||
})
|
||||
}, [wallets, loggers])
|
||||
|
||||
const waitForPayment = useCallback(async (invoice, { waitFor }) => {
|
||||
let walletError = new WalletAggregateError([])
|
||||
let walletInvoice = invoice
|
||||
|
||||
for (const wallet of walletsWithPayments) {
|
||||
for (const [i, wallet] of walletsWithPayments.entries()) {
|
||||
const controller = invoiceController(walletInvoice, invoiceHelper.isInvoice)
|
||||
try {
|
||||
return await new Promise((resolve, reject) => {
|
||||
|
@ -63,7 +65,12 @@ export function useWalletPayment () {
|
|||
const paymentAttempt = err instanceof WalletPaymentError
|
||||
if (paymentAttempt) {
|
||||
await invoiceHelper.cancel(walletInvoice)
|
||||
walletInvoice = await invoiceHelper.retry(walletInvoice)
|
||||
|
||||
// is there another wallet to try?
|
||||
const lastAttempt = i === walletsWithPayments.length - 1
|
||||
if (!lastAttempt) {
|
||||
walletInvoice = await invoiceHelper.retry(walletInvoice)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: receiver fallbacks
|
||||
|
|
Loading…
Reference in New Issue