2021-02-04 19:15:23 +01:00
|
|
|
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';
|
2021-02-04 19:15:23 +01:00
|
|
|
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-06-10 20:04:56 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function TokenCell({
|
2020-06-16 20:04:51 +02:00
|
|
|
address,
|
|
|
|
decimals,
|
2020-11-18 23:13:28 +01:00
|
|
|
balanceError,
|
2023-02-06 15:31:19 +01:00
|
|
|
image,
|
2020-06-16 20:04:51 +02:00
|
|
|
symbol,
|
|
|
|
string,
|
|
|
|
onClick,
|
2021-06-22 19:39:44 +02:00
|
|
|
isERC721,
|
2020-06-16 20:04:51 +02:00
|
|
|
}) {
|
2021-02-04 19:15:23 +01:00
|
|
|
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;
|
2021-02-04 19:15:23 +01:00
|
|
|
const formattedFiat = useTokenFiatAmount(address, string, symbol);
|
2020-11-18 23:13:28 +01:00
|
|
|
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
|
2020-11-18 23:13:28 +01:00
|
|
|
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>
|
2021-02-04 19:15:23 +01:00
|
|
|
) : null;
|
2020-06-03 19:50:12 +02:00
|
|
|
|
|
|
|
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}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-06-03 19:50:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TokenCell.propTypes = {
|
|
|
|
address: PropTypes.string,
|
2020-11-18 23:13:28 +01:00
|
|
|
balanceError: PropTypes.object,
|
2020-06-03 19:50:12 +02:00
|
|
|
symbol: PropTypes.string,
|
2020-06-16 20:04:51 +02:00
|
|
|
decimals: PropTypes.number,
|
2020-06-03 19:50:12 +02:00
|
|
|
string: PropTypes.string,
|
|
|
|
onClick: PropTypes.func.isRequired,
|
2021-06-22 19:39:44 +02:00
|
|
|
isERC721: PropTypes.bool,
|
2023-02-06 15:31:19 +01:00
|
|
|
image: PropTypes.string,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-06-03 19:50:12 +02:00
|
|
|
|
|
|
|
TokenCell.defaultProps = {
|
2020-11-18 23:13:28 +01:00
|
|
|
balanceError: null,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|