Fix sent zaps: query kind 9735 receipts with #P tag instead of ephemeral kind 9734

This commit is contained in:
Jure
2026-03-13 11:17:45 +01:00
parent 7746e31051
commit 93963de28d
2 changed files with 6 additions and 10 deletions

View File

@@ -32,13 +32,6 @@ function parseReceipt(receipt: NDKEvent): { amount: number | null; senderPubkey:
return { amount, senderPubkey, comment, noteId };
}
function parseRequest(zapReq: NDKEvent): { amount: number | null; recipientPubkey: string | null; comment: string; noteId: string | null } {
const recipientPubkey = zapReq.tags.find((t) => t[0] === "p")?.[1] ?? null;
const noteId = zapReq.tags.find((t) => t[0] === "e")?.[1] ?? null;
const amountTag = zapReq.tags.find((t) => t[0] === "amount");
const amount = amountTag?.[1] ? Math.round(parseInt(amountTag[1]) / 1000) : null;
return { amount, recipientPubkey, comment: zapReq.content ?? "", noteId };
}
// ── Row component ────────────────────────────────────────────────────────────
@@ -154,7 +147,7 @@ export function ZapHistoryView() {
return sum + (amount ?? 0);
}, 0);
const totalSent = sent.reduce((sum, e) => {
const { amount } = parseRequest(e);
const { amount } = parseReceipt(e);
return sum + (amount ?? 0);
}, 0);
@@ -221,7 +214,9 @@ export function ZapHistoryView() {
/>
);
} else {
const { amount, recipientPubkey, comment } = parseRequest(event);
// Sent zaps are also kind 9735 receipts; the recipient is in the lowercase "p" tag
const recipientPubkey = event.tags.find((t) => t[0] === "p")?.[1] ?? null;
const { amount, comment } = parseReceipt(event);
return (
<ZapRow
key={event.id}

View File

@@ -435,7 +435,8 @@ export async function fetchZapsReceived(pubkey: string, limit = 50): Promise<NDK
export async function fetchZapsSent(pubkey: string, limit = 50): Promise<NDKEvent[]> {
const instance = getNDK();
const filter: NDKFilter = { kinds: [NDKKind.ZapRequest], authors: [pubkey], limit };
// Zap receipts (kind 9735) with uppercase P tag = the sender's pubkey
const filter: NDKFilter = { kinds: [NDKKind.Zap], "#P": [pubkey], limit };
const events = await instance.fetchEvents(filter, {
cacheUsage: NDKSubscriptionCacheUsage.ONLY_RELAY,
});