import React, { useState } from "react"; import { Link } from "react-router-dom"; import { PublicKey } from "@solana/web3.js"; import { clusterPath } from "utils/url"; import { displayAddress } from "utils/tx"; import { Pubkey } from "solana-sdk-wasm"; type CopyState = "copy" | "copied"; type Props = { pubkey: PublicKey | Pubkey; alignRight?: boolean; link?: boolean; }; export default function Address({ pubkey, alignRight, link }: Props) { const [state, setState] = useState("copy"); const address = pubkey.toBase58(); const copyToClipboard = () => navigator.clipboard.writeText(address); const handleClick = () => copyToClipboard().then(() => { setState("copied"); setTimeout(() => setState("copy"), 1000); }); const copyIcon = state === "copy" ? ( ) : ( ); const content = ( <> {copyIcon} {link ? ( {displayAddress(address)} ) : ( displayAddress(address) )} ); return ( <>
{content}
{content}
); }