Skip to content

Commit

Permalink
Fix identifiying zap kind
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman authored and futurepaul committed Feb 20, 2024
1 parent bd38058 commit 041592a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/utils/fetchZaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ function findByTag(tags: string[][], tag: string): string | undefined {
}
}

function getZapKind(event: NostrEvent): "public" | "private" | "anonymous" {
const anonTag = event.tags.find((t) => {
if (t[0] === "anon") {
return true;
}
});

// If the anon field is empty it's anon, if it has other elements its private, otherwise it's public
if (anonTag) {
return anonTag.length < 2 ? "anonymous" : "private";
}

return "public";
}

async function simpleZapFromEvent(
event: NostrEvent,
wallet: MutinyWallet
Expand All @@ -66,8 +81,6 @@ async function simpleZapFromEvent(
const from = request.pubkey;

const content = request.content;
const anon = findByTag(request.tags, "anon");

const bolt11 = findByTag(event.tags, "bolt11") || "";

if (!bolt11) {
Expand Down Expand Up @@ -100,13 +113,7 @@ async function simpleZapFromEvent(
}

return {
// If the anon field is empty it's anon, if it has length it's private, otherwise it's public
kind:
typeof anon === "string"
? anon.length
? "private"
: "anonymous"
: "public",
kind: getZapKind(request),
from_hexpub: from,
to_hexpub: to,
timestamp: BigInt(event.created_at),
Expand Down Expand Up @@ -280,7 +287,7 @@ export const fetchZaps: ResourceFetcher<
zaps.push(event);
}
} catch (e) {
console.error("Failed to parse zap event: ", object);
console.error("Failed to parse zap event: ", object, e);
}
}
}
Expand Down

0 comments on commit 041592a

Please sign in to comment.