2023-03-30 20:11:13 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import {
|
|
|
|
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-05-09 10:05:47 +02:00
|
|
|
FontWeight,
|
2023-03-30 20:11:13 +02:00
|
|
|
IconColor,
|
|
|
|
Size,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
|
2023-05-08 19:32:39 +02:00
|
|
|
export const AccountPicker = ({ address, name, onClick, disabled }) => {
|
2023-03-30 20:11:13 +02:00
|
|
|
const useBlockie = useSelector((state) => state.metamask.useBlockie);
|
|
|
|
|
|
|
|
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
|
|
|
>
|
|
|
|
<AvatarAccount
|
|
|
|
variant={
|
|
|
|
useBlockie
|
|
|
|
? AvatarAccountVariant.Blockies
|
|
|
|
: AvatarAccountVariant.Jazzicon
|
|
|
|
}
|
|
|
|
address={address}
|
2023-05-05 07:21:10 +02:00
|
|
|
size={Size.XS}
|
|
|
|
borderColor={BackgroundColor.backgroundDefault} // we currently don't have white color for border hence using backgroundDefault as the border
|
2023-03-30 20:11:13 +02:00
|
|
|
/>
|
2023-05-09 10:05:47 +02:00
|
|
|
<Text as="span" fontWeight={FontWeight.Bold} ellipsis>
|
2023-03-30 20:11:13 +02:00
|
|
|
{name}
|
|
|
|
</Text>
|
|
|
|
<Icon
|
2023-04-14 00:24:47 +02:00
|
|
|
name={IconName.ArrowDown}
|
2023-03-30 20:11:13 +02:00
|
|
|
color={IconColor.iconDefault}
|
|
|
|
size={Size.SM}
|
|
|
|
/>
|
|
|
|
</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-03-30 20:11:13 +02:00
|
|
|
};
|