Fix invoice retry even if no payment was attempted

This commit is contained in:
ekzyis 2024-11-27 18:00:35 +01:00
parent 14a92ee5ce
commit 0051c82415
4 changed files with 23 additions and 7 deletions

View File

@ -8,7 +8,7 @@ import Bolt11Info from './bolt11-info'
import { useQuery } from '@apollo/client'
import { INVOICE } from '@/fragments/wallet'
import { FAST_POLL_INTERVAL, SSR } from '@/lib/constants'
import { WalletAggregateError, WalletConfigurationError } from '@/wallets/errors'
import { WalletConfigurationError, WalletPaymentAggregateError } from '@/wallets/errors'
import ItemJob from './item-job'
import Item from './item'
import { CommentFlat } from './comment'
@ -205,7 +205,7 @@ function ActionInfo ({ invoice }) {
function WalletError ({ error }) {
if (!error || error instanceof WalletConfigurationError) return null
if (!(error instanceof WalletAggregateError)) {
if (!(error instanceof WalletPaymentAggregateError)) {
console.error('unexpected wallet error:', error)
return null
}

View File

@ -1,7 +1,7 @@
import { useApolloClient, useLazyQuery, useMutation } from '@apollo/client'
import { useCallback, useState } from 'react'
import { useInvoice, useQrPayment } from './payment'
import { InvoiceCanceledError, InvoiceExpiredError, WalletError } from '@/wallets/errors'
import { InvoiceCanceledError, InvoiceExpiredError, WalletError, WalletPaymentError } from '@/wallets/errors'
import { GET_PAID_ACTION } from '@/fragments/paidAction'
import { useWalletPayment } from '@/wallets/payment'
@ -61,7 +61,10 @@ export function usePaidMutation (mutation,
}
}
walletInvoice = await invoiceHelper.retry(walletInvoice)
const paymentAttempted = walletError instanceof WalletPaymentError
if (paymentAttempted) {
walletInvoice = await invoiceHelper.retry(walletInvoice)
}
return await waitForQrPayment(walletInvoice, walletError, { persistOnNavigate, waitFor })
}, [waitForWalletPayment, waitForQrPayment, invoiceHelper])

View File

@ -61,3 +61,16 @@ export class WalletAggregateError extends WalletError {
this.invoice = invoice
}
}
export class WalletPaymentAggregateError extends WalletPaymentError {
constructor (errors, invoice) {
super('WalletPaymentAggregateError')
this.name = 'WalletPaymentAggregateError'
this.errors = errors
this.invoice = invoice
if (!errors.every(e => e instanceof WalletPaymentError)) {
throw new Error('only WalletPaymentError instances are allowed')
}
}
}

View File

@ -6,8 +6,8 @@ import { useWalletLogger } from '@/components/wallet-logger'
import { useInvoice } from '@/components/payment'
import { FAST_POLL_INTERVAL } from '@/lib/constants'
import {
WalletsNotAvailableError, WalletSenderError, WalletAggregateError, WalletNotEnabledError,
WalletSendNotConfiguredError, WalletPaymentError, WalletError, WalletConfigurationError
WalletsNotAvailableError, WalletSenderError, WalletAggregateError, WalletPaymentAggregateError,
WalletNotEnabledError, WalletSendNotConfiguredError, WalletPaymentError, WalletError
} from '@/wallets/errors'
import { canSend } from './common'
@ -102,7 +102,7 @@ export function useWalletPayment () {
// if we reach this line, no wallet payment succeeded
// only return payment errors
const paymentErrors = walletError.errors.filter(e => e instanceof WalletPaymentError)
throw new WalletAggregateError(paymentErrors, walletInvoice)
throw new WalletPaymentAggregateError(paymentErrors, walletInvoice)
}, [walletsWithPayments, invoiceHelper])
return waitForPayment