From 5cfefc1ca84a95c434c4b441793f11652de8ef35 Mon Sep 17 00:00:00 2001 From: k00b Date: Mon, 26 Aug 2024 13:58:37 -0500 Subject: [PATCH] cancelled failed payment if not showing qr --- components/use-paid-mutation.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/use-paid-mutation.js b/components/use-paid-mutation.js index 43dd7127..83800bfb 100644 --- a/components/use-paid-mutation.js +++ b/components/use-paid-mutation.js @@ -1,6 +1,6 @@ import { useApolloClient, useLazyQuery, useMutation } from '@apollo/client' import { useCallback, useState } from 'react' -import { InvoiceCanceledError, InvoiceExpiredError, useQrPayment, useWalletPayment } from './payment' +import { InvoiceCanceledError, InvoiceExpiredError, useInvoice, useQrPayment, useWalletPayment } from './payment' import { GET_PAID_ACTION } from '@/fragments/paidAction' /* @@ -23,6 +23,7 @@ export function usePaidMutation (mutation, fetchPolicy: 'network-only' }) const waitForWalletPayment = useWalletPayment() + const invoiceHelper = useInvoice() const waitForQrPayment = useQrPayment() const client = useApolloClient() // innerResult is used to store/control the result of the mutation when innerMutate runs @@ -40,12 +41,14 @@ export function usePaidMutation (mutation, err instanceof InvoiceExpiredError) { // bail since qr code payment will also fail // also bail if the payment took more than 1 second + // and cancel the invoice if it's not already canceled so it can be retried + invoiceHelper.cancel(invoice).catch(console.error) throw err } walletError = err } return await waitForQrPayment(invoice, walletError, { persistOnNavigate, waitFor }) - }, [waitForWalletPayment, waitForQrPayment]) + }, [waitForWalletPayment, waitForQrPayment, invoiceHelper]) const innerMutate = useCallback(async ({ onCompleted: innerOnCompleted, ...innerOptions