chore: nostr-tools zap api breaking change. (#492)

This commit is contained in:
fiatjaf_
2025-08-24 22:12:14 -03:00
committed by GitHub
parent 6b88da3f03
commit 267065ef29
5 changed files with 21 additions and 20 deletions

View File

@@ -66,7 +66,7 @@
"lru-cache": "^11.0.2", "lru-cache": "^11.0.2",
"lucide-react": "^0.469.0", "lucide-react": "^0.469.0",
"next-themes": "^0.4.6", "next-themes": "^0.4.6",
"nostr-tools": "^2.13.0", "nostr-tools": "^2.16.2",
"nstart-modal": "^2.0.0", "nstart-modal": "^2.0.0",
"path-to-regexp": "^8.2.0", "path-to-regexp": "^8.2.0",
"qr-code-styling": "^1.9.2", "qr-code-styling": "^1.9.2",

View File

@@ -43,7 +43,7 @@ export default function TopZaps({ event }: { event: Event }) {
} }
}} }}
pubkey={event.pubkey} pubkey={event.pubkey}
eventId={event.id} event={event}
defaultAmount={zap.amount} defaultAmount={zap.amount}
defaultComment={zap.comment} defaultComment={zap.comment}
/> />

View File

@@ -51,7 +51,7 @@ export default function ZapButton({ event }: { event: Event }) {
event.pubkey, event.pubkey,
defaultZapSats, defaultZapSats,
defaultZapComment, defaultZapComment,
event.id event
) )
// user canceled // user canceled
if (!zapResult) { if (!zapResult) {
@@ -159,7 +159,7 @@ export default function ZapButton({ event }: { event: Event }) {
setZapping(open) setZapping(open)
}} }}
pubkey={event.pubkey} pubkey={event.pubkey}
eventId={event.id} event={event}
/> />
</> </>
) )

View File

@@ -26,19 +26,20 @@ import { useTranslation } from 'react-i18next'
import { toast } from 'sonner' import { toast } from 'sonner'
import UserAvatar from '../UserAvatar' import UserAvatar from '../UserAvatar'
import Username from '../Username' import Username from '../Username'
import { NostrEvent } from 'nostr-tools'
export default function ZapDialog({ export default function ZapDialog({
open, open,
setOpen, setOpen,
pubkey, pubkey,
eventId, event,
defaultAmount, defaultAmount,
defaultComment defaultComment
}: { }: {
open: boolean open: boolean
setOpen: Dispatch<SetStateAction<boolean>> setOpen: Dispatch<SetStateAction<boolean>>
pubkey: string pubkey: string
eventId?: string event?: NostrEvent
defaultAmount?: number defaultAmount?: number
defaultComment?: string defaultComment?: string
}) { }) {
@@ -87,7 +88,7 @@ export default function ZapDialog({
open={open} open={open}
setOpen={setOpen} setOpen={setOpen}
recipient={pubkey} recipient={pubkey}
eventId={eventId} event={event}
defaultAmount={defaultAmount} defaultAmount={defaultAmount}
defaultComment={defaultComment} defaultComment={defaultComment}
/> />
@@ -110,7 +111,7 @@ export default function ZapDialog({
open={open} open={open}
setOpen={setOpen} setOpen={setOpen}
recipient={pubkey} recipient={pubkey}
eventId={eventId} event={event}
defaultAmount={defaultAmount} defaultAmount={defaultAmount}
defaultComment={defaultComment} defaultComment={defaultComment}
/> />
@@ -122,14 +123,14 @@ export default function ZapDialog({
function ZapDialogContent({ function ZapDialogContent({
setOpen, setOpen,
recipient, recipient,
eventId, event,
defaultAmount, defaultAmount,
defaultComment defaultComment
}: { }: {
open: boolean open: boolean
setOpen: Dispatch<SetStateAction<boolean>> setOpen: Dispatch<SetStateAction<boolean>>
recipient: string recipient: string
eventId?: string event?: NostrEvent
defaultAmount?: number defaultAmount?: number
defaultComment?: string defaultComment?: string
}) { }) {
@@ -146,15 +147,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 zapResult = await lightning.zap(pubkey, recipient, sats, comment, eventId, () => const zapResult = await lightning.zap(pubkey, recipient, sats, comment, event, () =>
setOpen(false) setOpen(false)
) )
// user canceled // user canceled
if (!zapResult) { if (!zapResult) {
return return
} }
if (eventId) { if (event) {
noteStatsService.addZap(pubkey, eventId, 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

@@ -11,7 +11,7 @@ import { Invoice } from '@getalby/lightning-tools'
import { bech32 } from '@scure/base' import { bech32 } from '@scure/base'
import { WebLNProvider } from '@webbtc/webln-types' import { WebLNProvider } from '@webbtc/webln-types'
import dayjs from 'dayjs' 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 { SubCloser } from 'nostr-tools/abstract-pool'
import { makeZapRequest } from 'nostr-tools/nip57' import { makeZapRequest } from 'nostr-tools/nip57'
import { utf8Decoder } from 'nostr-tools/utils' import { utf8Decoder } from 'nostr-tools/utils'
@@ -46,7 +46,7 @@ class LightningService {
recipient: string, recipient: string,
sats: number, sats: number,
comment: string, comment: string,
eventId?: 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) {
@@ -70,8 +70,8 @@ class LightningService {
const { callback, lnurl } = zapEndpoint const { callback, lnurl } = zapEndpoint
const amount = sats * 1000 const amount = sats * 1000
const zapRequestDraft = makeZapRequest({ const zapRequestDraft = makeZapRequest({
profile: recipient, event: event,
event: eventId ?? null, pubkey: recipient,
amount, amount,
relays: receiptRelayList.read relays: receiptRelayList.read
.slice(0, 4) .slice(0, 4)
@@ -133,8 +133,8 @@ class LightningService {
'#p': [recipient], '#p': [recipient],
since: dayjs().subtract(1, 'minute').unix() since: dayjs().subtract(1, 'minute').unix()
} }
if (eventId) { if (event) {
filter['#e'] = [eventId] filter['#e'] = [event.id]
} }
subCloser = client.subscribe( subCloser = client.subscribe(
senderRelayList.write.concat(BIG_RELAY_URLS).slice(0, 4), senderRelayList.write.concat(BIG_RELAY_URLS).slice(0, 4),
@@ -226,7 +226,7 @@ class LightningService {
const [name, domain] = profile.lightningAddress.split('@') const [name, domain] = profile.lightningAddress.split('@')
lnurl = new URL(`/.well-known/lnurlp/${name}`, `https://${domain}`).toString() lnurl = new URL(`/.well-known/lnurlp/${name}`, `https://${domain}`).toString()
} else { } else {
const { words } = bech32.decode(profile.lightningAddress, 1000) const { words } = bech32.decode(profile.lightningAddress as any, 1000)
const data = bech32.fromWords(words) const data = bech32.fromWords(words)
lnurl = utf8Decoder.decode(data) lnurl = utf8Decoder.decode(data)
} }