fix zap fallback retries in notifications

This commit is contained in:
k00b 2024-11-28 10:48:22 -06:00
parent 6b59e1fa75
commit cb028d217c
3 changed files with 9 additions and 9 deletions

View File

@ -47,16 +47,16 @@ export const useInvoice = () => {
return data.cancelInvoice
}, [cancelInvoice])
const retry = useCallback(async ({ id, hash, hmac }) => {
const retry = useCallback(async ({ id, hash, hmac }, { update }) => {
console.log('retrying invoice:', hash)
const { data, error } = await retryPaidAction({ variables: { invoiceId: Number(id) } })
const { data, error } = await retryPaidAction({ variables: { invoiceId: Number(id) }, update })
if (error) throw error
const newInvoice = data.retryPaidAction.invoice
console.log('new invoice:', newInvoice?.hash)
return newInvoice
})
}, [retryPaidAction])
return { cancel, retry, isInvoice }
}

View File

@ -31,13 +31,13 @@ export function usePaidMutation (mutation,
// innerResult is used to store/control the result of the mutation when innerMutate runs
const [innerResult, setInnerResult] = useState(result)
const waitForPayment = useCallback(async (invoice, { alwaysShowQROnFailure = false, persistOnNavigate = false, waitFor }) => {
const waitForPayment = useCallback(async (invoice, { alwaysShowQROnFailure = false, persistOnNavigate = false, waitFor, update }) => {
let walletError
let walletInvoice = invoice
const start = Date.now()
try {
return await waitForWalletPayment(walletInvoice, waitFor)
return await waitForWalletPayment(walletInvoice, { waitFor, update })
} catch (err) {
walletError = null
if (err instanceof WalletError) {
@ -105,7 +105,7 @@ export function usePaidMutation (mutation,
// onCompleted is called before the invoice is paid for optimistic updates
ourOnCompleted?.(data)
// don't wait to pay the invoice
waitForPayment(invoice, { persistOnNavigate, waitFor }).then((invoice) => {
waitForPayment(invoice, { persistOnNavigate, waitFor, update }).then((invoice) => {
// invoice might have been retried during payment
data = {
[dataKey]: {
@ -135,7 +135,7 @@ export function usePaidMutation (mutation,
try {
// wait for the invoice to be paid
// returns the invoice that was paid since it might have been updated via retries
invoice = await waitForPayment(invoice, { alwaysShowQROnFailure: true, persistOnNavigate, waitFor })
invoice = await waitForPayment(invoice, { alwaysShowQROnFailure: true, persistOnNavigate, waitFor, update })
if (!response.result) {
// if the mutation didn't return any data, ie pessimistic, we need to fetch it
const { data: { paidAction } } = await getPaidAction({ variables: { invoiceId: parseInt(invoice.id) } })

View File

@ -15,7 +15,7 @@ export function useWalletPayment () {
const sendPayment = useSendPayment()
const invoiceHelper = useInvoice()
return useCallback(async (invoice, { waitFor }) => {
return useCallback(async (invoice, { waitFor, update }) => {
let aggregateError = new WalletAggregateError([])
let latestInvoice = invoice
@ -44,7 +44,7 @@ export function useWalletPayment () {
// is there another wallet to try?
const lastAttempt = i === wallets.length - 1
if (!lastAttempt) {
latestInvoice = await invoiceHelper.retry(latestInvoice)
latestInvoice = await invoiceHelper.retry(latestInvoice, { update })
}
}