Skip to content

Commit

Permalink
add hardware wallet badge for send wallet list (#1659)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Sinclair <[email protected]>
  • Loading branch information
magiziz and DanielSinclair authored Aug 15, 2024
1 parent d300f4f commit add44e3
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 30 deletions.
13 changes: 11 additions & 2 deletions src/entries/popup/components/LabelPill/LabelPill.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import React from 'react';

import { Box, Inline, Text } from '~/design-system';
import type { BackgroundColor } from '~/design-system/styles/designTokens';

const LabelPill = ({ label, dot }: { label: string; dot?: boolean }) => (
const LabelPill = ({
label,
dot,
background,
}: {
label: string;
dot?: boolean;
background?: BackgroundColor;
}) => (
<Box
background="surfacePrimaryElevatedSecondary"
background={background || 'surfacePrimaryElevatedSecondary'}
borderRadius="round"
padding="8px"
>
Expand Down
8 changes: 7 additions & 1 deletion src/entries/popup/hooks/send/useAllFilteredWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const useAllFilteredWallets = ({ filter }: { filter?: string }) => {

return useMemo(
() => ({
wallets: filterWallets(visibleOwnedWallets, filter).map((a) => a.address),
wallets: filterWallets(visibleOwnedWallets, filter),
watchedWallets: filterWallets(watchedWallets, filter).map(
(a) => a.address,
),
Expand All @@ -45,3 +45,9 @@ export const useAllFilteredWallets = ({ filter }: { filter?: string }) => {
[visibleOwnedWallets, watchedWallets, contacts, filter],
);
};

export type VisibleOwnedWallets = ReturnType<
typeof useAllFilteredWallets
>['wallets'];

export type VisibleOwnedWallet = VisibleOwnedWallets[number];
89 changes: 62 additions & 27 deletions src/entries/popup/pages/send/ToAddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { i18n } from '~/core/languages';
import { useCurrentAddressStore } from '~/core/state';
import { useTestnetModeStore } from '~/core/state/currentSettings/testnetMode';
import { usePopupInstanceStore } from '~/core/state/popupInstances';
import { KeychainType } from '~/core/types/keychainTypes';
import { truncateAddress } from '~/core/utils/address';
import { TESTNET_MODE_BAR_HEIGHT } from '~/core/utils/dimensions';
import {
Expand All @@ -34,10 +35,15 @@ import { TextOverflow } from '~/design-system/components/TextOverflow/TextOverfl
import { SymbolName } from '~/design-system/styles/designTokens';

import { DropdownInputWrapper } from '../../components/DropdownInputWrapper/DropdownInputWrapper';
import { LabelPill } from '../../components/LabelPill/LabelPill';
import { CursorTooltip } from '../../components/Tooltip/CursorTooltip';
import { WalletAvatar } from '../../components/WalletAvatar/WalletAvatar';
import { WalletContextMenu } from '../../components/WalletContextMenu';
import { useAllFilteredWallets } from '../../hooks/send/useAllFilteredWallets';
import {
VisibleOwnedWallet,
VisibleOwnedWallets,
useAllFilteredWallets,
} from '../../hooks/send/useAllFilteredWallets';
import { useWalletInfo } from '../../hooks/useWalletInfo';

import { InputActionButton } from './InputActionButton';
Expand All @@ -51,7 +57,7 @@ const WalletSection = ({
section,
}: {
title: string;
wallets: Address[];
wallets: Address[] | VisibleOwnedWallets;
onClickWallet: (address: Address) => void;
symbol: SymbolName;
section: 'contacts' | 'my_wallets' | 'watching';
Expand All @@ -73,23 +79,30 @@ const WalletSection = ({
</Box>

<Box>
{wallets.map((wallet, i) => (
<Bleed horizontal="12px" key={i}>
<Lens borderRadius="12px" onKeyDown={() => onClickWallet(wallet)}>
<RowHighlightWrapper key={i}>
<Inset horizontal="12px" key={i}>
<WalletRow
testId={`wallet-${i + 1}`}
onClick={onClickWallet}
key={wallet}
section={section}
wallet={wallet}
/>
</Inset>
</RowHighlightWrapper>
</Lens>
</Bleed>
))}
{wallets.map((wallet, i) => {
const address = typeof wallet === 'string' ? wallet : wallet.address;

return (
<Bleed horizontal="12px" key={i}>
<Lens
borderRadius="12px"
onKeyDown={() => onClickWallet(address)}
>
<RowHighlightWrapper key={i}>
<Inset horizontal="12px" key={i}>
<WalletRow
testId={`wallet-${i + 1}`}
onClick={onClickWallet}
key={address}
section={section}
wallet={wallet}
/>
</Inset>
</RowHighlightWrapper>
</Lens>
</Bleed>
);
})}
</Box>
</Stack>
) : null;
Expand All @@ -101,30 +114,38 @@ const WalletRow = ({
section,
testId,
}: {
wallet: Address;
wallet: Address | VisibleOwnedWallet;
onClick: (address: Address) => void;
section: 'contacts' | 'my_wallets' | 'watching';
testId?: string;
}) => {
const address = typeof wallet === 'string' ? wallet : wallet.address;

const { displayName, contactAddress, contactName, isNameDefined } =
useWalletInfo({
address: wallet,
address,
});
const name =
section === 'contacts'
? contactName || truncateAddress(contactAddress)
: displayName;

const hardwareWalletVendor =
typeof wallet !== 'string' &&
wallet.type === KeychainType.HardwareWalletKeychain
? wallet.vendor
: null;

return (
<Box
testId={testId}
key={wallet}
onClick={() => onClick(wallet)}
key={address}
onClick={() => onClick(address)}
paddingVertical="8px"
>
<Columns alignVertical="center" space="8px">
<Column width="content">
<WalletAvatar size={36} addressOrName={wallet} emojiSize="20pt" />
<WalletAvatar size={36} addressOrName={address} emojiSize="20pt" />
</Column>
<Column>
<Stack space="8px">
Expand All @@ -134,11 +155,23 @@ const WalletRow = ({

{isNameDefined && (
<Text weight="semibold" size="12pt" color="labelTertiary">
{truncateAddress(wallet)}
{truncateAddress(address)}
</Text>
)}
</Stack>
</Column>

{!!hardwareWalletVendor && (
<Column width="content">
<LabelPill
dot
label={i18n.t(
`wallet_switcher.${hardwareWalletVendor.toLowerCase()}`,
)}
background="surfaceSecondary"
/>
</Column>
)}
</Columns>
</Box>
);
Expand All @@ -150,7 +183,7 @@ const DropdownWalletsList = ({
watchedWallets,
selectWalletAndCloseDropdown,
}: {
wallets: Address[];
wallets: VisibleOwnedWallets;
contacts: Address[];
watchedWallets: Address[];
selectWalletAndCloseDropdown: (address: Address) => void;
Expand Down Expand Up @@ -322,7 +355,9 @@ export const ToAddressInput = React.forwardRef<InputRefAPI, ToAddressProps>(
filter: toAddress ? undefined : toAddressOrName,
});
const { currentAddress } = useCurrentAddressStore();
const selectableWallets = wallets.filter((a) => a !== currentAddress);
const selectableWallets = wallets.filter(
(w) => w.address !== currentAddress,
);
const { sendAddress: savedSendAddress } = usePopupInstanceStore();

useEffect(() => {
Expand Down

0 comments on commit add44e3

Please sign in to comment.