fix: resolve zap profile issue

This commit is contained in:
codytseng
2025-08-25 14:27:01 +08:00
parent c04b84a5b6
commit 9aa63fd11c
3 changed files with 9 additions and 13 deletions

View File

@@ -46,13 +46,7 @@ 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 zapResult = await lightning.zap( const zapResult = await lightning.zap(pubkey, event, defaultZapSats, defaultZapComment)
pubkey,
event.pubkey,
defaultZapSats,
defaultZapComment,
event
)
// user canceled // user canceled
if (!zapResult) { if (!zapResult) {
return return

View File

@@ -147,7 +147,7 @@ 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 zapResult = await lightning.zap(pubkey, recipient, sats, comment, event, () => const zapResult = await lightning.zap(pubkey, event ?? recipient, sats, comment, () =>
setOpen(false) setOpen(false)
) )
// user canceled // user canceled
@@ -155,7 +155,7 @@ function ZapDialogContent({
return return
} }
if (event) { if (event) {
noteStatsService.addZap(pubkey, event?.id, zapResult.invoice, sats, comment) noteStatsService.addZap(pubkey, event.id, zapResult.invoice, sats, comment)
} }
} catch (error) { } catch (error) {
toast.error(`${t('Zap failed')}: ${(error as Error).message}`) toast.error(`${t('Zap failed')}: ${(error as Error).message}`)

View File

@@ -45,15 +45,18 @@ class LightningService {
async zap( async zap(
sender: string, sender: string,
recipient: string, recipientOrEvent: string | NostrEvent,
sats: number, sats: number,
comment: string, comment: string,
event?: NostrEvent,
closeOuterModel?: () => void closeOuterModel?: () => void
): Promise<{ preimage: string; invoice: string } | null> { ): 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')
} }
const { recipient, event } =
typeof recipientOrEvent === 'string'
? { recipient: recipientOrEvent }
: { recipient: recipientOrEvent.pubkey, event: recipientOrEvent }
const [profile, receiptRelayList, senderRelayList] = await Promise.all([ const [profile, receiptRelayList, senderRelayList] = await Promise.all([
client.fetchProfile(recipient, true), client.fetchProfile(recipient, true),
@@ -72,8 +75,7 @@ class LightningService {
const { callback, lnurl } = zapEndpoint const { callback, lnurl } = zapEndpoint
const amount = sats * 1000 const amount = sats * 1000
const zapRequestDraft = makeZapRequest({ const zapRequestDraft = makeZapRequest({
event: event, ...(event ? { event } : { pubkey: recipient }),
pubkey: recipient,
amount, amount,
relays: receiptRelayList.read relays: receiptRelayList.read
.slice(0, 4) .slice(0, 4)