Skip to content

Commit

Permalink
Fix formik bag lost
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Feb 7, 2024
1 parent b38377b commit 172cac1
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions components/invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const useInvoiceable = (onSubmit, options = defaultOptions) => {

const onSubmitWrapper = useCallback(async (
{ cost, ...formValues },
{ variables, optimisticResponse, update, ...apolloArgs }) => {
{ variables, optimisticResponse, update, ...submitArgs }) => {
// some actions require a session
if (!me && options.requireSession) {
throw new Error('you must be logged in')
Expand All @@ -201,7 +201,7 @@ export const useInvoiceable = (onSubmit, options = defaultOptions) => {
try {
const insufficientFunds = me?.privates.sats < cost
return await onSubmit(formValues,
{ variables, optimisticsResponse: insufficientFunds ? null : optimisticResponse, ...apolloArgs })
{ ...submitArgs, variables, optimisticsResponse: insufficientFunds ? null : optimisticResponse })
} catch (error) {
if (!payOrLoginError(error) || !cost) {
// can't handle error here - bail
Expand Down Expand Up @@ -244,20 +244,18 @@ export const useInvoiceable = (onSubmit, options = defaultOptions) => {
}

// wait until invoice is paid or modal is closed
const { modalOnClose, gqlCacheUpdateUndo } = await waitForPayment({
const { modalOnClose, webLn, gqlCacheUpdateUndo } = await waitForPayment({
invoice: inv,
showModal,
provider,
pollInvoice,
gqlCacheUpdate: _update
})

const webLnPayment = !!gqlCacheUpdateUndo

const retry = () => onSubmit(
{ hash: inv.hash, hmac: inv.hmac, ...formValues },
// unset update function since we already ran an cache update if we paid using WebLN
{ variables, update: webLnPayment ? null : undefined })
{ ...submitArgs, variables, update: webLn ? null : undefined })
// first retry
try {
const ret = await retry()
Expand Down Expand Up @@ -335,7 +333,7 @@ const waitForWebLNPayment = async ({ provider, invoice, pollInvoice, gqlCacheUpd
provider.sendPayment(invoice)
// WebLN payment will never resolve here for HODL invoices
// since they only get resolved after settlement which can't happen here
.then(() => resolve({ gqlCacheUpdateUndo: undoUpdate }))
.then(() => resolve({ webLn: true, gqlCacheUpdateUndo: undoUpdate }))
.catch(err => {
clearInterval(interval)
reject(err)
Expand All @@ -350,7 +348,7 @@ const waitForWebLNPayment = async ({ provider, invoice, pollInvoice, gqlCacheUpd
const { invoice: inv } = data
if (inv.isHeld && inv.satsReceived) {
clearInterval(interval)
resolve({ gqlCacheUpdateUndo: undoUpdate })
resolve({ webLn: true, gqlCacheUpdateUndo: undoUpdate })
}
if (inv.cancelled) {
clearInterval(interval)
Expand Down

0 comments on commit 172cac1

Please sign in to comment.