fix: parse old zaps
This commit is contained in:
parent
677ca771c8
commit
0a056edcad
@ -46,11 +46,14 @@ function getZapper(zap: TaggedRawEvent, dhash: string) {
|
||||
const rawEvent: TaggedRawEvent = JSON.parse(zapRequest);
|
||||
if (Array.isArray(rawEvent)) {
|
||||
// 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)
|
||||
return { pubkey: ev.PubKey, valid: metaHash == dhash };
|
||||
return ev.PubKey
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +69,7 @@ interface ParsedZap {
|
||||
|
||||
export function parseZap(zap: TaggedRawEvent): ParsedZap {
|
||||
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 p = findTag(zap, 'p')!
|
||||
return {
|
||||
@ -74,9 +77,9 @@ export function parseZap(zap: TaggedRawEvent): ParsedZap {
|
||||
e,
|
||||
p,
|
||||
amount: Number(amount) / 1000,
|
||||
zapper: zapper?.pubkey,
|
||||
zapper,
|
||||
content: zap.content,
|
||||
valid: zapper?.valid ?? false,
|
||||
valid: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ export default function ProfilePage() {
|
||||
: user?.website || "";
|
||||
const zapFeed = useZapsFeed(id)
|
||||
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])
|
||||
const zapsTotal = zaps.reduce((acc, z) => acc + z.amount, 0)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user