mirror of
https://github.com/hoornet/vega.git
synced 2026-05-10 22:29:11 -07:00
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>
This commit is contained in:
23
src/hooks/useZapCount.ts
Normal file
23
src/hooks/useZapCount.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user