import React from 'react'; import { useNostrEvents, useProfile } from "nostr-react"; import { Card, CardHeader, CardTitle, CardContent, CardFooter, CardDescription } from '@/components/ui/card'; import { NostrEvent, Event, nip19, } from "nostr-tools"; import { Avatar, AvatarImage } from './ui/avatar'; import Link from 'next/link'; interface NotificationProps { event: NostrEvent; } const Notification: React.FC = ({ event }) => { let sender = event.pubkey; let sats = 0; let reactedToId = ''; const { data: userData, isLoading: userDataLoading } = useProfile({ pubkey: sender, }); if (!event) { return null; } if (event.kind === 9735) { for (let tag of event.tags) { if (tag[0] === 'P') { sender = tag[1]; } if (tag[0] === 'bolt11') { let bolt11decoded = require('light-bolt11-decoder').decode(tag[1]); for (let field of bolt11decoded.sections) { if (field.name === 'amount') { sats = field.value / 1000; } } } } } if (event.kind === 7) { for (let tag of event.tags) { if (tag[0] === 'e') { reactedToId = tag[1]; } } } let name = userData?.name ?? nip19.npubEncode(event.pubkey).slice(0, 8) + ':' + nip19.npubEncode(event.pubkey).slice(-3); let createdAt = new Date(event.created_at * 1000); return ( <>
{/* ZAP */} {event.kind === 9735 && (

{sats} sats ⚡️

{name} zapped you

{createdAt.toLocaleDateString() + ' ' + createdAt.toLocaleTimeString()}

)} {/* FOLLOW */} {event.kind === 3 && (

{event.content}

{name} started following you

{createdAt.toLocaleDateString() + ' ' + createdAt.toLocaleTimeString()}

)} {/* REACTION */} {event.kind === 7 && (

{event.content}

{name} reacted to you

{createdAt.toLocaleDateString() + ' ' + createdAt.toLocaleTimeString()}

)}

); } export default Notification;