diff --git a/package.json b/package.json index f616ee1..09e0463 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "lru-cache": "^11.0.2", "lucide-react": "^0.469.0", "next-themes": "^0.4.6", - "nostr-tools": "^2.13.0", + "nostr-tools": "^2.16.2", "nstart-modal": "^2.0.0", "path-to-regexp": "^8.2.0", "qr-code-styling": "^1.9.2", diff --git a/src/components/NoteStats/TopZaps.tsx b/src/components/NoteStats/TopZaps.tsx index f3f2438..65d6d5a 100644 --- a/src/components/NoteStats/TopZaps.tsx +++ b/src/components/NoteStats/TopZaps.tsx @@ -43,7 +43,7 @@ export default function TopZaps({ event }: { event: Event }) { } }} pubkey={event.pubkey} - eventId={event.id} + event={event} defaultAmount={zap.amount} defaultComment={zap.comment} /> diff --git a/src/components/NoteStats/ZapButton.tsx b/src/components/NoteStats/ZapButton.tsx index 6889fee..0cbe2a5 100644 --- a/src/components/NoteStats/ZapButton.tsx +++ b/src/components/NoteStats/ZapButton.tsx @@ -51,7 +51,7 @@ export default function ZapButton({ event }: { event: Event }) { event.pubkey, defaultZapSats, defaultZapComment, - event.id + event ) // user canceled if (!zapResult) { @@ -159,7 +159,7 @@ export default function ZapButton({ event }: { event: Event }) { setZapping(open) }} pubkey={event.pubkey} - eventId={event.id} + event={event} /> ) diff --git a/src/components/ZapDialog/index.tsx b/src/components/ZapDialog/index.tsx index 33fc622..f65fb6f 100644 --- a/src/components/ZapDialog/index.tsx +++ b/src/components/ZapDialog/index.tsx @@ -26,19 +26,20 @@ import { useTranslation } from 'react-i18next' import { toast } from 'sonner' import UserAvatar from '../UserAvatar' import Username from '../Username' +import { NostrEvent } from 'nostr-tools' export default function ZapDialog({ open, setOpen, pubkey, - eventId, + event, defaultAmount, defaultComment }: { open: boolean setOpen: Dispatch> pubkey: string - eventId?: string + event?: NostrEvent defaultAmount?: number defaultComment?: string }) { @@ -87,7 +88,7 @@ export default function ZapDialog({ open={open} setOpen={setOpen} recipient={pubkey} - eventId={eventId} + event={event} defaultAmount={defaultAmount} defaultComment={defaultComment} /> @@ -110,7 +111,7 @@ export default function ZapDialog({ open={open} setOpen={setOpen} recipient={pubkey} - eventId={eventId} + event={event} defaultAmount={defaultAmount} defaultComment={defaultComment} /> @@ -122,14 +123,14 @@ export default function ZapDialog({ function ZapDialogContent({ setOpen, recipient, - eventId, + event, defaultAmount, defaultComment }: { open: boolean setOpen: Dispatch> recipient: string - eventId?: string + event?: NostrEvent defaultAmount?: number defaultComment?: string }) { @@ -146,15 +147,15 @@ function ZapDialogContent({ throw new Error('You need to be logged in to zap') } setZapping(true) - const zapResult = await lightning.zap(pubkey, recipient, sats, comment, eventId, () => + const zapResult = await lightning.zap(pubkey, recipient, sats, comment, event, () => setOpen(false) ) // user canceled if (!zapResult) { return } - if (eventId) { - noteStatsService.addZap(pubkey, eventId, zapResult.invoice, sats, comment) + if (event) { + 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 1900950..51fe8df 100644 --- a/src/services/lightning.service.ts +++ b/src/services/lightning.service.ts @@ -11,7 +11,7 @@ import { Invoice } from '@getalby/lightning-tools' import { bech32 } from '@scure/base' import { WebLNProvider } from '@webbtc/webln-types' import dayjs from 'dayjs' -import { Filter, kinds } from 'nostr-tools' +import { Filter, kinds, NostrEvent } from 'nostr-tools' import { SubCloser } from 'nostr-tools/abstract-pool' import { makeZapRequest } from 'nostr-tools/nip57' import { utf8Decoder } from 'nostr-tools/utils' @@ -46,7 +46,7 @@ class LightningService { recipient: string, sats: number, comment: string, - eventId?: string, + event?: NostrEvent, closeOuterModel?: () => void ): Promise<{ preimage: string; invoice: string } | null> { if (!client.signer) { @@ -70,8 +70,8 @@ class LightningService { const { callback, lnurl } = zapEndpoint const amount = sats * 1000 const zapRequestDraft = makeZapRequest({ - profile: recipient, - event: eventId ?? null, + event: event, + pubkey: recipient, amount, relays: receiptRelayList.read .slice(0, 4) @@ -133,8 +133,8 @@ class LightningService { '#p': [recipient], since: dayjs().subtract(1, 'minute').unix() } - if (eventId) { - filter['#e'] = [eventId] + if (event) { + filter['#e'] = [event.id] } subCloser = client.subscribe( senderRelayList.write.concat(BIG_RELAY_URLS).slice(0, 4), @@ -226,7 +226,7 @@ class LightningService { const [name, domain] = profile.lightningAddress.split('@') lnurl = new URL(`/.well-known/lnurlp/${name}`, `https://${domain}`).toString() } else { - const { words } = bech32.decode(profile.lightningAddress, 1000) + const { words } = bech32.decode(profile.lightningAddress as any, 1000) const data = bech32.fromWords(words) lnurl = utf8Decoder.decode(data) }