Fix onConfirmation called at every render
This commit is contained in:
parent
9bc5138461
commit
4fe1d416de
@ -20,7 +20,6 @@ export function Invoice ({ invoice, onConfirmation, successVerb }) {
|
|||||||
if (invoice.confirmedAt) {
|
if (invoice.confirmedAt) {
|
||||||
variant = 'confirmed'
|
variant = 'confirmed'
|
||||||
status = `${numWithUnits(invoice.satsReceived, { abbreviate: false })} ${successVerb || 'deposited'}`
|
status = `${numWithUnits(invoice.satsReceived, { abbreviate: false })} ${successVerb || 'deposited'}`
|
||||||
onConfirmation?.(invoice)
|
|
||||||
webLn = false
|
webLn = false
|
||||||
} else if (invoice.cancelled) {
|
} else if (invoice.cancelled) {
|
||||||
variant = 'failed'
|
variant = 'failed'
|
||||||
@ -32,6 +31,12 @@ export function Invoice ({ invoice, onConfirmation, successVerb }) {
|
|||||||
webLn = false
|
webLn = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (invoice.confirmedAt) {
|
||||||
|
onConfirmation?.(invoice)
|
||||||
|
}
|
||||||
|
}, [invoice.confirmedAt])
|
||||||
|
|
||||||
const { nostr } = invoice
|
const { nostr } = invoice
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -150,14 +155,10 @@ export const useInvoiceable = (fn, options = defaultOptions) => {
|
|||||||
const [fnArgs, setFnArgs] = useState()
|
const [fnArgs, setFnArgs] = useState()
|
||||||
|
|
||||||
// fix for bug where `showModal` runs the code for two modals and thus executes `onConfirmation` twice
|
// fix for bug where `showModal` runs the code for two modals and thus executes `onConfirmation` twice
|
||||||
let called = false
|
|
||||||
let errorCount = 0
|
let errorCount = 0
|
||||||
const onConfirmation = useCallback(
|
const onConfirmation = useCallback(
|
||||||
onClose => {
|
onClose => {
|
||||||
called = false
|
|
||||||
return async ({ id, satsReceived, hash }) => {
|
return async ({ id, satsReceived, hash }) => {
|
||||||
if (called) return
|
|
||||||
called = true
|
|
||||||
await sleep(2000)
|
await sleep(2000)
|
||||||
const repeat = () =>
|
const repeat = () =>
|
||||||
fn(satsReceived, ...fnArgs, hash)
|
fn(satsReceived, ...fnArgs, hash)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user