import { useFetchEvent } from '@/hooks' import { getZapInfoFromEvent } from '@/lib/event-metadata' import { formatAmount } from '@/lib/lightning' import { toNote, toProfile } from '@/lib/link' import { cn } from '@/lib/utils' import { Zap as ZapIcon } from 'lucide-react' import { Event } from 'nostr-tools' import { useMemo } from 'react' import { useTranslation } from 'react-i18next' import { useSecondaryPage } from '@/PageManager' import Username from '../Username' import UserAvatar from '../UserAvatar' export default function Zap({ event, className }: { event: Event; className?: string }) { const { t } = useTranslation() const { push } = useSecondaryPage() const zapInfo = useMemo(() => getZapInfoFromEvent(event), [event]) const { event: targetEvent } = useFetchEvent(zapInfo?.eventId) if (!zapInfo || !zapInfo.senderPubkey || !zapInfo.amount) { return (
[{t('Invalid zap receipt')}]
) } const { senderPubkey, recipientPubkey, amount, comment } = zapInfo return (
{/* Zapped note/profile link in top-right corner */} {(targetEvent || recipientPubkey) && ( )}
{t('zapped')} {recipientPubkey && recipientPubkey !== senderPubkey && ( <> )}
{formatAmount(amount)} {t('sats')}
{comment && (
{comment}
)}
) }