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
37 changes: 32 additions & 5 deletions frontend/src/ReferralLinkGenerator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,40 @@ export default function ReferralLinkGenerator({
}, [id, walletAddress]);

const handleCopy = async () => {
const link = buildInviteLink();
try {
await navigator.clipboard.writeText(buildInviteLink());
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error('Failed to copy:', err);
if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
await navigator.clipboard.writeText(link);
setCopied(true);
setError('');
setTimeout(() => setCopied(false), 2000);
return;
}
} catch {
// Fall through to execCommand fallback below (#1481)
}

try {
const textarea = document.createElement('textarea');
textarea.value = link;
textarea.setAttribute('readonly', '');
textarea.style.position = 'fixed';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
textarea.select();
const succeeded = typeof document.execCommand === 'function' && document.execCommand('copy');
document.body.removeChild(textarea);
if (succeeded) {
setCopied(true);
setError('');
setTimeout(() => setCopied(false), 2000);
return;
}
} catch {
// Ignore and show manual copy prompt
}

setError('Clipboard unavailable — please select and copy the referral link manually.');
};

const buildShareText = () => {
Expand Down