Merge pull request #333 from Semisol/patch-1

Use inner note content as comment
This commit is contained in:
Kieran 2023-02-19 22:10:54 +00:00 committed by GitHub
commit 4fa67db639
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,7 @@ interface Zapper {
pubkey?: HexKey;
isValid: boolean;
isAnon: boolean;
content: string;
}
function getZapper(zap: TaggedRawEvent, dhash: string): Zapper {
@ -56,17 +57,17 @@ function getZapper(zap: TaggedRawEvent, dhash: string): Zapper {
const rawEvent: TaggedRawEvent = JSON.parse(zapRequest);
if (Array.isArray(rawEvent)) {
// old format, ignored
return { isValid: false, isAnon: false };
return { isValid: false, isAnon: false, content: "" };
}
const anonZap = rawEvent.tags.some(a => a[0] === "anon");
const metaHash = sha256(zapRequest);
const ev = new Event(rawEvent);
return { pubkey: ev.PubKey, isValid: dhash === metaHash, isAnon: anonZap };
return { pubkey: ev.PubKey, isValid: dhash === metaHash, isAnon: anonZap, content: rawEvent.content };
} catch (e) {
console.warn("Invalid zap", zapRequest);
}
}
return { isValid: false, isAnon: false };
return { isValid: false, isAnon: false, content: "" };
}
export interface ParsedZap {
@ -83,7 +84,7 @@ export interface ParsedZap {
export function parseZap(zap: TaggedRawEvent): ParsedZap {
const { amount, hash } = getInvoice(zap);
const zapper = hash ? getZapper(zap, hash) : ({ isValid: false } as Zapper);
const zapper = hash ? getZapper(zap, hash) : ({ isValid: false, content: "" } as Zapper);
const e = findTag(zap, "e");
const p = unwrap(findTag(zap, "p"));
return {
@ -92,7 +93,7 @@ export function parseZap(zap: TaggedRawEvent): ParsedZap {
p,
amount: Number(amount) / 1000,
zapper: zapper.pubkey,
content: zap.content,
content: zapper.content,
valid: zapper.isValid,
zapService: zap.pubkey,
anonZap: zapper.isAnon,