From 7dda8a1e0131d70da08b1e0e625ff7807c3981d8 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sat, 22 Jul 2023 12:49:01 +0200 Subject: [PATCH] Fix onSuccess called twice For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: ) is called twice. This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice. --- lib/anonymous.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/anonymous.js b/lib/anonymous.js index 16d95543..663a1c37 100644 --- a/lib/anonymous.js +++ b/lib/anonymous.js @@ -43,12 +43,16 @@ export const useAnonymous = (fn, options = defaultOptions) => { const invoice = data?.createInvoice useEffect(() => { if (invoice) { + // fix for bug where `showModal` runs the code for two modals and thus executes `onSuccess` twice + let called = false showModal(onClose => { setTimeout(async () => { + if (called) return + called = true await fn(satsReceived, ...fnArgs, invoice.hash) onClose() }, 2000)