make fallback retry cache updates a special case
This commit is contained in:
parent
cb028d217c
commit
105f7b07e5
@ -370,17 +370,8 @@ function useActRetry ({ invoice }) {
|
|||||||
invoice.item.root?.bounty === invoice.satsRequested && invoice.item.root?.mine
|
invoice.item.root?.bounty === invoice.satsRequested && invoice.item.root?.mine
|
||||||
? payBountyCacheMods
|
? payBountyCacheMods
|
||||||
: {}
|
: {}
|
||||||
return useAct({
|
|
||||||
query: RETRY_PAID_ACTION,
|
const update = (cache, { data }) => {
|
||||||
onPayError: (e, cache, { data }) => {
|
|
||||||
paidActionCacheMods?.onPayError?.(e, cache, { data })
|
|
||||||
bountyCacheMods?.onPayError?.(e, cache, { data })
|
|
||||||
},
|
|
||||||
onPaid: (cache, { data }) => {
|
|
||||||
paidActionCacheMods?.onPaid?.(cache, { data })
|
|
||||||
bountyCacheMods?.onPaid?.(cache, { data })
|
|
||||||
},
|
|
||||||
update: (cache, { data }) => {
|
|
||||||
const response = Object.values(data)[0]
|
const response = Object.values(data)[0]
|
||||||
if (!response?.invoice) return
|
if (!response?.invoice) return
|
||||||
cache.modify({
|
cache.modify({
|
||||||
@ -401,6 +392,19 @@ function useActRetry ({ invoice }) {
|
|||||||
paidActionCacheMods?.update?.(cache, { data })
|
paidActionCacheMods?.update?.(cache, { data })
|
||||||
bountyCacheMods?.update?.(cache, { data })
|
bountyCacheMods?.update?.(cache, { data })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return useAct({
|
||||||
|
query: RETRY_PAID_ACTION,
|
||||||
|
onPayError: (e, cache, { data }) => {
|
||||||
|
paidActionCacheMods?.onPayError?.(e, cache, { data })
|
||||||
|
bountyCacheMods?.onPayError?.(e, cache, { data })
|
||||||
|
},
|
||||||
|
onPaid: (cache, { data }) => {
|
||||||
|
paidActionCacheMods?.onPaid?.(cache, { data })
|
||||||
|
bountyCacheMods?.onPaid?.(cache, { data })
|
||||||
|
},
|
||||||
|
update,
|
||||||
|
updateOnFallback: update
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,13 +31,13 @@ export function usePaidMutation (mutation,
|
|||||||
// innerResult is used to store/control the result of the mutation when innerMutate runs
|
// innerResult is used to store/control the result of the mutation when innerMutate runs
|
||||||
const [innerResult, setInnerResult] = useState(result)
|
const [innerResult, setInnerResult] = useState(result)
|
||||||
|
|
||||||
const waitForPayment = useCallback(async (invoice, { alwaysShowQROnFailure = false, persistOnNavigate = false, waitFor, update }) => {
|
const waitForPayment = useCallback(async (invoice, { alwaysShowQROnFailure = false, persistOnNavigate = false, waitFor, updateOnFallback }) => {
|
||||||
let walletError
|
let walletError
|
||||||
let walletInvoice = invoice
|
let walletInvoice = invoice
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await waitForWalletPayment(walletInvoice, { waitFor, update })
|
return await waitForWalletPayment(walletInvoice, { waitFor, updateOnFallback })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
walletError = null
|
walletError = null
|
||||||
if (err instanceof WalletError) {
|
if (err instanceof WalletError) {
|
||||||
@ -63,7 +63,7 @@ export function usePaidMutation (mutation,
|
|||||||
|
|
||||||
const paymentAttempted = walletError instanceof WalletPaymentError
|
const paymentAttempted = walletError instanceof WalletPaymentError
|
||||||
if (paymentAttempted) {
|
if (paymentAttempted) {
|
||||||
walletInvoice = await invoiceHelper.retry(walletInvoice)
|
walletInvoice = await invoiceHelper.retry(walletInvoice, { updateOnFallback })
|
||||||
}
|
}
|
||||||
return await waitForQrPayment(walletInvoice, walletError, { persistOnNavigate, waitFor })
|
return await waitForQrPayment(walletInvoice, walletError, { persistOnNavigate, waitFor })
|
||||||
}, [waitForWalletPayment, waitForQrPayment, invoiceHelper])
|
}, [waitForWalletPayment, waitForQrPayment, invoiceHelper])
|
||||||
@ -77,7 +77,7 @@ export function usePaidMutation (mutation,
|
|||||||
// use the most inner callbacks/options if they exist
|
// use the most inner callbacks/options if they exist
|
||||||
const {
|
const {
|
||||||
onPaid, onPayError, forceWaitForPayment, persistOnNavigate,
|
onPaid, onPayError, forceWaitForPayment, persistOnNavigate,
|
||||||
update, waitFor = inv => inv?.actionState === 'PAID'
|
update, waitFor = inv => inv?.actionState === 'PAID', updateOnFallback
|
||||||
} = { ...options, ...innerOptions }
|
} = { ...options, ...innerOptions }
|
||||||
const ourOnCompleted = innerOnCompleted || onCompleted
|
const ourOnCompleted = innerOnCompleted || onCompleted
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ export function usePaidMutation (mutation,
|
|||||||
// onCompleted is called before the invoice is paid for optimistic updates
|
// onCompleted is called before the invoice is paid for optimistic updates
|
||||||
ourOnCompleted?.(data)
|
ourOnCompleted?.(data)
|
||||||
// don't wait to pay the invoice
|
// don't wait to pay the invoice
|
||||||
waitForPayment(invoice, { persistOnNavigate, waitFor, update }).then((invoice) => {
|
waitForPayment(invoice, { persistOnNavigate, waitFor, updateOnFallback }).then((invoice) => {
|
||||||
// invoice might have been retried during payment
|
// invoice might have been retried during payment
|
||||||
data = {
|
data = {
|
||||||
[dataKey]: {
|
[dataKey]: {
|
||||||
@ -135,7 +135,7 @@ export function usePaidMutation (mutation,
|
|||||||
try {
|
try {
|
||||||
// wait for the invoice to be paid
|
// wait for the invoice to be paid
|
||||||
// returns the invoice that was paid since it might have been updated via retries
|
// returns the invoice that was paid since it might have been updated via retries
|
||||||
invoice = await waitForPayment(invoice, { alwaysShowQROnFailure: true, persistOnNavigate, waitFor, update })
|
invoice = await waitForPayment(invoice, { alwaysShowQROnFailure: true, persistOnNavigate, waitFor, updateOnFallback })
|
||||||
if (!response.result) {
|
if (!response.result) {
|
||||||
// if the mutation didn't return any data, ie pessimistic, we need to fetch it
|
// 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) } })
|
const { data: { paidAction } } = await getPaidAction({ variables: { invoiceId: parseInt(invoice.id) } })
|
||||||
|
@ -15,7 +15,7 @@ export function useWalletPayment () {
|
|||||||
const sendPayment = useSendPayment()
|
const sendPayment = useSendPayment()
|
||||||
const invoiceHelper = useInvoice()
|
const invoiceHelper = useInvoice()
|
||||||
|
|
||||||
return useCallback(async (invoice, { waitFor, update }) => {
|
return useCallback(async (invoice, { waitFor, updateOnFallback }) => {
|
||||||
let aggregateError = new WalletAggregateError([])
|
let aggregateError = new WalletAggregateError([])
|
||||||
let latestInvoice = invoice
|
let latestInvoice = invoice
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ export function useWalletPayment () {
|
|||||||
// is there another wallet to try?
|
// is there another wallet to try?
|
||||||
const lastAttempt = i === wallets.length - 1
|
const lastAttempt = i === wallets.length - 1
|
||||||
if (!lastAttempt) {
|
if (!lastAttempt) {
|
||||||
latestInvoice = await invoiceHelper.retry(latestInvoice, { update })
|
latestInvoice = await invoiceHelper.retry(latestInvoice, { update: updateOnFallback })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user