feat: handle user cancellation in zap process
This commit is contained in:
@@ -48,14 +48,18 @@ export default function ZapButton({ event }: { event: Event }) {
|
|||||||
throw new Error('You need to be logged in to zap')
|
throw new Error('You need to be logged in to zap')
|
||||||
}
|
}
|
||||||
setZapping(true)
|
setZapping(true)
|
||||||
const { invoice } = await lightning.zap(
|
const zapResult = await lightning.zap(
|
||||||
pubkey,
|
pubkey,
|
||||||
event.pubkey,
|
event.pubkey,
|
||||||
defaultZapSats,
|
defaultZapSats,
|
||||||
defaultZapComment,
|
defaultZapComment,
|
||||||
event.id
|
event.id
|
||||||
)
|
)
|
||||||
addZap(event.id, invoice, defaultZapSats, defaultZapComment)
|
// user canceled
|
||||||
|
if (!zapResult) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
addZap(event.id, zapResult.invoice, defaultZapSats, defaultZapComment)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
title: t('Zap failed'),
|
title: t('Zap failed'),
|
||||||
|
|||||||
@@ -77,11 +77,15 @@ function ZapDialogContent({
|
|||||||
throw new Error('You need to be logged in to zap')
|
throw new Error('You need to be logged in to zap')
|
||||||
}
|
}
|
||||||
setZapping(true)
|
setZapping(true)
|
||||||
const { invoice } = await lightning.zap(pubkey, recipient, sats, comment, eventId, () =>
|
const zapResult = await lightning.zap(pubkey, recipient, sats, comment, eventId, () =>
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
)
|
)
|
||||||
|
// user canceled
|
||||||
|
if (!zapResult) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (eventId) {
|
if (eventId) {
|
||||||
addZap(eventId, invoice, sats, comment)
|
addZap(eventId, zapResult.invoice, sats, comment)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class LightningService {
|
|||||||
comment: string,
|
comment: string,
|
||||||
eventId?: string,
|
eventId?: string,
|
||||||
closeOuterModel?: () => void
|
closeOuterModel?: () => void
|
||||||
): Promise<{ preimage: string; invoice: string }> {
|
): Promise<{ preimage: string; invoice: string } | null> {
|
||||||
if (!client.signer) {
|
if (!client.signer) {
|
||||||
throw new Error('You need to be logged in to zap')
|
throw new Error('You need to be logged in to zap')
|
||||||
}
|
}
|
||||||
@@ -112,6 +112,7 @@ class LightningService {
|
|||||||
onCancelled: () => {
|
onCancelled: () => {
|
||||||
clearInterval(checkPaymentInterval)
|
clearInterval(checkPaymentInterval)
|
||||||
subCloser?.close()
|
subCloser?.close()
|
||||||
|
resolve(null)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user