Fix onSuccess called twice
For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice. This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice.
This commit is contained in:
parent
853a389b65
commit
7dda8a1e01
|
@ -43,12 +43,16 @@ export const useAnonymous = (fn, options = defaultOptions) => {
|
||||||
const invoice = data?.createInvoice
|
const invoice = data?.createInvoice
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (invoice) {
|
if (invoice) {
|
||||||
|
// fix for bug where `showModal` runs the code for two modals and thus executes `onSuccess` twice
|
||||||
|
let called = false
|
||||||
showModal(onClose =>
|
showModal(onClose =>
|
||||||
<Invoice
|
<Invoice
|
||||||
id={invoice.id}
|
id={invoice.id}
|
||||||
onConfirmation={
|
onConfirmation={
|
||||||
async ({ satsReceived }) => {
|
async ({ satsReceived }) => {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
|
if (called) return
|
||||||
|
called = true
|
||||||
await fn(satsReceived, ...fnArgs, invoice.hash)
|
await fn(satsReceived, ...fnArgs, invoice.hash)
|
||||||
onClose()
|
onClose()
|
||||||
}, 2000)
|
}, 2000)
|
||||||
|
|
Loading…
Reference in New Issue