import React from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { ButtonBase } from '../../component-library'; import { ICON_NAMES } from '../../component-library/icon/deprecated'; import { BackgroundColor, TextVariant, TextColor, Size, BorderRadius, AlignItems, } from '../../../helpers/constants/design-system'; import { useCopyToClipboard } from '../../../hooks/useCopyToClipboard'; import { shortenAddress } from '../../../helpers/utils/util'; import Tooltip from '../../ui/tooltip/tooltip'; import { useI18nContext } from '../../../hooks/useI18nContext'; export const AddressCopyButton = ({ address, shorten = false, wrap = false, }) => { const displayAddress = shorten ? shortenAddress(address) : address; const [copied, handleCopy] = useCopyToClipboard(); const t = useI18nContext(); return ( handleCopy(address)} paddingRight={4} paddingLeft={4} size={Size.SM} variant={TextVariant.bodyXs} color={TextColor.primaryDefault} endIconName={copied ? ICON_NAMES.COPY_SUCCESS : ICON_NAMES.COPY} className={classnames('multichain-address-copy-button', { 'multichain-address-copy-button__address--wrap': wrap, })} borderRadius={BorderRadius.pill} alignItems={AlignItems.center} data-testid="address-copy-button-text" > {displayAddress} ); }; AddressCopyButton.propTypes = { /** * Address to be copied */ address: PropTypes.string.isRequired, /** * Represents if the address should be shortened */ shorten: PropTypes.bool, /** * Represents if the element should wrap to multiple lines */ wrap: PropTypes.bool, };