From 9aa63fd11ccece6752ea6551892a878952d80b00 Mon Sep 17 00:00:00 2001 From: codytseng Date: Mon, 25 Aug 2025 14:27:01 +0800 Subject: [PATCH] fix: resolve zap profile issue --- src/components/NoteStats/ZapButton.tsx | 8 +------- src/components/ZapDialog/index.tsx | 4 ++-- src/services/lightning.service.ts | 10 ++++++---- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/components/NoteStats/ZapButton.tsx b/src/components/NoteStats/ZapButton.tsx index 0cbe2a58..8dd3d92d 100644 --- a/src/components/NoteStats/ZapButton.tsx +++ b/src/components/NoteStats/ZapButton.tsx @@ -46,13 +46,7 @@ export default function ZapButton({ event }: { event: Event }) { throw new Error('You need to be logged in to zap') } setZapping(true) - const zapResult = await lightning.zap( - pubkey, - event.pubkey, - defaultZapSats, - defaultZapComment, - event - ) + const zapResult = await lightning.zap(pubkey, event, defaultZapSats, defaultZapComment) // user canceled if (!zapResult) { return diff --git a/src/components/ZapDialog/index.tsx b/src/components/ZapDialog/index.tsx index f65fb6f4..f0a12cf4 100644 --- a/src/components/ZapDialog/index.tsx +++ b/src/components/ZapDialog/index.tsx @@ -147,7 +147,7 @@ function ZapDialogContent({ throw new Error('You need to be logged in to zap') } setZapping(true) - const zapResult = await lightning.zap(pubkey, recipient, sats, comment, event, () => + const zapResult = await lightning.zap(pubkey, event ?? recipient, sats, comment, () => setOpen(false) ) // user canceled @@ -155,7 +155,7 @@ function ZapDialogContent({ return } if (event) { - noteStatsService.addZap(pubkey, event?.id, zapResult.invoice, sats, comment) + noteStatsService.addZap(pubkey, event.id, zapResult.invoice, sats, comment) } } catch (error) { toast.error(`${t('Zap failed')}: ${(error as Error).message}`) diff --git a/src/services/lightning.service.ts b/src/services/lightning.service.ts index 99becabe..d63019d2 100644 --- a/src/services/lightning.service.ts +++ b/src/services/lightning.service.ts @@ -45,15 +45,18 @@ class LightningService { async zap( sender: string, - recipient: string, + recipientOrEvent: string | NostrEvent, sats: number, comment: string, - event?: NostrEvent, closeOuterModel?: () => void ): Promise<{ preimage: string; invoice: string } | null> { if (!client.signer) { throw new Error('You need to be logged in to zap') } + const { recipient, event } = + typeof recipientOrEvent === 'string' + ? { recipient: recipientOrEvent } + : { recipient: recipientOrEvent.pubkey, event: recipientOrEvent } const [profile, receiptRelayList, senderRelayList] = await Promise.all([ client.fetchProfile(recipient, true), @@ -72,8 +75,7 @@ class LightningService { const { callback, lnurl } = zapEndpoint const amount = sats * 1000 const zapRequestDraft = makeZapRequest({ - event: event, - pubkey: recipient, + ...(event ? { event } : { pubkey: recipient }), amount, relays: receiptRelayList.read .slice(0, 4)