Skip to content

Commit

Permalink
mark payment as pending permanently.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Mar 25, 2019
1 parent c68860c commit 23b5c09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/Payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]})
Expand All @@ -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,
Expand All @@ -65,8 +74,6 @@ export default function Payment() {
.catch(() => {
window.close()
})

setPaymentPending(true)
}

if (paymentPending) {
Expand Down
3 changes: 3 additions & 0 deletions src/predefined-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down

0 comments on commit 23b5c09

Please sign in to comment.