From 0f46aec26bf3fb16b1d4845c32afa0a8e65a9718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Leszczyk?= Date: Thu, 12 Dec 2024 09:24:35 +0100 Subject: [PATCH] feat: bring back address copy button --- src/pages/Accounts/components/AccountItem.tsx | 56 ++++++++++++++++++- src/pages/Accounts/components/AccountName.tsx | 1 + 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/pages/Accounts/components/AccountItem.tsx b/src/pages/Accounts/components/AccountItem.tsx index a6484011..abe4a31d 100644 --- a/src/pages/Accounts/components/AccountItem.tsx +++ b/src/pages/Accounts/components/AccountItem.tsx @@ -1,6 +1,9 @@ import { Checkbox, Collapse, + CopyIcon, + Grow, + IconButton, Stack, Tooltip, Typography, @@ -15,6 +18,7 @@ import { useState, } from 'react'; import { useTranslation } from 'react-i18next'; +import { NetworkVMType } from '@avalabs/core-chains-sdk'; import { useBalancesContext } from '@src/contexts/BalancesProvider'; import { useAccountsContext } from '@src/contexts/AccountsProvider'; @@ -154,6 +158,22 @@ export const AccountItem = forwardRef( useAccountRename(account); const { prompt: promptRemove, renderDialog: removeDialog } = useAccountRemoval(toBeRemoved); + const handleCopyClick = useCallback( + (ev) => { + ev.stopPropagation(); + if (!address || !network?.vmName) { + return; + } + const eventName = getCopyEventNameByNetworkType(network.vmName); + + navigator.clipboard.writeText(address); + toast.success('Copied!', { duration: 1000 }); + capture(eventName, { + type: account.type, + }); + }, + [address, account.type, capture, network?.vmName, toast] + ); return ( <> @@ -216,8 +236,7 @@ export const AccountItem = forwardRef( backgroundColor: isActive ? 'grey.700' : 'grey.800', color: 'grey.50', }, - pt: 0.5, - pb: 1, + py: 0.75, pl: 2, pr: 1, }} @@ -243,7 +262,13 @@ export const AccountItem = forwardRef( isActive={isActive} /> {address && ( - + + + + + + )} @@ -299,3 +334,18 @@ export const AccountItem = forwardRef( ); AccountItem.displayName = 'AccountItem'; + +const getCopyEventNameByNetworkType = (type: NetworkVMType) => { + switch (type) { + case NetworkVMType.BITCOIN: + return 'AccountSelectorBtcAddressCopied'; + case NetworkVMType.EVM: + return 'AccountSelectorEthAddressCopied'; + case NetworkVMType.AVM: + return 'AccountSelectorAVMAddressCopied'; + case NetworkVMType.PVM: + return 'AccountSelectorPVMAddressCopied'; + default: + return 'AccountSelectorAddressCopied'; + } +}; diff --git a/src/pages/Accounts/components/AccountName.tsx b/src/pages/Accounts/components/AccountName.tsx index 5c930724..0232da12 100644 --- a/src/pages/Accounts/components/AccountName.tsx +++ b/src/pages/Accounts/components/AccountName.tsx @@ -64,6 +64,7 @@ export default function AccountName({ { e.stopPropagation(); promptRename();