Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit 041592a

Browse files
benthecarmanfuturepaul
authored andcommitted
Fix identifiying zap kind
1 parent bd38058 commit 041592a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/utils/fetchZaps.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ function findByTag(tags: string[][], tag: string): string | undefined {
5454
}
5555
}
5656

57+
function getZapKind(event: NostrEvent): "public" | "private" | "anonymous" {
58+
const anonTag = event.tags.find((t) => {
59+
if (t[0] === "anon") {
60+
return true;
61+
}
62+
});
63+
64+
// If the anon field is empty it's anon, if it has other elements its private, otherwise it's public
65+
if (anonTag) {
66+
return anonTag.length < 2 ? "anonymous" : "private";
67+
}
68+
69+
return "public";
70+
}
71+
5772
async function simpleZapFromEvent(
5873
event: NostrEvent,
5974
wallet: MutinyWallet
@@ -66,8 +81,6 @@ async function simpleZapFromEvent(
6681
const from = request.pubkey;
6782

6883
const content = request.content;
69-
const anon = findByTag(request.tags, "anon");
70-
7184
const bolt11 = findByTag(event.tags, "bolt11") || "";
7285

7386
if (!bolt11) {
@@ -100,13 +113,7 @@ async function simpleZapFromEvent(
100113
}
101114

102115
return {
103-
// If the anon field is empty it's anon, if it has length it's private, otherwise it's public
104-
kind:
105-
typeof anon === "string"
106-
? anon.length
107-
? "private"
108-
: "anonymous"
109-
: "public",
116+
kind: getZapKind(request),
110117
from_hexpub: from,
111118
to_hexpub: to,
112119
timestamp: BigInt(event.created_at),
@@ -280,7 +287,7 @@ export const fetchZaps: ResourceFetcher<
280287
zaps.push(event);
281288
}
282289
} catch (e) {
283-
console.error("Failed to parse zap event: ", object);
290+
console.error("Failed to parse zap event: ", object, e);
284291
}
285292
}
286293
}

0 commit comments

Comments
 (0)