import { Button, ButtonProps, PossibleButtonSize, buttonSizesMap, } from "./button"; import { Card } from "./card"; import { Text } from "./text"; import { Icon, Tooltip, useClipboard, useToast } from "@chakra-ui/react"; import { useTrack } from "hooks/analytics/useTrack"; import React, { useEffect } from "react"; import { FiCopy } from "react-icons/fi"; interface AddressCopyButtonProps extends Omit { address?: string; noIcon?: boolean; size?: PossibleButtonSize; title?: string; shortenAddress?: boolean; } /** * shorten the string to 13 characters with the format of 6 chars + ... + 4 chars * does not shorten if string is less than 13 characters * * @param str string to shorten * @returns shortened string to length 13 */ const shorten = (str: string) => { if (str.length > 13) { return `${str.substring(0, 6)}...${str.substring(str.length - 4)}`; } else { return str; } }; export const AddressCopyButton: React.FC = ({ address, noIcon, flexGrow = 0, size = "sm", borderRadius = "md", variant = "outline", shortenAddress = true, title = "address", ...restButtonProps }) => { const { onCopy, setValue } = useClipboard(address || ""); useEffect(() => { if (address) { setValue(address); } }, [address, setValue]); const trackEvent = useTrack(); const toast = useToast(); return ( Copy {title} to clipboard } > ); };