Skip to content

Commit

Permalink
feat: bring back address copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
meeh0w committed Dec 12, 2024
1 parent 8a72bbe commit 0f46aec
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
56 changes: 53 additions & 3 deletions src/pages/Accounts/components/AccountItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {
Checkbox,
Collapse,
CopyIcon,
Grow,
IconButton,
Stack,
Tooltip,
Typography,
Expand All @@ -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';
Expand Down Expand Up @@ -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 (
<>
Expand Down Expand Up @@ -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,
}}
Expand All @@ -243,7 +262,13 @@ export const AccountItem = forwardRef(
isActive={isActive}
/>
{address && (
<Stack direction="row">
<Stack
sx={{
flexDirection: 'row',
gap: 1,
alignItems: 'center',
}}
>
<Tooltip title={address} disableInteractive>
<Typography
variant="caption"
Expand All @@ -252,6 +277,16 @@ export const AccountItem = forwardRef(
{truncateAddress(address)}
</Typography>
</Tooltip>
<Grow in={cardHovered || isActive}>
<IconButton
color="primary"
size="small"
sx={{ p: 0.5 }}
onClick={handleCopyClick}
>
<CopyIcon size={12} />
</IconButton>
</Grow>
</Stack>
)}
</Stack>
Expand Down Expand Up @@ -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';
}
};
1 change: 1 addition & 0 deletions src/pages/Accounts/components/AccountName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default function AccountName({
<Grow {...commonTransitionProps} in={cardHovered && !isManageMode}>
<IconButton
size="small"
sx={{ p: 0.25 }}
onClick={(e) => {
e.stopPropagation();
promptRename();
Expand Down

0 comments on commit 0f46aec

Please sign in to comment.