fix: parse old zaps

This commit is contained in:
Alejandro Gomez 2023-02-04 10:48:21 +01:00
parent 677ca771c8
commit 0a056edcad
No known key found for this signature in database
GPG Key ID: 4DF39E566658C817
2 changed files with 10 additions and 7 deletions

View File

@ -46,11 +46,14 @@ function getZapper(zap: TaggedRawEvent, dhash: string) {
const rawEvent: TaggedRawEvent = JSON.parse(zapRequest); const rawEvent: TaggedRawEvent = JSON.parse(zapRequest);
if (Array.isArray(rawEvent)) { if (Array.isArray(rawEvent)) {
// old format, ignored // old format, ignored
return; const rawDescriptionTag = rawEvent.find(a => a[0] === 'application/nostr')
const rawDescription = rawDescriptionTag && rawDescriptionTag[1]
const request = typeof rawDescription === 'string' ? JSON.parse(rawDescription) : rawDescription
return request?.pubkey
} }
const metaHash = sha256(zapRequest); //const metaHash = sha256(zapRequest);
const ev = new Event(rawEvent) const ev = new Event(rawEvent)
return { pubkey: ev.PubKey, valid: metaHash == dhash }; return ev.PubKey
} }
} }
@ -66,7 +69,7 @@ interface ParsedZap {
export function parseZap(zap: TaggedRawEvent): ParsedZap { export function parseZap(zap: TaggedRawEvent): ParsedZap {
const { amount, hash } = getInvoice(zap) const { amount, hash } = getInvoice(zap)
const zapper = hash ? getZapper(zap, hash) : { valid: false, pubkey: undefined }; const zapper = hash && getZapper(zap, hash)
const e = findTag(zap, 'e') const e = findTag(zap, 'e')
const p = findTag(zap, 'p')! const p = findTag(zap, 'p')!
return { return {
@ -74,9 +77,9 @@ export function parseZap(zap: TaggedRawEvent): ParsedZap {
e, e,
p, p,
amount: Number(amount) / 1000, amount: Number(amount) / 1000,
zapper: zapper?.pubkey, zapper,
content: zap.content, content: zap.content,
valid: zapper?.valid ?? false, valid: true,
} }
} }

View File

@ -63,7 +63,7 @@ export default function ProfilePage() {
: user?.website || ""; : user?.website || "";
const zapFeed = useZapsFeed(id) const zapFeed = useZapsFeed(id)
const zaps = useMemo(() => { const zaps = useMemo(() => {
return zapFeed.store.notes.map(parseZap).filter(z => z.valid && z.p === id) return zapFeed.store.notes.map(parseZap).filter(z => z.valid && z.p === id && !z.e)
}, [zapFeed.store.notes, id]) }, [zapFeed.store.notes, id])
const zapsTotal = zaps.reduce((acc, z) => acc + z.amount, 0) const zapsTotal = zaps.reduce((acc, z) => acc + z.amount, 0)