snort/packages/app/src/Feed/ZapsFeed.ts

27 lines
822 B
TypeScript
Raw Normal View History

2023-02-03 21:38:14 +00:00
import { useMemo } from "react";
2023-02-10 11:12:11 +00:00
import { HexKey, EventKind, Subscriptions } from "@snort/nostr";
import { parseZap } from "Element/Zap";
2023-02-03 21:38:14 +00:00
import useSubscription from "./Subscription";
export default function useZapsFeed(pubkey: HexKey) {
const sub = useMemo(() => {
2023-02-07 19:47:57 +00:00
const x = new Subscriptions();
x.Id = `zaps:${pubkey.slice(0, 12)}`;
x.Kinds = new Set([EventKind.ZapReceipt]);
x.PTags = new Set([pubkey]);
return x;
}, [pubkey]);
2023-02-03 21:38:14 +00:00
2023-02-10 11:12:11 +00:00
const zapsFeed = useSubscription(sub, { leaveOpen: false, cache: true });
const zaps = useMemo(() => {
const profileZaps = zapsFeed.store.notes
.map(parseZap)
.filter(z => z.valid && z.p === pubkey && z.zapper !== pubkey && !z.e);
profileZaps.sort((a, b) => b.amount - a.amount);
return profileZaps;
}, [zapsFeed]);
return zaps;
2023-02-03 21:38:14 +00:00
}