Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 59 additions & 59 deletions src/pages/VerifyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3328,76 +3328,76 @@ React.useEffect(() => {
zkMeta?.zkPoseidonHash,
]);

const onDownloadNotePng = useCallback(async () => {
if (!noteSvgFromPng || noteClaimed) return;
const onDownloadNotePng = useCallback(async () => {
if (!noteSvgFromPng || noteClaimed) return;

try {
const payloadBase = noteSendPayloadRaw
? { ...noteSendPayloadRaw }
: noteSendMeta
try {
const payloadBase = noteSendPayloadRaw
? { ...noteSendPayloadRaw }
: noteSendMeta
? {
parentCanonical: noteSendMeta.parentCanonical,
amountPhi: noteSendMeta.amountPhi,
amountUsd: noteSendMeta.amountUsd,
childCanonical: noteSendMeta.childCanonical,
}
: null;

const nextNonce = genNonce();

const noteSendPayload = payloadBase
? {
parentCanonical: noteSendMeta.parentCanonical,
amountPhi: noteSendMeta.amountPhi,
amountUsd: noteSendMeta.amountUsd,
childCanonical: noteSendMeta.childCanonical,
...payloadBase,
parentCanonical: payloadBase.parentCanonical || noteSendMeta?.parentCanonical,
amountPhi: noteSendMeta?.amountPhi ?? payloadBase.amountPhi,
amountUsd: noteSendMeta?.amountUsd ?? payloadBase.amountUsd,
transferNonce: nextNonce,
}
: null;

const nextNonce = genNonce();

const noteSendPayload = payloadBase
? {
...payloadBase,
parentCanonical: payloadBase.parentCanonical || noteSendMeta?.parentCanonical,
amountPhi: noteSendMeta?.amountPhi ?? payloadBase.amountPhi,
amountUsd: noteSendMeta?.amountUsd ?? payloadBase.amountUsd,
transferNonce: nextNonce,
}
: null;
if (noteSendPayload && "childCanonical" in noteSendPayload) {
delete (noteSendPayload as { childCanonical?: unknown }).childCanonical;
}

if (noteSendPayload && "childCanonical" in noteSendPayload) {
delete (noteSendPayload as { childCanonical?: unknown }).childCanonical;
}
const nonce = nextNonce ? `-${nextNonce.slice(0, 8)}` : "";
const filename = `☤KAI-NOTE${nonce}.png`;

const nonce = nextNonce ? `-${nextNonce.slice(0, 8)}` : "";
const filename = `☤KAI-NOTE${nonce}.png`;
const png = await svgStringToPngBlob(noteSvgFromPng, 2400);

const png = await svgStringToPngBlob(noteSvgFromPng, 2400);
const noteSendJson = noteSendPayload ? JSON.stringify(noteSendPayload) : "";
const entries = [
noteProofBundleJson ? { keyword: "phi_proof_bundle", text: noteProofBundleJson } : null,
sharedReceipt?.bundleHash ? { keyword: "phi_bundle_hash", text: sharedReceipt.bundleHash } : null,
sharedReceipt?.receiptHash ? { keyword: "phi_receipt_hash", text: sharedReceipt.receiptHash } : null,
noteSendJson ? { keyword: "phi_note_send", text: noteSendJson } : null,
{ keyword: "phi_note_svg", text: noteSvgFromPng },
].filter((entry): entry is { keyword: string; text: string } => Boolean(entry));

const noteSendJson = noteSendPayload ? JSON.stringify(noteSendPayload) : "";
const entries = [
noteProofBundleJson ? { keyword: "phi_proof_bundle", text: noteProofBundleJson } : null,
sharedReceipt?.bundleHash ? { keyword: "phi_bundle_hash", text: sharedReceipt.bundleHash } : null,
sharedReceipt?.receiptHash ? { keyword: "phi_receipt_hash", text: sharedReceipt.receiptHash } : null,
noteSendJson ? { keyword: "phi_note_send", text: noteSendJson } : null,
{ keyword: "phi_note_svg", text: noteSvgFromPng },
].filter((entry): entry is { keyword: string; text: string } => Boolean(entry));
if (entries.length === 0) {
triggerDownload(filename, png, "image/png");
} else {
const bytes = new Uint8Array(await png.arrayBuffer());
const enriched = insertPngTextChunks(bytes, entries);
const finalBlob = new Blob([enriched as BlobPart], { type: "image/png" });
triggerDownload(filename, finalBlob, "image/png");
}

if (entries.length === 0) {
triggerDownload(filename, png, "image/png");
return;
} catch (err) {
const msg = err instanceof Error ? err.message : "Note download failed.";
setNotice(msg);
} finally {
// ✅ ALWAYS flip claim + force UI refresh (mobile-safe)
confirmNoteSend();
}

const bytes = new Uint8Array(await png.arrayBuffer());
const enriched = insertPngTextChunks(bytes, entries);
const finalBlob = new Blob([enriched as BlobPart], { type: "image/png" });
triggerDownload(filename, finalBlob, "image/png");
} catch (err) {
const msg = err instanceof Error ? err.message : "Note download failed.";
setNotice(msg);
} finally {
// ✅ ALWAYS flip claim + force UI refresh (mobile-safe)
confirmNoteSend();
}
}, [
confirmNoteSend,
noteClaimed,
noteProofBundleJson,
noteSendMeta,
noteSendPayloadRaw,
noteSvgFromPng,
sharedReceipt,
]);
}, [
confirmNoteSend,
noteClaimed,
noteProofBundleJson,
noteSendMeta,
noteSendPayloadRaw,
noteSvgFromPng,
sharedReceipt,
]);

const onDownloadVerifiedCard = useCallback(async () => {
if (!verifiedCardData) return;
Expand Down