diff --git a/src/components/NoteCard.tsx b/src/components/NoteCard.tsx index 6f9659bf..1e3f2812 100644 --- a/src/components/NoteCard.tsx +++ b/src/components/NoteCard.tsx @@ -17,6 +17,13 @@ interface NoteCardProps { className?: string; } +/** Formats a sats amount into a compact human-readable string. */ +function formatSats(sats: number): string { + if (sats >= 1_000_000) return `${(sats / 1_000_000).toFixed(1).replace(/\.0$/, '')}M`; + if (sats >= 1_000) return `${(sats / 1_000).toFixed(1).replace(/\.0$/, '')}K`; + return sats.toString(); +} + /** Extracts image URLs from note content. */ function extractImages(content: string): string[] { const urlRegex = /https?:\/\/[^\s]+\.(jpg|jpeg|png|gif|webp|svg)(\?[^\s]*)?/gi; @@ -164,7 +171,7 @@ export function NoteCard({ event, className }: NoteCardProps) { onClick={(e) => e.stopPropagation()} > - {stats?.zaps ? {stats.zaps} : null} + {stats?.zapAmount ? {formatSats(stats.zapAmount)} : null} {/* More */} diff --git a/src/hooks/useTrending.ts b/src/hooks/useTrending.ts index ddacd8d9..2c77e22f 100644 --- a/src/hooks/useTrending.ts +++ b/src/hooks/useTrending.ts @@ -77,18 +77,27 @@ export function useEventStats(eventId: string | undefined) { let replies = 0; let reposts = 0; let reactions = 0; - let zaps = 0; + let zapAmount = 0; for (const e of events) { switch (e.kind) { case 1: replies++; break; case 6: reposts++; break; case 7: reactions++; break; - case 9735: zaps++; break; + case 9735: { + const amountTag = e.tags.find(([name]) => name === 'amount'); + if (amountTag?.[1]) { + const msats = parseInt(amountTag[1], 10); + if (!isNaN(msats)) { + zapAmount += Math.floor(msats / 1000); + } + } + break; + } } } - return { replies, reposts, reactions, zaps }; + return { replies, reposts, reactions, zapAmount }; }, enabled: !!eventId, staleTime: 60 * 1000,