11import { Asset } from "@chain-registry/types" ;
22import { AmountInput , Tooltip } from "@namada/components" ;
3+ import { copyToClipboard , shortenAddress } from "@namada/utils" ;
34import BigNumber from "bignumber.js" ;
45import clsx from "clsx" ;
56import { wallets } from "integrations" ;
7+ import { useState } from "react" ;
8+ import { GoCheck } from "react-icons/go" ;
69import { Address } from "types" ;
710import namadaShieldedIcon from "./assets/namada-shielded.svg" ;
811import namadaTransparentIcon from "./assets/namada-transparent.svg" ;
@@ -80,11 +83,21 @@ export const TransferSource = ({
8083 openAssetSelector,
8184 onChangeAmount,
8285} : TransferSourceProps ) : JSX . Element => {
86+ const [ isCopied , setIsCopied ] = useState ( false ) ;
87+
8388 const selectedTokenType =
8489 isTransparentAddress ( sourceAddress ?? "" ) ? "transparent"
8590 : isShieldedAddress ( sourceAddress ?? "" ) ? "shielded"
8691 : "keplr" ;
8792
93+ const handleCopyAddress = ( ) : void => {
94+ if ( sourceAddress ) {
95+ copyToClipboard ( sourceAddress ) ;
96+ setIsCopied ( true ) ;
97+ setTimeout ( ( ) => setIsCopied ( false ) , 500 ) ;
98+ }
99+ } ;
100+
88101 return (
89102 < div
90103 className = { clsx (
@@ -108,10 +121,17 @@ export const TransferSource = ({
108121 < img
109122 src = { getWalletIcon ( sourceAddress , selectedTokenType ) }
110123 alt = "Wallet icon"
111- className = "w-7 h-7"
124+ className = "cursor-pointer w-7 h-7"
125+ onClick = { handleCopyAddress }
126+ title = "Copy address"
112127 />
113128 < Tooltip position = "top" className = "z-50" >
114- { sourceAddress }
129+ { isCopied ?
130+ < >
131+ Copied
132+ < GoCheck className = "mt-0.5 ml-1 text-green-500" />
133+ </ >
134+ : shortenAddress ( sourceAddress ) }
115135 </ Tooltip >
116136 </ div >
117137 </ div >
0 commit comments