import { useFetchEvent } from '@/hooks' import { getZapInfoFromEvent } from '@/lib/event-metadata' import { formatAmount } from '@/lib/lightning' import { cn } from '@/lib/utils' import { Zap } from 'lucide-react' import { Event } from 'nostr-tools' import { useMemo } from 'react' import { useTranslation } from 'react-i18next' import Username from '../Username' export default function ZapPreview({ event, className }: { event: Event; className?: string }) { const { t } = useTranslation() 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 (
{t('zapped')} {recipientPubkey && recipientPubkey !== senderPubkey && ( )}
{comment ? (

{comment}

) : null}
{formatAmount(amount)} {t('sats')}
{targetEvent && (
{t('on note')} {targetEvent.id.substring(0, 8)}...
)}
) }