mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
109 lines
3.5 KiB
JavaScript
109 lines
3.5 KiB
JavaScript
import React, { useContext } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import classnames from 'classnames';
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import { I18nContext } from '../../../contexts/i18n';
|
|
import { SEND_ROUTE } from '../../../helpers/constants/routes';
|
|
import Tooltip from '../../ui/tooltip';
|
|
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display';
|
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
|
|
import {
|
|
isBalanceCached,
|
|
getShouldShowFiat,
|
|
getNativeCurrencyImage,
|
|
getSelectedAccountCachedBalance,
|
|
} from '../../../selectors';
|
|
import IconButton from '../../ui/icon-button';
|
|
import Spinner from '../../ui/spinner';
|
|
import { startNewDraftTransaction } from '../../../ducks/send';
|
|
import { AssetType } from '../../../../shared/constants/transaction';
|
|
import WalletOverview from './wallet-overview';
|
|
|
|
const EthOverview = ({ className }) => {
|
|
const dispatch = useDispatch();
|
|
const t = useContext(I18nContext);
|
|
const history = useHistory();
|
|
const balanceIsCached = useSelector(isBalanceCached);
|
|
const showFiat = useSelector(getShouldShowFiat);
|
|
const balance = useSelector(getSelectedAccountCachedBalance);
|
|
const primaryTokenImage = useSelector(getNativeCurrencyImage);
|
|
|
|
return (
|
|
<WalletOverview
|
|
balance={
|
|
<Tooltip
|
|
position="top"
|
|
title={t('balanceOutdated')}
|
|
disabled={!balanceIsCached}
|
|
>
|
|
<div className="eth-overview__balance">
|
|
<div className="eth-overview__primary-container">
|
|
{balance ? (
|
|
<UserPreferencedCurrencyDisplay
|
|
style={{ display: 'contents' }}
|
|
className={classnames('eth-overview__primary-balance', {
|
|
'eth-overview__cached-balance': balanceIsCached,
|
|
})}
|
|
data-testid="eth-overview__primary-currency"
|
|
value={balance}
|
|
type={PRIMARY}
|
|
ethNumberOfDecimals={4}
|
|
hideTitle
|
|
/>
|
|
) : (
|
|
<Spinner
|
|
color="var(--color-secondary-default)"
|
|
className="loading-overlay__spinner"
|
|
/>
|
|
)}
|
|
{balanceIsCached ? (
|
|
<span className="eth-overview__cached-star">*</span>
|
|
) : null}
|
|
</div>
|
|
{showFiat && balance && (
|
|
<UserPreferencedCurrencyDisplay
|
|
className={classnames({
|
|
'eth-overview__cached-secondary-balance': balanceIsCached,
|
|
'eth-overview__secondary-balance': !balanceIsCached,
|
|
})}
|
|
data-testid="eth-overview__secondary-currency"
|
|
value={balance}
|
|
type={SECONDARY}
|
|
ethNumberOfDecimals={4}
|
|
hideTitle
|
|
/>
|
|
)}
|
|
</div>
|
|
</Tooltip>
|
|
}
|
|
buttons={
|
|
<IconButton
|
|
className="eth-overview__button"
|
|
data-testid="eth-overview-send"
|
|
label={t('send')}
|
|
onClick={() => {
|
|
dispatch(startNewDraftTransaction({ type: AssetType.native })).then(
|
|
() => {
|
|
history.push(SEND_ROUTE);
|
|
},
|
|
);
|
|
}}
|
|
/>
|
|
}
|
|
className={className}
|
|
/>
|
|
);
|
|
};
|
|
|
|
EthOverview.propTypes = {
|
|
className: PropTypes.string,
|
|
};
|
|
|
|
EthOverview.defaultProps = {
|
|
className: undefined,
|
|
};
|
|
|
|
export default EthOverview;
|