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 Tooltip from '../../ui/tooltip'; import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display'; import { PRIMARY, SECONDARY } from '../../../helpers/constants/common'; import { isBalanceCached, getShouldShowFiat, getCurrentKeyring, getSwapsDefaultToken, getIsSwapsChain, getIsBridgeChain, getIsBuyableChain, getNativeCurrencyImage, getSelectedAccountCachedBalance, } from '../../../selectors'; import { setSwapsFromToken } from '../../../ducks/swaps/swaps'; import IconButton from '../../ui/icon-button'; import { isHardwareKeyring } from '../../../helpers/utils/hardware'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import { MetaMetricsContextProp, MetaMetricsEventCategory, MetaMetricsEventName, MetaMetricsSwapsEventSource, } from '../../../../shared/constants/metametrics'; import Spinner from '../../ui/spinner'; import { startNewDraftTransaction } from '../../../ducks/send'; import { AssetType } from '../../../../shared/constants/transaction'; import { ButtonIcon, BUTTON_ICON_SIZES } from '../../component-library'; import { Icon, ICON_NAMES } from '../../component-library/icon/deprecated'; import { IconColor } from '../../../helpers/constants/design-system'; import useRamps from '../../../hooks/experiences/useRamps'; import WalletOverview from './wallet-overview'; const EthOverview = ({ className }) => { const dispatch = useDispatch(); const t = useContext(I18nContext); const trackEvent = useContext(MetaMetricsContext); const history = useHistory(); const keyring = useSelector(getCurrentKeyring); const usingHardwareWallet = isHardwareKeyring(keyring?.type); const balanceIsCached = useSelector(isBalanceCached); const showFiat = useSelector(getShouldShowFiat); const balance = useSelector(getSelectedAccountCachedBalance); const isSwapsChain = useSelector(getIsSwapsChain); const isBridgeChain = useSelector(getIsBridgeChain); const isBuyableChain = useSelector(getIsBuyableChain); const primaryTokenImage = useSelector(getNativeCurrencyImage); const defaultSwapsToken = useSelector(getSwapsDefaultToken); const { openBuyCryptoInPdapp } = useRamps(); return (
{balance ? ( ) : ( )} {balanceIsCached ? ( * ) : null} { const portfolioUrl = process.env.PORTFOLIO_URL; global.platform.openTab({ url: `${portfolioUrl}?metamaskEntry=ext`, }); trackEvent( { category: MetaMetricsEventCategory.Home, event: MetaMetricsEventName.PortfolioLinkClicked, properties: { url: portfolioUrl, }, }, { contextPropsIntoEventProperties: [ MetaMetricsContextProp.PageTitle, ], }, ); }} />
{showFiat && balance && ( )}
} buttons={ <> } disabled={!isBuyableChain} data-testid="eth-overview-buy" label={t('buy')} onClick={() => { openBuyCryptoInPdapp(); trackEvent({ event: MetaMetricsEventName.NavBuyButtonClicked, category: MetaMetricsEventCategory.Navigation, properties: { location: 'Home', text: 'Buy', }, }); }} /> } label={t('send')} onClick={() => { trackEvent({ event: MetaMetricsEventName.NavSendButtonClicked, category: MetaMetricsEventCategory.Navigation, properties: { token_symbol: 'ETH', location: 'Home', text: 'Send', }, }); dispatch( startNewDraftTransaction({ type: AssetType.native }), ).then(() => { history.push(SEND_ROUTE); }); }} /> } onClick={() => { if (isSwapsChain) { trackEvent({ event: MetaMetricsEventName.NavSwapButtonClicked, category: MetaMetricsEventCategory.Swaps, properties: { token_symbol: 'ETH', location: MetaMetricsSwapsEventSource.MainView, text: 'Swap', }, }); dispatch(setSwapsFromToken(defaultSwapsToken)); if (usingHardwareWallet) { global.platform.openExtensionInBrowser(BUILD_QUOTE_ROUTE); } else { history.push(BUILD_QUOTE_ROUTE); } } }} label={t('swap')} tooltipRender={ isSwapsChain ? null : (contents) => ( {contents} ) } /> } label={t('bridge')} onClick={() => { if (isBridgeChain) { const portfolioUrl = process.env.PORTFOLIO_URL; const bridgeUrl = `${portfolioUrl}/bridge`; global.platform.openTab({ url: `${bridgeUrl}?metamaskEntry=ext`, }); trackEvent({ category: MetaMetricsEventCategory.Navigation, event: MetaMetricsEventName.BridgeLinkClicked, properties: { location: 'Home', text: 'Bridge', }, }); } }} tooltipRender={ isBridgeChain ? null : (contents) => ( {contents} ) } /> } className={className} icon={} /> ); }; EthOverview.propTypes = { className: PropTypes.string, }; EthOverview.defaultProps = { className: undefined, }; export default EthOverview;