2023-03-30 20:11:13 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useSelector } from 'react-redux';
|
2023-08-23 18:36:03 +02:00
|
|
|
import { toChecksumHexAddress } from '@metamask/controller-utils';
|
2023-03-30 20:11:13 +02:00
|
|
|
import {
|
2023-08-23 18:36:03 +02:00
|
|
|
Box,
|
2023-03-30 20:11:13 +02:00
|
|
|
Button,
|
|
|
|
AvatarAccount,
|
|
|
|
AvatarAccountVariant,
|
2023-04-14 00:24:47 +02:00
|
|
|
Icon,
|
|
|
|
IconName,
|
2023-07-18 07:02:02 +02:00
|
|
|
Text,
|
2023-03-30 20:11:13 +02:00
|
|
|
} from '../../component-library';
|
|
|
|
import {
|
|
|
|
AlignItems,
|
|
|
|
BackgroundColor,
|
|
|
|
BorderRadius,
|
2023-06-13 17:11:21 +02:00
|
|
|
Display,
|
2023-08-23 18:36:03 +02:00
|
|
|
FlexDirection,
|
2023-05-09 10:05:47 +02:00
|
|
|
FontWeight,
|
2023-03-30 20:11:13 +02:00
|
|
|
IconColor,
|
|
|
|
Size,
|
2023-08-23 18:36:03 +02:00
|
|
|
TextAlign,
|
|
|
|
TextColor,
|
|
|
|
TextVariant,
|
2023-03-30 20:11:13 +02:00
|
|
|
} from '../../../helpers/constants/design-system';
|
2023-08-31 15:53:22 +02:00
|
|
|
import { getUseBlockie } from '../../../selectors';
|
2023-08-23 18:36:03 +02:00
|
|
|
import { shortenAddress } from '../../../helpers/utils/util';
|
2023-03-30 20:11:13 +02:00
|
|
|
|
2023-08-23 18:36:03 +02:00
|
|
|
export const AccountPicker = ({
|
|
|
|
address,
|
|
|
|
name,
|
|
|
|
onClick,
|
|
|
|
disabled,
|
|
|
|
showAddress = false,
|
|
|
|
}) => {
|
2023-08-31 15:53:22 +02:00
|
|
|
const useBlockie = useSelector(getUseBlockie);
|
2023-08-23 18:36:03 +02:00
|
|
|
const shortenedAddress = shortenAddress(toChecksumHexAddress(address));
|
2023-03-30 20:11:13 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
className="multichain-account-picker"
|
2023-06-01 23:14:38 +02:00
|
|
|
data-testid="account-menu-icon"
|
2023-03-30 20:11:13 +02:00
|
|
|
onClick={onClick}
|
|
|
|
backgroundColor={BackgroundColor.transparent}
|
|
|
|
borderRadius={BorderRadius.LG}
|
|
|
|
ellipsis
|
|
|
|
textProps={{
|
2023-06-13 17:11:21 +02:00
|
|
|
display: Display.Flex,
|
2023-03-30 20:11:13 +02:00
|
|
|
gap: 2,
|
|
|
|
alignItems: AlignItems.center,
|
|
|
|
}}
|
2023-05-08 19:32:39 +02:00
|
|
|
disabled={disabled}
|
2023-03-30 20:11:13 +02:00
|
|
|
>
|
2023-08-23 18:36:03 +02:00
|
|
|
<Box
|
|
|
|
display={Display.Flex}
|
|
|
|
className="multichain-account-picker-container"
|
|
|
|
flexDirection={FlexDirection.Column}
|
|
|
|
>
|
|
|
|
<Box display={Display.Flex} alignItems={AlignItems.center} gap={1}>
|
|
|
|
<AvatarAccount
|
|
|
|
variant={
|
|
|
|
useBlockie
|
|
|
|
? AvatarAccountVariant.Blockies
|
|
|
|
: AvatarAccountVariant.Jazzicon
|
|
|
|
}
|
|
|
|
address={address}
|
|
|
|
size={Size.XS}
|
|
|
|
borderColor={BackgroundColor.backgroundDefault} // we currently don't have white color for border hence using backgroundDefault as the border
|
|
|
|
/>
|
|
|
|
<Text as="span" fontWeight={FontWeight.Bold} ellipsis>
|
|
|
|
{name}
|
|
|
|
</Text>
|
|
|
|
<Icon
|
|
|
|
name={IconName.ArrowDown}
|
|
|
|
color={IconColor.iconDefault}
|
|
|
|
size={Size.SM}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
{showAddress ? (
|
|
|
|
<Text
|
|
|
|
color={TextColor.textAlternative}
|
|
|
|
textAlign={TextAlign.Center}
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
>
|
|
|
|
{shortenedAddress}
|
|
|
|
</Text>
|
|
|
|
) : null}
|
|
|
|
</Box>
|
2023-03-30 20:11:13 +02:00
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
AccountPicker.propTypes = {
|
|
|
|
/**
|
|
|
|
* Account name
|
|
|
|
*/
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
/**
|
|
|
|
* Account address, used for blockie or jazzicon
|
|
|
|
*/
|
|
|
|
address: PropTypes.string.isRequired,
|
|
|
|
/**
|
|
|
|
* Action to perform when the account picker is clicked
|
|
|
|
*/
|
|
|
|
onClick: PropTypes.func.isRequired,
|
2023-05-08 19:32:39 +02:00
|
|
|
/**
|
|
|
|
* Represents if the AccountPicker should be actionable
|
|
|
|
*/
|
|
|
|
disabled: PropTypes.bool.isRequired,
|
2023-08-23 18:36:03 +02:00
|
|
|
/**
|
|
|
|
* Represents if the account address should display
|
|
|
|
*/
|
|
|
|
showAddress: PropTypes.bool,
|
2023-03-30 20:11:13 +02:00
|
|
|
};
|