Files
vega/src/hooks/useZapCount.ts
Jure af5e04f963 Add zap counts on notes (Phase 1 #2)
- fetchZapCount(eventId): fetches kind 9735 receipts for an event,
  parses millisat amounts from embedded zap request description tags,
  returns { count, totalSats }
- useZapCount hook: session-cached, same pattern as useReactionCount
- NoteCard: zap button shows " N sats" when total > 0, falls back
  to " zap" when no zaps yet; stats row shown for logged-out users
  displaying ♥ and  counts when non-zero

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 20:43:54 +01:00

24 lines
579 B
TypeScript

import { useEffect, useState } from "react";
import { fetchZapCount } from "../lib/nostr";
interface ZapData { count: number; totalSats: number; }
const cache = new Map<string, ZapData>();
export function useZapCount(eventId: string): ZapData | null {
const [data, setData] = useState<ZapData | null>(() => cache.get(eventId) ?? null);
useEffect(() => {
if (cache.has(eventId)) {
setData(cache.get(eventId)!);
return;
}
fetchZapCount(eventId).then((d) => {
cache.set(eventId, d);
setData(d);
});
}, [eventId]);
return data;
}