2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
2021-09-10 20:03:42 +02:00
|
|
|
import ImportTokenLink from '../import-token-link';
|
2021-02-04 19:15:23 +01:00
|
|
|
import TokenList from '../token-list';
|
2021-09-10 22:21:04 +02:00
|
|
|
import { IMPORT_TOKEN_ROUTE } from '../../../helpers/constants/routes';
|
2021-02-04 19:15:23 +01:00
|
|
|
import AssetListItem from '../asset-list-item';
|
|
|
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
|
|
|
import { useMetricEvent } from '../../../hooks/useMetricEvent';
|
|
|
|
import { useUserPreferencedCurrency } from '../../../hooks/useUserPreferencedCurrency';
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
getCurrentAccountWithSendEtherInfo,
|
|
|
|
getShouldShowFiat,
|
2021-04-02 00:57:00 +02:00
|
|
|
getNativeCurrencyImage,
|
2021-09-27 19:42:51 +02:00
|
|
|
getIsMainnet,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../selectors';
|
2021-06-08 18:03:59 +02:00
|
|
|
import { getNativeCurrency } from '../../../ducks/metamask/metamask';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { useCurrencyDisplay } from '../../../hooks/useCurrencyDisplay';
|
2021-09-10 20:03:42 +02:00
|
|
|
import Typography from '../../ui/typography/typography';
|
|
|
|
import Box from '../../ui/box/box';
|
|
|
|
import {
|
|
|
|
COLORS,
|
|
|
|
TYPOGRAPHY,
|
|
|
|
FONT_WEIGHT,
|
|
|
|
JUSTIFY_CONTENT,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2020-05-14 05:16:30 +02:00
|
|
|
|
2020-06-01 19:54:32 +02:00
|
|
|
const AssetList = ({ onClickAsset }) => {
|
2021-09-10 20:03:42 +02:00
|
|
|
const t = useI18nContext();
|
2021-02-04 19:15:23 +01:00
|
|
|
const history = useHistory();
|
2020-11-03 00:41:28 +01:00
|
|
|
const selectedAccountBalance = useSelector(
|
|
|
|
(state) => getCurrentAccountWithSendEtherInfo(state).balance,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const nativeCurrency = useSelector(getNativeCurrency);
|
|
|
|
const showFiat = useSelector(getShouldShowFiat);
|
2020-05-21 18:06:06 +02:00
|
|
|
const selectTokenEvent = useMetricEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Navigation',
|
|
|
|
action: 'Token Menu',
|
|
|
|
name: 'Clicked Token',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-21 18:06:06 +02:00
|
|
|
const addTokenEvent = useMetricEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Navigation',
|
|
|
|
action: 'Token Menu',
|
|
|
|
name: 'Clicked "Add Token"',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-14 05:16:30 +02:00
|
|
|
|
|
|
|
const {
|
|
|
|
currency: primaryCurrency,
|
|
|
|
numberOfDecimals: primaryNumberOfDecimals,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = useUserPreferencedCurrency(PRIMARY, { ethNumberOfDecimals: 4 });
|
2020-05-14 05:16:30 +02:00
|
|
|
const {
|
|
|
|
currency: secondaryCurrency,
|
|
|
|
numberOfDecimals: secondaryNumberOfDecimals,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = useUserPreferencedCurrency(SECONDARY, { ethNumberOfDecimals: 4 });
|
2020-05-14 05:16:30 +02:00
|
|
|
|
2020-11-05 23:16:24 +01:00
|
|
|
const [, primaryCurrencyProperties] = useCurrencyDisplay(
|
|
|
|
selectedAccountBalance,
|
|
|
|
{
|
|
|
|
numberOfDecimals: primaryNumberOfDecimals,
|
|
|
|
currency: primaryCurrency,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-06-03 19:50:12 +02:00
|
|
|
|
2021-06-24 01:28:49 +02:00
|
|
|
const [
|
|
|
|
secondaryCurrencyDisplay,
|
|
|
|
secondaryCurrencyProperties,
|
|
|
|
] = useCurrencyDisplay(selectedAccountBalance, {
|
|
|
|
numberOfDecimals: secondaryNumberOfDecimals,
|
|
|
|
currency: secondaryCurrency,
|
|
|
|
});
|
2020-06-03 19:50:12 +02:00
|
|
|
|
2021-04-02 00:57:00 +02:00
|
|
|
const primaryTokenImage = useSelector(getNativeCurrencyImage);
|
2021-09-27 19:42:51 +02:00
|
|
|
const isMainnet = useSelector(getIsMainnet) || process.env.IN_TEST;
|
2021-04-02 00:57:00 +02:00
|
|
|
|
2020-05-14 05:16:30 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<AssetListItem
|
2020-06-01 19:54:32 +02:00
|
|
|
onClick={() => onClickAsset(nativeCurrency)}
|
2020-05-14 05:16:30 +02:00
|
|
|
data-testid="wallet-balance"
|
2021-06-24 01:28:49 +02:00
|
|
|
primary={
|
|
|
|
primaryCurrencyProperties.value ?? secondaryCurrencyProperties.value
|
|
|
|
}
|
2020-11-05 23:16:24 +01:00
|
|
|
tokenSymbol={primaryCurrencyProperties.suffix}
|
2020-06-06 00:06:15 +02:00
|
|
|
secondary={showFiat ? secondaryCurrencyDisplay : undefined}
|
2021-04-02 00:57:00 +02:00
|
|
|
tokenImage={primaryTokenImage}
|
|
|
|
identiconBorder
|
2020-06-03 19:50:12 +02:00
|
|
|
/>
|
2020-05-14 05:16:30 +02:00
|
|
|
<TokenList
|
|
|
|
onTokenClick={(tokenAddress) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
onClickAsset(tokenAddress);
|
|
|
|
selectTokenEvent();
|
2020-05-14 05:16:30 +02:00
|
|
|
}}
|
|
|
|
/>
|
2021-09-10 20:03:42 +02:00
|
|
|
<Box marginTop={4}>
|
|
|
|
<Box justifyContent={JUSTIFY_CONTENT.CENTER}>
|
|
|
|
<Typography
|
|
|
|
color={COLORS.UI4}
|
|
|
|
variant={TYPOGRAPHY.H6}
|
|
|
|
fontWeight={FONT_WEIGHT.NORMAL}
|
|
|
|
>
|
|
|
|
{t('missingToken')}
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
<ImportTokenLink
|
2021-09-27 19:42:51 +02:00
|
|
|
isMainnet={isMainnet}
|
2021-09-10 20:03:42 +02:00
|
|
|
onClick={() => {
|
2021-09-10 22:21:04 +02:00
|
|
|
history.push(IMPORT_TOKEN_ROUTE);
|
2021-09-10 20:03:42 +02:00
|
|
|
addTokenEvent();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Box>
|
2020-05-14 05:16:30 +02:00
|
|
|
</>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-05-14 05:16:30 +02:00
|
|
|
|
2020-06-01 19:54:32 +02:00
|
|
|
AssetList.propTypes = {
|
|
|
|
onClickAsset: PropTypes.func.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-06-01 19:54:32 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default AssetList;
|