Skip to content

Commit

Permalink
add live-updating zap counter to events
Browse files Browse the repository at this point in the history
  • Loading branch information
chakany committed Dec 7, 2024
1 parent 6a79d14 commit db262aa
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/components/Recipe/TotalZaps.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
let didSigs = new Map();
async function fetch() {
const evs = await $ndk.fetchEvents({
const sub = await $ndk.subscribe({
kinds: [9735],
'#a': [`${event.kind}:${event.author.pubkey}:${event.tags.find((e) => e[0] == 'd')?.[1]}`]
});
evs.forEach((a) => {
let bolt11 = a.tags.find((e) => e[0] == 'bolt11')?.[1];
if (bolt11 && a.sig) {
if (!didSigs.has(a.sig)) {
}, { closeOnEose: false });
sub.on("event", (event: NDKEvent) => {
let bolt11 = event.tags.find((e) => e[0] == 'bolt11')?.[1];
if (bolt11 && event.sig) {
if (!didSigs.has(event.sig)) {
let decoded = decode(bolt11);
totalZapAmount =
totalZapAmount + Number(decoded.sections.find((e) => e.name == 'amount').value);
didSigs.set(a.sig, a.sig);
didSigs.set(event.sig, event.sig);
}
}
});
}
Expand Down

0 comments on commit db262aa

Please sign in to comment.