diff --git a/src/components/shared/copyable-address/copyable-address.types.ts b/src/components/shared/copyable-address/copyable-address.types.ts new file mode 100644 index 00000000..63edd53b --- /dev/null +++ b/src/components/shared/copyable-address/copyable-address.types.ts @@ -0,0 +1,6 @@ +export interface CopyableAddressProps { + address: string + showFull?: boolean + showLabel?: boolean + className?: string +} \ No newline at end of file diff --git a/src/components/shared/copyable-address/index.tsx b/src/components/shared/copyable-address/index.tsx new file mode 100644 index 00000000..614a9183 --- /dev/null +++ b/src/components/shared/copyable-address/index.tsx @@ -0,0 +1,45 @@ +"use client" + +import { FC } from "react" +import { Check, Copy } from "lucide-react" + +import { cn } from "@/utils" +import { formatAddress } from "@mysten/sui/utils" +import { useResolveSuiNSName } from "@mysten/dapp-kit" +import { useClipboard } from "@/hooks/use-clipboard" +import { getWalletLabel } from "@/constants/wallet-labels" +import { CopyableAddressProps } from "./copyable-address.types" + + +const CopyableAddress: FC = ({ address, showFull = false, showLabel = true, className }) => { + const { copy, copied } = useClipboard() + const label = showLabel ? getWalletLabel(address) : undefined + // const { data: suins } = useResolveSuiNSName(label ? undefined : address) + + // priority: label, suins, formatted address + const displayName = label || (showFull ? address : formatAddress(address)) + + return ( +
copy(address)} + > + + {displayName} + + + {copied ? : } +
+ ) +} + +export default CopyableAddress; \ No newline at end of file