mirror of
https://github.com/hoornet/vega.git
synced 2026-05-07 12:49:13 -07:00
- 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>
24 lines
579 B
TypeScript
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;
|
|
}
|