import { useFetchEvent } from '@/hooks' import { extractZapInfoFromReceipt } from '@/lib/event' import { formatAmount } from '@/lib/lightning' import { toNote, toProfile } from '@/lib/link' import { cn } from '@/lib/utils' import { useSecondaryPage } from '@/PageManager' import { useNostr } from '@/providers/NostrProvider' import { Zap } from 'lucide-react' import { Event } from 'nostr-tools' import { useMemo } from 'react' import { useTranslation } from 'react-i18next' import ContentPreview from '../../ContentPreview' import { FormattedTimestamp } from '../../FormattedTimestamp' import UserAvatar from '../../UserAvatar' export function ZapNotification({ notification, isNew = false }: { notification: Event isNew?: boolean }) { const { t } = useTranslation() const { push } = useSecondaryPage() const { pubkey } = useNostr() const { senderPubkey, eventId, amount, comment } = useMemo( () => extractZapInfoFromReceipt(notification) ?? ({} as any), [notification] ) const { event, isFetching } = useFetchEvent(eventId) if (!senderPubkey || !amount) return null return (
(eventId ? push(toNote(eventId)) : pubkey ? push(toProfile(pubkey)) : null)} >
{formatAmount(amount)} {t('sats')}
{comment &&
{comment}
} {eventId && !isFetching && ( )}
) }