1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-11 20:27:12 +01:00
metamask-extension/ui/components/app/token-cell/token-cell.js

94 lines
2.6 KiB
JavaScript
Raw Normal View History

import classnames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import { useSelector } from 'react-redux';
import AssetListItem from '../asset-list-item';
2023-03-23 11:08:33 +01:00
import { getSelectedAddress, getTokenList } from '../../../selectors';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { useTokenFiatAmount } from '../../../hooks/useTokenFiatAmount';
2023-03-23 11:08:33 +01:00
import { MultichainTokenListItem } from '../../multichain';
import { ButtonLink, Text } from '../../component-library';
import { TextColor } from '../../../helpers/constants/design-system';
2020-11-03 00:41:28 +01:00
export default function TokenCell({
address,
decimals,
balanceError,
image,
symbol,
string,
onClick,
isERC721,
}) {
const userAddress = useSelector(getSelectedAddress);
const t = useI18nContext();
2023-03-23 11:08:33 +01:00
const tokenList = useSelector(getTokenList);
const tokenData = Object.values(tokenList).find(
(token) => token.symbol === symbol,
);
const title = tokenData?.name || symbol;
const tokenImage = tokenData?.iconUrl || image;
const formattedFiat = useTokenFiatAmount(address, string, symbol);
const warning = balanceError ? (
2023-03-23 11:08:33 +01:00
<Text as="span">
2020-11-03 00:41:28 +01:00
{t('troubleTokenBalances')}
2023-03-23 11:08:33 +01:00
<ButtonLink
2020-11-03 00:41:28 +01:00
href={`https://ethplorer.io/address/${userAddress}`}
2023-03-23 11:08:33 +01:00
externalLink
onClick={(event) => event.stopPropagation()}
2023-03-23 11:08:33 +01:00
textProps={{
color: TextColor.warningDefault,
}}
2020-11-03 00:41:28 +01:00
>
{t('here')}
2023-03-23 11:08:33 +01:00
</ButtonLink>
</Text>
) : null;
return (
2023-03-23 11:08:33 +01:00
<>
{process.env.MULTICHAIN ? (
<MultichainTokenListItem
onClick={() => onClick(address)}
tokenSymbol={symbol}
tokenImage={tokenImage}
primary={`${string || 0}`}
secondary={formattedFiat}
title={title}
/>
) : (
<AssetListItem
className={classnames('token-cell', {
'token-cell--outdated': Boolean(balanceError),
})}
iconClassName="token-cell__icon"
onClick={() => onClick(address)}
tokenAddress={address}
tokenSymbol={symbol}
tokenDecimals={decimals}
tokenImage={image}
warning={warning}
primary={`${string || 0}`}
secondary={formattedFiat}
isERC721={isERC721}
/>
)}
</>
);
}
TokenCell.propTypes = {
address: PropTypes.string,
balanceError: PropTypes.object,
symbol: PropTypes.string,
decimals: PropTypes.number,
string: PropTypes.string,
onClick: PropTypes.func.isRequired,
isERC721: PropTypes.bool,
image: PropTypes.string,
};
TokenCell.defaultProps = {
balanceError: null,
};