diff --git a/src/components/Payment.js b/src/components/Payment.js index 7c002ec..846cd1b 100644 --- a/src/components/Payment.js +++ b/src/components/Payment.js @@ -12,14 +12,14 @@ export default function Payment() { let [bolt11, setBolt11] = useState(action.invoice || '') let [doneTyping, setDoneTyping] = useState(!!action.invoice) + let [paymentPending, setPaymentPending] = useState(!!action.pending) let [invoiceData, setInvoiceData] = useState(null) let [satoshiActual, setSatoshiActual] = useState(0) - let [paymentPending, setPaymentPending] = useState(false) useEffect( () => { - if (bolt11 === '' || doneTyping === false) return + if (bolt11 === '' || doneTyping === false || paymentPending) return browser.runtime .sendMessage({tab, rpc: true, method: 'decodepay', params: [bolt11]}) @@ -39,6 +39,15 @@ export default function Payment() { function sendPayment(e) { e.preventDefault() + // set pending + setPaymentPending(true) + browser.runtime.sendMessage({ + tab, + triggerBehaviors: true, + behaviors: ['save-pending-to-current-action'] + }) + + // actually send payment browser.runtime .sendMessage({ tab, @@ -65,8 +74,6 @@ export default function Payment() { .catch(() => { window.close() }) - - setPaymentPending(true) } if (paymentPending) { diff --git a/src/predefined-behaviors.js b/src/predefined-behaviors.js index d0e5190..be38c4f 100644 --- a/src/predefined-behaviors.js +++ b/src/predefined-behaviors.js @@ -10,6 +10,9 @@ const behaviors = { 'navigate-home': (_, __, tabId) => { set(tabId, {type: HOME}) }, + 'save-pending-to-current-action': (_, [action], tabId) => { + set(tabId, {...action, pending: true}) + }, 'return-preimage': ({payment_preimage}, [_, promise]) => { if (promise) promise.resolve(payment_preimage) },