Skip to content

Commit

Permalink
fix: account circle numbers and delete unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarkhanzadian committed Nov 20, 2023
1 parent 99fb117 commit a6588dc
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 88 deletions.
12 changes: 12 additions & 0 deletions src/app/components/account/account-avatar-item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { memo } from 'react';

import { AccountAvatar } from '@app/components/account/account-avatar';

interface AccountAvatarItemProps {
publicKey: string;
index: number;
name: string;
}
export const AccountAvatarItem = memo(({ name, publicKey, index }: AccountAvatarItemProps) => {
return <AccountAvatar index={index} name={name} publicKey={publicKey} />;
});
24 changes: 19 additions & 5 deletions src/app/components/account/account-avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import { memo } from 'react';

import { AccountAvatar } from '@app/components/account/account-avatar/account-avatar';
import { Box, CircleProps } from 'leather-styles/jsx';

interface AccountAvatarItemProps {
import { DynamicColorCircle } from '@app/ui/components/dynamic-color-circle';

const getAccountNumber = (index: number) => {
// Always return account number in the Account Circle
return String(index + 1);
};

interface AccountAvatarProps extends CircleProps {
name: string;
publicKey: string;
index: number;
name: string;
}
export const AccountAvatarItem = memo(({ name, publicKey, index }: AccountAvatarItemProps) => {
return <AccountAvatar index={index} name={name} publicKey={publicKey} />;
export const AccountAvatar = memo(({ name, publicKey, index, ...props }: AccountAvatarProps) => {
const gradient = publicKey + index.toString();
const text = getAccountNumber(index);

return (
<DynamicColorCircle sizeParam="48" value={gradient} {...props}>
<Box position="absolute">{text}</Box>
</DynamicColorCircle>
);
});
42 changes: 0 additions & 42 deletions src/app/components/account/account-avatar/account-avatar.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions src/app/components/account/account-list-item-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ interface AccountListItemLayoutProps extends StackProps {
accountName: React.ReactNode;
avatar: React.JSX.Element;
balanceLabel: React.ReactNode;
hasCopied?: boolean;
onCopyToClipboard?(e: React.MouseEvent): void;
onClickBtcCopyIcon?(e: React.MouseEvent): void;
onSelectAccount(): void;
}
export function AccountListItemLayout(props: AccountListItemLayoutProps) {
Expand All @@ -32,9 +29,6 @@ export function AccountListItemLayout(props: AccountListItemLayoutProps) {
avatar,
balanceLabel,
onSelectAccount,
hasCopied,
onCopyToClipboard,
onClickBtcCopyIcon,
children = null,
...rest
} = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CircleProps } from 'leather-styles/jsx';

import { useCurrentAccountDisplayName } from '@app/common/hooks/account/use-account-names';
import { useDrawers } from '@app/common/hooks/use-drawers';
import { AccountAvatar } from '@app/components/account/account-avatar/account-avatar';
import { AccountAvatar } from '@app/components/account/account-avatar';
import { useCurrentStacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';

export const CurrentAccountAvatar = memo((props: CircleProps) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { memo } from 'react';
import { useNavigate } from 'react-router-dom';

import { RouteUrls } from '@shared/route-urls';

import { useAccountDisplayName } from '@app/common/hooks/account/use-account-names';
import { useSwitchAccount } from '@app/common/hooks/account/use-switch-account';
import { useAnalytics } from '@app/common/hooks/analytics/use-analytics';
import { useClipboard } from '@app/common/hooks/use-copy-to-clipboard';
import { useDrawers } from '@app/common/hooks/use-drawers';
import { useLoading } from '@app/common/hooks/use-loading';
import { AccountTotalBalance } from '@app/components/account-total-balance';
import { AccountListItemLayout } from '@app/components/account/account-list-item-layout';
import { usePressable } from '@app/components/item-hover';
import { useNativeSegwitSigner } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks';
import { useStacksAccounts } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';

import { AccountAvatarItem } from '../../../components/account/account-avatar';
import { AccountAvatarItem } from '../../../components/account/account-avatar-item';
import { AccountNameLayout } from '../../../components/account/account-name';

interface SwitchAccountListItemProps {
Expand All @@ -36,7 +30,6 @@ export const SwitchAccountListItem = memo(
const { handleSwitchAccount } = useSwitchAccount(handleClose);
const [component, bind] = usePressable(true);
const name = useAccountDisplayName({ address: stacksAddress, index });
const navigate = useNavigate();

const handleClick = async () => {
setIsLoading();
Expand All @@ -46,45 +39,23 @@ export const SwitchAccountListItem = memo(
}, 80);
};

const analytics = useAnalytics();
const { onCopy, hasCopied } = useClipboard(stacksAddress || '');
const { setIsShowingSwitchAccountsState } = useDrawers();

const onCopyToClipboard = (e: React.MouseEvent) => {
e.stopPropagation();
void analytics.track('copy_address_to_clipboard');
onCopy();
};

const onClickBtcCopyIcon = (e: React.MouseEvent) => {
if (!bitcoinAddress) return;
e.stopPropagation();
setIsShowingSwitchAccountsState(false);
navigate(RouteUrls.ReceiveBtc, {
state: { btcAddress: bitcoinAddress, accountIndex: currentAccountIndex },
});
};

return (
<AccountListItemLayout
index={index}
isLoading={isLoading}
isActive={currentAccountIndex === index}
avatar={
<AccountAvatarItem
index={currentAccountIndex}
index={index}
publicKey={stacksAccounts[index]?.stxPublicKey || ''}
name={name}
publicKey={stacksAccounts[currentAccountIndex]?.stxPublicKey || ''}
/>
}
onSelectAccount={handleClick}
accountName={<AccountNameLayout>{name}</AccountNameLayout>}
balanceLabel={
<AccountTotalBalance stxAddress={stacksAddress} btcAddress={bitcoinAddress} />
}
hasCopied={hasCopied}
onCopyToClipboard={onCopyToClipboard}
onClickBtcCopyIcon={onClickBtcCopyIcon}
mt="space.05"
{...bind}
>
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/choose-account/components/accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useCreateAccount } from '@app/common/hooks/account/use-create-account';
import { useWalletType } from '@app/common/use-wallet-type';
import { slugify } from '@app/common/utils';
import { AccountTotalBalance } from '@app/components/account-total-balance';
import { AccountAvatar } from '@app/components/account/account-avatar/account-avatar';
import { AccountAvatar } from '@app/components/account/account-avatar';
import { AccountListItemLayout } from '@app/components/account/account-list-item-layout';
import { usePressable } from '@app/components/item-hover';
import { useNativeSegwitAccountIndexAddressIndexZero } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BitcoinSendFormValues, StacksSendFormValues } from '@shared/models/form

import { useAccountDisplayName } from '@app/common/hooks/account/use-account-names';
import { AccountTotalBalance } from '@app/components/account-total-balance';
import { AccountAvatarItem } from '@app/components/account/account-avatar';
import { AccountAvatarItem } from '@app/components/account/account-avatar-item';
import { AccountListItemLayout } from '@app/components/account/account-list-item-layout';
import { AccountName } from '@app/components/account/account-name';
import { usePressable } from '@app/components/item-hover';
Expand Down

0 comments on commit a6588dc

Please sign in to comment.