Skip to content
Closed
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
39 changes: 34 additions & 5 deletions src/app/dashboard/affiliates/DashboardClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ function formatSats(sats: number): string {
return sats.toLocaleString();
}

async function copyText(text: string): Promise<boolean> {
try {
if (navigator.clipboard?.writeText) {
await navigator.clipboard.writeText(text);
return true;
}
} catch {
// Fall through to the textarea fallback below.
}

const textarea = document.createElement("textarea");
textarea.value = text;
textarea.setAttribute("readonly", "");
textarea.style.position = "fixed";
textarea.style.opacity = "0";
document.body.appendChild(textarea);
textarea.select();

try {
return document.execCommand("copy");
} finally {
document.body.removeChild(textarea);
}
}
Comment on lines +67 to +72

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Unhandled exception in textarea fallback path

The inner try/finally for execCommand has no catch. document.execCommand('copy') can throw a SecurityError or InvalidStateError (e.g., in a cross-origin iframe, or when no text is selected). If it does, the exception propagates out of copyText as a rejected Promise, and the async onClick handler has no catch either — producing a silent unhandled promise rejection and leaving the UI without feedback.

Suggested change
try {
return document.execCommand("copy");
} finally {
document.body.removeChild(textarea);
}
}
try {
return document.execCommand("copy");
} catch {
return false;
} finally {
document.body.removeChild(textarea);
}
}


function StatCard({
label,
value,
Expand Down Expand Up @@ -105,11 +130,15 @@ function CopyButton({ text, label, stopPropagation }: { text: string; label?: st
size="sm"
variant="outline"
title={label}
onClick={(e) => {
if (stopPropagation) e.preventDefault();
navigator.clipboard.writeText(text);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
onClick={async (e) => {
if (stopPropagation) {
e.preventDefault();
e.stopPropagation();
}
if (await copyText(text)) {
setCopied(true);
setTimeout(() => setCopied(false), 2000);
}
}}
>
{copied ? (
Expand Down
Loading