2023-04-27 16:28:08 +02:00
|
|
|
import React, { useContext } from 'react';
|
2023-03-23 11:08:33 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import {
|
2023-06-13 17:17:21 +02:00
|
|
|
BlockSize,
|
2023-03-23 11:08:33 +01:00
|
|
|
BorderColor,
|
2023-06-13 17:17:21 +02:00
|
|
|
Display,
|
|
|
|
FlexDirection,
|
2023-05-09 10:05:47 +02:00
|
|
|
FontWeight,
|
2023-03-23 11:08:33 +01:00
|
|
|
JustifyContent,
|
|
|
|
TextColor,
|
|
|
|
TextVariant,
|
2023-05-09 10:05:47 +02:00
|
|
|
TextAlign,
|
2023-03-23 11:08:33 +01:00
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import {
|
|
|
|
AvatarNetwork,
|
2023-07-24 20:15:33 +02:00
|
|
|
AvatarNetworkSize,
|
2023-03-23 11:08:33 +01:00
|
|
|
AvatarToken,
|
|
|
|
BadgeWrapper,
|
2023-06-13 17:17:21 +02:00
|
|
|
Box,
|
2023-07-18 07:02:02 +02:00
|
|
|
Text,
|
2023-03-23 11:08:33 +01:00
|
|
|
} from '../../component-library';
|
2023-07-12 19:27:39 +02:00
|
|
|
import {
|
|
|
|
getCurrentChainId,
|
|
|
|
getCurrentNetwork,
|
|
|
|
getNativeCurrencyImage,
|
2023-07-17 18:43:26 +02:00
|
|
|
getTestNetworkBackgroundColor,
|
2023-07-12 19:27:39 +02:00
|
|
|
} from '../../../selectors';
|
2023-03-23 11:08:33 +01:00
|
|
|
import Tooltip from '../../ui/tooltip';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2023-04-27 16:28:08 +02:00
|
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
|
|
|
import {
|
|
|
|
MetaMetricsEventCategory,
|
|
|
|
MetaMetricsEventName,
|
|
|
|
} from '../../../../shared/constants/metametrics';
|
2023-03-23 11:08:33 +01:00
|
|
|
|
2023-06-14 17:51:19 +02:00
|
|
|
export const TokenListItem = ({
|
2023-03-23 11:08:33 +01:00
|
|
|
className,
|
|
|
|
onClick,
|
|
|
|
tokenSymbol,
|
|
|
|
tokenImage,
|
|
|
|
primary,
|
|
|
|
secondary,
|
|
|
|
title,
|
|
|
|
}) => {
|
|
|
|
const t = useI18nContext();
|
|
|
|
const primaryTokenImage = useSelector(getNativeCurrencyImage);
|
2023-04-27 16:28:08 +02:00
|
|
|
const trackEvent = useContext(MetaMetricsContext);
|
|
|
|
const chainId = useSelector(getCurrentChainId);
|
2023-08-02 11:37:12 +02:00
|
|
|
const tokenTitle = title === 'ETH' ? t('networkNameEthereum') : title;
|
2023-04-27 16:28:08 +02:00
|
|
|
|
2023-07-12 19:27:39 +02:00
|
|
|
// Used for badge icon
|
|
|
|
const currentNetwork = useSelector(getCurrentNetwork);
|
2023-07-17 18:43:26 +02:00
|
|
|
const testNetworkBackgroundColor = useSelector(getTestNetworkBackgroundColor);
|
|
|
|
|
2023-03-23 11:08:33 +01:00
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
className={classnames('multichain-token-list-item', className)}
|
2023-06-13 17:17:21 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Column}
|
2023-03-23 11:08:33 +01:00
|
|
|
gap={4}
|
|
|
|
data-testid="multichain-token-list-item"
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
className="multichain-token-list-item__container-cell"
|
2023-06-13 17:17:21 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Row}
|
2023-03-23 11:08:33 +01:00
|
|
|
padding={4}
|
|
|
|
as="a"
|
|
|
|
data-testid="multichain-token-list-button"
|
|
|
|
href="#"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
onClick();
|
2023-04-27 16:28:08 +02:00
|
|
|
trackEvent({
|
|
|
|
category: MetaMetricsEventCategory.Tokens,
|
|
|
|
event: MetaMetricsEventName.TokenDetailsOpened,
|
|
|
|
properties: {
|
|
|
|
location: 'Home',
|
|
|
|
chain_id: chainId,
|
|
|
|
token_symbol: tokenSymbol,
|
|
|
|
},
|
|
|
|
});
|
2023-03-23 11:08:33 +01:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<BadgeWrapper
|
|
|
|
badge={
|
|
|
|
<AvatarNetwork
|
2023-07-24 20:15:33 +02:00
|
|
|
size={AvatarNetworkSize.Xs}
|
2023-07-12 19:27:39 +02:00
|
|
|
name={currentNetwork?.nickname}
|
|
|
|
src={currentNetwork?.rpcPrefs?.imageUrl}
|
2023-07-17 18:43:26 +02:00
|
|
|
backgroundColor={testNetworkBackgroundColor}
|
2023-03-23 11:08:33 +01:00
|
|
|
borderColor={
|
2023-07-12 19:27:39 +02:00
|
|
|
primaryTokenImage
|
2023-03-23 11:08:33 +01:00
|
|
|
? BorderColor.borderMuted
|
|
|
|
: BorderColor.borderDefault
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
marginRight={3}
|
|
|
|
>
|
|
|
|
<AvatarToken
|
|
|
|
name={tokenSymbol}
|
2023-07-12 19:27:39 +02:00
|
|
|
src={tokenImage}
|
2023-03-23 11:08:33 +01:00
|
|
|
showHalo
|
|
|
|
borderColor={
|
2023-07-12 19:27:39 +02:00
|
|
|
tokenImage ? BorderColor.transparent : BorderColor.borderDefault
|
2023-03-23 11:08:33 +01:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
</BadgeWrapper>
|
|
|
|
<Box
|
|
|
|
className="multichain-token-list-item__container-cell--text-container"
|
2023-06-13 17:17:21 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Column}
|
|
|
|
width={BlockSize.Full}
|
2023-03-23 11:08:33 +01:00
|
|
|
style={{ flexGrow: 1, overflow: 'hidden' }}
|
|
|
|
>
|
|
|
|
<Box
|
2023-06-13 17:17:21 +02:00
|
|
|
display={Display.Flex}
|
2023-03-23 11:08:33 +01:00
|
|
|
justifyContent={JustifyContent.spaceBetween}
|
|
|
|
gap={1}
|
|
|
|
>
|
2023-06-13 17:17:21 +02:00
|
|
|
<Box width={BlockSize.OneThird}>
|
2023-08-02 11:37:12 +02:00
|
|
|
{title?.length > 12 ? (
|
|
|
|
<Tooltip
|
|
|
|
position="bottom"
|
|
|
|
interactive
|
|
|
|
html={title}
|
|
|
|
tooltipInnerClassName="multichain-token-list-item__tooltip"
|
|
|
|
>
|
|
|
|
<Text
|
|
|
|
fontWeight={FontWeight.Medium}
|
|
|
|
variant={TextVariant.bodyMd}
|
|
|
|
ellipsis
|
|
|
|
>
|
|
|
|
{tokenTitle}
|
|
|
|
</Text>
|
|
|
|
</Tooltip>
|
|
|
|
) : (
|
2023-03-23 11:08:33 +01:00
|
|
|
<Text
|
2023-05-09 10:05:47 +02:00
|
|
|
fontWeight={FontWeight.Medium}
|
2023-03-23 11:08:33 +01:00
|
|
|
variant={TextVariant.bodyMd}
|
|
|
|
ellipsis
|
|
|
|
>
|
2023-08-02 11:37:12 +02:00
|
|
|
{tokenTitle}
|
2023-03-23 11:08:33 +01:00
|
|
|
</Text>
|
2023-08-02 11:37:12 +02:00
|
|
|
)}
|
2023-03-23 11:08:33 +01:00
|
|
|
</Box>
|
|
|
|
<Text
|
2023-05-09 10:05:47 +02:00
|
|
|
fontWeight={FontWeight.Medium}
|
2023-03-23 11:08:33 +01:00
|
|
|
variant={TextVariant.bodyMd}
|
2023-06-13 17:17:21 +02:00
|
|
|
width={BlockSize.TwoThirds}
|
2023-05-09 10:05:47 +02:00
|
|
|
textAlign={TextAlign.End}
|
2023-03-23 11:08:33 +01:00
|
|
|
>
|
|
|
|
{secondary}
|
|
|
|
</Text>
|
|
|
|
</Box>
|
2023-06-01 23:14:38 +02:00
|
|
|
<Text
|
|
|
|
color={TextColor.textAlternative}
|
|
|
|
data-testid="multichain-token-list-item-value"
|
|
|
|
>
|
2023-05-03 18:51:12 +02:00
|
|
|
{primary} {tokenSymbol}{' '}
|
2023-03-23 11:08:33 +01:00
|
|
|
</Text>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-06-14 17:51:19 +02:00
|
|
|
TokenListItem.propTypes = {
|
2023-03-23 11:08:33 +01:00
|
|
|
/**
|
|
|
|
* An additional className to apply to the TokenList.
|
|
|
|
*/
|
|
|
|
className: PropTypes.string,
|
|
|
|
/**
|
2023-06-14 17:51:19 +02:00
|
|
|
* The onClick handler to be passed to the TokenListItem component
|
2023-03-23 11:08:33 +01:00
|
|
|
*/
|
|
|
|
onClick: PropTypes.func,
|
|
|
|
/**
|
|
|
|
* tokenSymbol represents the symbol of the Token
|
|
|
|
*/
|
|
|
|
tokenSymbol: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* title represents the name of the token and if name is not available then Symbol
|
|
|
|
*/
|
|
|
|
title: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* tokenImage represnts the image of the token icon
|
|
|
|
*/
|
|
|
|
tokenImage: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* primary represents the balance
|
|
|
|
*/
|
|
|
|
primary: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* secondary represents the balance in dollars
|
|
|
|
*/
|
|
|
|
secondary: PropTypes.string,
|
|
|
|
};
|