diff --git a/src/widgets/WalletModal/CopyToClipboard.tsx b/src/widgets/WalletModal/CopyToClipboard.tsx index 58a43c005..364c34f84 100644 --- a/src/widgets/WalletModal/CopyToClipboard.tsx +++ b/src/widgets/WalletModal/CopyToClipboard.tsx @@ -30,17 +30,33 @@ const Tooltip = styled.div<{ isTooltipDisplayed: boolean }>` const CopyToClipboard: React.FC = ({ toCopy, children, ...props }) => { const [isTooltipDisplayed, setIsTooltipDisplayed] = useState(false); + const copyToClipboard = (content: string) => { + const el = document.createElement("textarea"); + el.value = content; + document.body.appendChild(el); + el.select(); + document.execCommand("copy"); + document.body.removeChild(el); + }; + + function displayTooltip() { + setIsTooltipDisplayed(true); + setTimeout(() => { + setIsTooltipDisplayed(false); + }, 1000); + } + return ( { - if (navigator.clipboard) { + if (document.queryCommandSupported("copy")) { + copyToClipboard(toCopy); + displayTooltip(); + } else if (navigator.clipboard) { navigator.clipboard.writeText(toCopy); - setIsTooltipDisplayed(true); - setTimeout(() => { - setIsTooltipDisplayed(false); - }, 1000); + displayTooltip(); } }} {...props}