-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added copy feature for addresses and keys
- Loading branch information
1 parent
4403545
commit fe9bd2a
Showing
3 changed files
with
67 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Image from "next/image"; | ||
import { useEffect, useState } from "react"; | ||
|
||
type Props = { | ||
data: string; | ||
}; | ||
|
||
function CopyButton({ data }: Props) { | ||
const [isCopied, setIsCopied] = useState(false); | ||
|
||
useEffect(() => { | ||
const id = setTimeout(() => { | ||
setIsCopied(false); | ||
}, 1500); | ||
|
||
return () => clearTimeout(id); | ||
}, [isCopied]); | ||
|
||
function handleCopyClick() { | ||
if (!data) return; | ||
navigator.clipboard.writeText(data); | ||
setIsCopied(true); | ||
} | ||
|
||
if (!data) { | ||
return null; | ||
} | ||
return ( | ||
<button | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
handleCopyClick(); | ||
}} | ||
className="dark:bg-black p-1 rounded-sm bg-[#333]" | ||
> | ||
<Image | ||
src={isCopied ? "/assets/tick.svg" : "/assets/copy.svg"} | ||
width={20} | ||
height={20} | ||
alt="#" | ||
/> | ||
</button> | ||
); | ||
} | ||
|
||
export default CopyButton; |