From f181f58425dc5fe5c5d5572e4b6f56bc22d79a1f Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Mon, 16 Feb 2026 17:53:22 -0600 Subject: [PATCH] Show total zap amount (sats) instead of zap count on notes - useEventStats now sums the `amount` tag (millisatoshis) from kind 9735 zap receipts and returns `zapAmount` in sats instead of a zap count - NoteCard displays the total with compact formatting (e.g. 1.2K, 3.5M) Co-authored-by: shakespeare.diy --- src/components/NoteCard.tsx | 9 ++++++++- src/hooks/useTrending.ts | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) 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,