Fix invoice retry even if no payment was attempted
This commit is contained in:
parent
14a92ee5ce
commit
0051c82415
@ -8,7 +8,7 @@ import Bolt11Info from './bolt11-info'
|
|||||||
import { useQuery } from '@apollo/client'
|
import { useQuery } from '@apollo/client'
|
||||||
import { INVOICE } from '@/fragments/wallet'
|
import { INVOICE } from '@/fragments/wallet'
|
||||||
import { FAST_POLL_INTERVAL, SSR } from '@/lib/constants'
|
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 ItemJob from './item-job'
|
||||||
import Item from './item'
|
import Item from './item'
|
||||||
import { CommentFlat } from './comment'
|
import { CommentFlat } from './comment'
|
||||||
@ -205,7 +205,7 @@ function ActionInfo ({ invoice }) {
|
|||||||
function WalletError ({ error }) {
|
function WalletError ({ error }) {
|
||||||
if (!error || error instanceof WalletConfigurationError) return null
|
if (!error || error instanceof WalletConfigurationError) return null
|
||||||
|
|
||||||
if (!(error instanceof WalletAggregateError)) {
|
if (!(error instanceof WalletPaymentAggregateError)) {
|
||||||
console.error('unexpected wallet error:', error)
|
console.error('unexpected wallet error:', error)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useApolloClient, useLazyQuery, useMutation } from '@apollo/client'
|
import { useApolloClient, useLazyQuery, useMutation } from '@apollo/client'
|
||||||
import { useCallback, useState } from 'react'
|
import { useCallback, useState } from 'react'
|
||||||
import { useInvoice, useQrPayment } from './payment'
|
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 { GET_PAID_ACTION } from '@/fragments/paidAction'
|
||||||
import { useWalletPayment } from '@/wallets/payment'
|
import { useWalletPayment } from '@/wallets/payment'
|
||||||
|
|
||||||
@ -61,7 +61,10 @@ export function usePaidMutation (mutation,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const paymentAttempted = walletError instanceof WalletPaymentError
|
||||||
|
if (paymentAttempted) {
|
||||||
walletInvoice = await invoiceHelper.retry(walletInvoice)
|
walletInvoice = await invoiceHelper.retry(walletInvoice)
|
||||||
|
}
|
||||||
return await waitForQrPayment(walletInvoice, walletError, { persistOnNavigate, waitFor })
|
return await waitForQrPayment(walletInvoice, walletError, { persistOnNavigate, waitFor })
|
||||||
}, [waitForWalletPayment, waitForQrPayment, invoiceHelper])
|
}, [waitForWalletPayment, waitForQrPayment, invoiceHelper])
|
||||||
|
|
||||||
|
@ -61,3 +61,16 @@ export class WalletAggregateError extends WalletError {
|
|||||||
this.invoice = invoice
|
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')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,8 +6,8 @@ import { useWalletLogger } from '@/components/wallet-logger'
|
|||||||
import { useInvoice } from '@/components/payment'
|
import { useInvoice } from '@/components/payment'
|
||||||
import { FAST_POLL_INTERVAL } from '@/lib/constants'
|
import { FAST_POLL_INTERVAL } from '@/lib/constants'
|
||||||
import {
|
import {
|
||||||
WalletsNotAvailableError, WalletSenderError, WalletAggregateError, WalletNotEnabledError,
|
WalletsNotAvailableError, WalletSenderError, WalletAggregateError, WalletPaymentAggregateError,
|
||||||
WalletSendNotConfiguredError, WalletPaymentError, WalletError, WalletConfigurationError
|
WalletNotEnabledError, WalletSendNotConfiguredError, WalletPaymentError, WalletError
|
||||||
} from '@/wallets/errors'
|
} from '@/wallets/errors'
|
||||||
import { canSend } from './common'
|
import { canSend } from './common'
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ export function useWalletPayment () {
|
|||||||
// if we reach this line, no wallet payment succeeded
|
// if we reach this line, no wallet payment succeeded
|
||||||
// only return payment errors
|
// only return payment errors
|
||||||
const paymentErrors = walletError.errors.filter(e => e instanceof WalletPaymentError)
|
const paymentErrors = walletError.errors.filter(e => e instanceof WalletPaymentError)
|
||||||
throw new WalletAggregateError(paymentErrors, walletInvoice)
|
throw new WalletPaymentAggregateError(paymentErrors, walletInvoice)
|
||||||
}, [walletsWithPayments, invoiceHelper])
|
}, [walletsWithPayments, invoiceHelper])
|
||||||
|
|
||||||
return waitForPayment
|
return waitForPayment
|
||||||
|
Loading…
x
Reference in New Issue
Block a user