import { type AllDualVariantIconKeys, type AllIconKeys, ButtCon, isDualVariantIcon, MenuItem, type SxProps, } from '@biom3/react'; import { useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { WrappedBrowserProvider } from '@imtbl/checkout-sdk'; import { getWalletLogoByName } from '../../../../lib/logoUtils'; import { getWalletProviderNameByProvider, isPassportProvider } from '../../../../lib/provider'; import { abbreviateWalletAddress } from '../../../../lib/utils'; const isCopiedStyle: SxProps = { background: 'base.color.status.success.bright', fill: 'base.color.status.success.bright', }; const isCopiedIconStyle: SxProps = { fill: 'base.color.fixed.black.1000', }; export function WalletAddress({ provider, showL1Warning, setShowL1Warning, }: { provider?: WrappedBrowserProvider; showL1Warning: boolean; setShowL1Warning: (show: boolean) => void; }) { const [walletAddress, setWalletAddress] = useState(''); const [isCopied, setIsCopied] = useState(false); const { t } = useTranslation(); const ctaIcon = useMemo(() => { if (isPassportProvider(provider) && !showL1Warning) { return 'ShowPassword'; } return isCopied ? 'Tick' : 'CopyText'; }, [provider, showL1Warning, isCopied]); useEffect(() => { if (!provider || walletAddress !== '') return; (async () => { const address = await (await provider.getSigner()).getAddress(); setWalletAddress(address); })(); }, [provider, walletAddress]); const handleIconClick = async () => { if (walletAddress && ctaIcon === 'CopyText') { navigator.clipboard.writeText(walletAddress); setIsCopied(true); setTimeout(() => setIsCopied(false), 1000); } else if (ctaIcon === 'ShowPassword') { setShowL1Warning(true); } }; return ( {isDualVariantIcon(ctaIcon) ? ( ) : ( )} {t('views.SETTINGS.walletAddress.label')} {abbreviateWalletAddress(walletAddress)} ); }