copy mac fixed

This commit is contained in:
2024-10-30 19:16:32 +05:30
parent 949ff91d26
commit bdf71c55d1
2 changed files with 99 additions and 20 deletions

View File

@@ -83,19 +83,55 @@ const LatestTransactions = () => {
setTotalItems(transCount?.data?.transactionCount);
}, [transCount]);
// function copyToClipboard(text) {
// navigator.clipboard
// .writeText(text)
// .then(() => {
// toast({
// render: () => (
// <ToastBox status={"warn"} message={"Text copied to clipboard"} />
// ),
// });
// })
// .catch((err) => {
// console.error("Failed to copy text: ", err);
// });
// }
function copyToClipboard(text) {
navigator.clipboard
.writeText(text)
.then(() => {
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard
.writeText(text)
.then(() => {
toast({
render: () => (
<ToastBox status={"warn"} message={"Text copied to clipboard"} />
),
});
})
.catch((err) => {
console.error("Failed to copy text: ", err);
});
} else {
// Fallback method for unsupported browsers
const textArea = document.createElement("textarea");
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand("copy");
toast({
render: () => (
<ToastBox status={"warn"} message={"Text copied to clipboard"} />
),
});
})
.catch((err) => {
console.error("Failed to copy text: ", err);
});
} catch (err) {
console.error("Fallback: Failed to copy text: ", err);
}
document.body.removeChild(textArea);
}
}
const handleRefreshClick = () => {

View File

@@ -60,27 +60,64 @@ const toast = useToast()
// console.error("Error generating short URL:", error);
// }
// };
function copyToClipboard(text) {
if (!navigator.clipboard) {
console.error("Clipboard API is not available.");
return;
}
navigator.clipboard
.writeText(text)
.then(() => {
// function copyToClipboard(text) {
// if (!navigator.clipboard) {
// console.error("Clipboard API is not available.");
// return;
// }
// navigator.clipboard
// .writeText(text)
// .then(() => {
// toast({
// render: () => (
// <ToastBox status={"warn"} message={"Text copied to clipboard"} />
// ),
// });
// setIsCopy(true)
// })
// .catch((err) => {
// console.error("Failed to copy text: ", err);
// });
// }
function copyToClipboard(text) {
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard
.writeText(text)
.then(() => {
toast({
render: () => (
<ToastBox status={"warn"} message={"Text copied to clipboard"} />
),
});
})
.catch((err) => {
console.error("Failed to copy text: ", err);
});
} else {
// Fallback method for unsupported browsers
const textArea = document.createElement("textarea");
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand("copy");
toast({
render: () => (
<ToastBox status={"warn"} message={"Text copied to clipboard"} />
),
});
setIsCopy(true)
})
.catch((err) => {
console.error("Failed to copy text: ", err);
});
} catch (err) {
console.error("Fallback: Failed to copy text: ", err);
}
document.body.removeChild(textArea);
}
}
const handleGenrateShortURL = async () => {
setLinkVisible(true)
@@ -242,6 +279,12 @@ const toast = useToast()
<AmountCard />
<Container maxW="6xl" p={{base: "2rem 1rem",md:"4rem 1rem"}}>
<Box
boxShadow={
colorMode === "light"
? "rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;"
: "none"
}
p={{base :1,md : 5}}
rounded={10}
bg={colorMode === "light" ? "#DEDBEB47" : "#232127"}