mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-04 23:14:56 +01:00
ece437b139
* updating controllers with conversionRate change with minimal required changes in extension * swapping showFiat selector in places where possible * adding invalid conversion protection * lint fixes * adjusting list-item styling logic
103 lines
3.0 KiB
JavaScript
103 lines
3.0 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { useSelector } from 'react-redux';
|
|
import { useHistory } from 'react-router-dom';
|
|
import AddTokenButton from '../add-token-button';
|
|
import TokenList from '../token-list';
|
|
import { ADD_TOKEN_ROUTE } from '../../../helpers/constants/routes';
|
|
import AssetListItem from '../asset-list-item';
|
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
|
import { useMetricEvent } from '../../../hooks/useMetricEvent';
|
|
import { useUserPreferencedCurrency } from '../../../hooks/useUserPreferencedCurrency';
|
|
import {
|
|
getCurrentAccountWithSendEtherInfo,
|
|
getShouldShowFiat,
|
|
getNativeCurrencyImage,
|
|
} from '../../../selectors';
|
|
import { getNativeCurrency } from '../../../ducks/metamask/metamask';
|
|
import { useCurrencyDisplay } from '../../../hooks/useCurrencyDisplay';
|
|
|
|
const AssetList = ({ onClickAsset }) => {
|
|
const history = useHistory();
|
|
const selectedAccountBalance = useSelector(
|
|
(state) => getCurrentAccountWithSendEtherInfo(state).balance,
|
|
);
|
|
const nativeCurrency = useSelector(getNativeCurrency);
|
|
const showFiat = useSelector(getShouldShowFiat);
|
|
const selectTokenEvent = useMetricEvent({
|
|
eventOpts: {
|
|
category: 'Navigation',
|
|
action: 'Token Menu',
|
|
name: 'Clicked Token',
|
|
},
|
|
});
|
|
const addTokenEvent = useMetricEvent({
|
|
eventOpts: {
|
|
category: 'Navigation',
|
|
action: 'Token Menu',
|
|
name: 'Clicked "Add Token"',
|
|
},
|
|
});
|
|
|
|
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);
|
|
|
|
return (
|
|
<>
|
|
<AssetListItem
|
|
onClick={() => onClickAsset(nativeCurrency)}
|
|
data-testid="wallet-balance"
|
|
primary={
|
|
primaryCurrencyProperties.value ?? secondaryCurrencyProperties.value
|
|
}
|
|
tokenSymbol={primaryCurrencyProperties.suffix}
|
|
secondary={showFiat ? secondaryCurrencyDisplay : undefined}
|
|
tokenImage={primaryTokenImage}
|
|
identiconBorder
|
|
/>
|
|
<TokenList
|
|
onTokenClick={(tokenAddress) => {
|
|
onClickAsset(tokenAddress);
|
|
selectTokenEvent();
|
|
}}
|
|
/>
|
|
<AddTokenButton
|
|
onClick={() => {
|
|
history.push(ADD_TOKEN_ROUTE);
|
|
addTokenEvent();
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
AssetList.propTypes = {
|
|
onClickAsset: PropTypes.func.isRequired,
|
|
};
|
|
|
|
export default AssetList;
|