mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-25 11:28:51 +01:00
103 lines
3.4 KiB
JavaScript
103 lines
3.4 KiB
JavaScript
import React, { useState } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { useSelector } from 'react-redux';
|
|
import TokenList from '../token-list';
|
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
|
import { useUserPreferencedCurrency } from '../../../hooks/useUserPreferencedCurrency';
|
|
import {
|
|
getSelectedAccountCachedBalance,
|
|
getShouldShowFiat,
|
|
getNativeCurrencyImage,
|
|
getDetectedTokensInCurrentNetwork,
|
|
getIstokenDetectionInactiveOnNonMainnetSupportedNetwork,
|
|
} from '../../../selectors';
|
|
import { getNativeCurrency } from '../../../ducks/metamask/metamask';
|
|
import { useCurrencyDisplay } from '../../../hooks/useCurrencyDisplay';
|
|
import Box from '../../ui/box/box';
|
|
import DetectedToken from '../detected-token/detected-token';
|
|
import {
|
|
DetectedTokensBanner,
|
|
TokenListItem,
|
|
ImportTokenLink,
|
|
BalanceOverview,
|
|
} from '../../multichain';
|
|
|
|
const AssetList = ({ onClickAsset }) => {
|
|
const [showDetectedTokens, setShowDetectedTokens] = useState(false);
|
|
|
|
const selectedAccountBalance = useSelector(getSelectedAccountCachedBalance);
|
|
const nativeCurrency = useSelector(getNativeCurrency);
|
|
const showFiat = useSelector(getShouldShowFiat);
|
|
const balance = useSelector(getSelectedAccountCachedBalance);
|
|
const balanceIsLoading = !balance;
|
|
|
|
const {
|
|
currency: primaryCurrency,
|
|
numberOfDecimals: primaryNumberOfDecimals,
|
|
} = useUserPreferencedCurrency(PRIMARY, { ethNumberOfDecimals: 4 });
|
|
const {
|
|
currency: secondaryCurrency,
|
|
numberOfDecimals: secondaryNumberOfDecimals,
|
|
} = useUserPreferencedCurrency(SECONDARY, { ethNumberOfDecimals: 4 });
|
|
|
|
const [, primaryCurrencyProperties] = useCurrencyDisplay(
|
|
selectedAccountBalance,
|
|
{
|
|
numberOfDecimals: primaryNumberOfDecimals,
|
|
currency: primaryCurrency,
|
|
},
|
|
);
|
|
|
|
const [secondaryCurrencyDisplay, secondaryCurrencyProperties] =
|
|
useCurrencyDisplay(selectedAccountBalance, {
|
|
numberOfDecimals: secondaryNumberOfDecimals,
|
|
currency: secondaryCurrency,
|
|
});
|
|
|
|
const primaryTokenImage = useSelector(getNativeCurrencyImage);
|
|
const detectedTokens = useSelector(getDetectedTokensInCurrentNetwork) || [];
|
|
const isTokenDetectionInactiveOnNonMainnetSupportedNetwork = useSelector(
|
|
getIstokenDetectionInactiveOnNonMainnetSupportedNetwork,
|
|
);
|
|
|
|
return (
|
|
<>
|
|
{process.env.MULTICHAIN ? <BalanceOverview /> : null}
|
|
<TokenListItem
|
|
onClick={() => onClickAsset(nativeCurrency)}
|
|
title={nativeCurrency}
|
|
primary={
|
|
primaryCurrencyProperties.value ?? secondaryCurrencyProperties.value
|
|
}
|
|
tokenSymbol={primaryCurrencyProperties.suffix}
|
|
secondary={showFiat ? secondaryCurrencyDisplay : undefined}
|
|
tokenImage={balanceIsLoading ? null : primaryTokenImage}
|
|
/>
|
|
<TokenList
|
|
onTokenClick={(tokenAddress) => {
|
|
onClickAsset(tokenAddress);
|
|
}}
|
|
/>
|
|
{detectedTokens.length > 0 &&
|
|
!isTokenDetectionInactiveOnNonMainnetSupportedNetwork ? (
|
|
<DetectedTokensBanner
|
|
actionButtonOnClick={() => setShowDetectedTokens(true)}
|
|
margin={4}
|
|
/>
|
|
) : null}
|
|
<Box marginTop={detectedTokens.length > 0 ? 0 : 4}>
|
|
<ImportTokenLink margin={4} marginBottom={2} />
|
|
</Box>
|
|
{showDetectedTokens && (
|
|
<DetectedToken setShowDetectedTokens={setShowDetectedTokens} />
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
AssetList.propTypes = {
|
|
onClickAsset: PropTypes.func.isRequired,
|
|
};
|
|
|
|
export default AssetList;
|