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 Identicon from '../../ui/identicon'; import { I18nContext } from '../../../contexts/i18n'; import { SEND_ROUTE, BUILD_QUOTE_ROUTE, } from '../../../helpers/constants/routes'; import { useMetricEvent, useNewMetricEvent, } from '../../../hooks/useMetricEvent'; import Tooltip from '../../ui/tooltip'; import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display'; import { PRIMARY, SECONDARY } from '../../../helpers/constants/common'; import { showModal } from '../../../store/actions'; import { isBalanceCached, getSelectedAccount, getShouldShowFiat, getCurrentKeyring, getSwapsDefaultToken, getIsSwapsChain, getIsBuyableChain, getNativeCurrencyImage, } from '../../../selectors/selectors'; import SwapIcon from '../../ui/icon/swap-icon.component'; import BuyIcon from '../../ui/icon/overview-buy-icon.component'; import SendIcon from '../../ui/icon/overview-send-icon.component'; import { setSwapsFromToken } from '../../../ducks/swaps/swaps'; import IconButton from '../../ui/icon-button'; import { isHardwareKeyring } from '../../../helpers/utils/hardware'; import WalletOverview from './wallet-overview'; const EthOverview = ({ className }) => { const dispatch = useDispatch(); const t = useContext(I18nContext); const sendEvent = useMetricEvent({ eventOpts: { category: 'Navigation', action: 'Home', name: 'Clicked Send: Eth', }, }); const depositEvent = useMetricEvent({ eventOpts: { category: 'Navigation', action: 'Home', name: 'Clicked Deposit', }, }); const history = useHistory(); const keyring = useSelector(getCurrentKeyring); const usingHardwareWallet = isHardwareKeyring(keyring.type); const balanceIsCached = useSelector(isBalanceCached); const showFiat = useSelector(getShouldShowFiat); const selectedAccount = useSelector(getSelectedAccount); const { balance } = selectedAccount; const isSwapsChain = useSelector(getIsSwapsChain); const isBuyableChain = useSelector(getIsBuyableChain); const primaryTokenImage = useSelector(getNativeCurrencyImage); const enteredSwapsEvent = useNewMetricEvent({ event: 'Swaps Opened', properties: { source: 'Main View', active_currency: 'ETH' }, category: 'swaps', }); const defaultSwapsToken = useSelector(getSwapsDefaultToken); return (
{balanceIsCached ? ( * ) : null}
{showFiat && ( )}
} buttons={ <> { depositEvent(); dispatch(showModal({ name: 'DEPOSIT_ETHER' })); }} /> { sendEvent(); history.push(SEND_ROUTE); }} /> { if (isSwapsChain) { enteredSwapsEvent(); dispatch(setSwapsFromToken(defaultSwapsToken)); if (usingHardwareWallet) { global.platform.openExtensionInBrowser(BUILD_QUOTE_ROUTE); } else { history.push(BUILD_QUOTE_ROUTE); } } }} label={t('swap')} tooltipRender={(contents) => ( {contents} )} /> } className={className} icon={} /> ); }; EthOverview.propTypes = { className: PropTypes.string, }; EthOverview.defaultProps = { className: undefined, }; export default EthOverview;