diff --git a/src/components/modal/ZapRequestModal.tsx b/src/components/modal/ZapRequestModal.tsx index 21ccb92..181b17e 100644 --- a/src/components/modal/ZapRequestModal.tsx +++ b/src/components/modal/ZapRequestModal.tsx @@ -12,6 +12,8 @@ import { import { createMutation } from '@tanstack/solid-query'; import Bolt from 'heroicons/24/outline/bolt.svg'; +import Check from 'heroicons/24/solid/check.svg'; +import * as Kind from 'nostr-tools/kinds'; import { type Event as NostrEvent } from 'nostr-tools/pure'; import qrcode from 'qrcode'; import { requestProvider, type WebLNProvider } from 'webln'; @@ -23,15 +25,18 @@ import useConfig from '@/core/useConfig'; import { useTranslation } from '@/i18n/useTranslation'; import createZapRequest from '@/nostr/builder/createZapRequest'; import { genericEvent } from '@/nostr/event'; +import ZapReceipt from '@/nostr/event/ZapReceipt'; import { signEvent } from '@/nostr/useCommands'; import useLnurlEndpoint from '@/nostr/useLnurlEndpoint'; import useProfile from '@/nostr/useProfile'; import usePubkey from '@/nostr/usePubkey'; +import useSubscription from '@/nostr/useSubscription'; import fetchLnurlCallback, { type FetchLnurlCallbackParams } from '@/nostr/zap/fetchLnurlCallback'; import lud06ToLnurlPayUrl from '@/nostr/zap/lud06ToLnurlPayUrl'; import lud16ToLnurlPayUrl from '@/nostr/zap/lud16ToLnurlPayUrl'; import verifyInvoice from '@/nostr/zap/verifyInvoice'; import ensureNonNull from '@/utils/ensureNonNull'; +import epoch from '@/utils/epoch'; export type ZapRequestModalProps = { event: NostrEvent; @@ -90,12 +95,34 @@ const QRCodeDisplay: Component<{ text: string }> = (props) => { return ; }; -const InvoiceDisplay: Component<{ invoice: string }> = (props) => { +const InvoiceDisplay: Component<{ invoice: string; event: NostrEvent; nostrPubkey?: string }> = ( + props, +) => { const i18n = useTranslation(); + const { config } = useConfig(); const webln = useWebLN(); const lightingInvoice = () => `lightning:${props.invoice}`; + const { events } = useSubscription(() => + ensureNonNull([props.nostrPubkey] as const)(([nostrPubkey]) => ({ + relayUrls: config().relayUrls, + filters: [ + { + kinds: [Kind.Zap], + authors: nostrPubkey != null ? [nostrPubkey] : undefined, + '#p': [props.event.pubkey], + '#e': [props.event.id], + since: epoch(), + }, + ], + continuous: true, + })), + ); + + const zapped = () => + events().find((ev) => new ZapReceipt(ev).bolt11().paymentRequest === props.invoice); + const handleClickWebLN = () => { const provider = webln.provider(); if (provider == null) return; @@ -112,26 +139,38 @@ const InvoiceDisplay: Component<{ invoice: string }> = (props) => { }; return ( -
+ } + > + + {i18n()('zap.sendViaWallet')} + +