Use inner note content as comment

This commit is contained in:
Semisol 2023-02-19 19:39:20 +03:00 committed by GitHub
parent f34e42701f
commit 38892b6c34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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