import React, { useContext } from 'react'; import PropTypes from 'prop-types'; import { useHistory } from 'react-router-dom'; import { useDispatch, useSelector } from 'react-redux'; import { getAccountLink } from '@metamask/etherscan-link'; import { showModal } from '../../../store/actions'; import { CONNECTED_ROUTE, NETWORKS_ROUTE, } from '../../../helpers/constants/routes'; import { getURLHostName } from '../../../helpers/utils/util'; import { Menu, MenuItem } from '../../ui/menu'; import { getBlockExplorerLinkText, getCurrentChainId, getCurrentKeyring, getRpcPrefsForCurrentProvider, getSelectedIdentity, } from '../../../selectors'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { getEnvironmentType } from '../../../../app/scripts/lib/util'; import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../shared/constants/app'; import { KeyringType } from '../../../../shared/constants/keyring'; import { MetaMetricsEventCategory, MetaMetricsEventLinkType, MetaMetricsEventName, } from '../../../../shared/constants/metametrics'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import { IconName } from '../../component-library'; export default function AccountOptionsMenu({ anchorElement, onClose }) { const t = useI18nContext(); const dispatch = useDispatch(); const history = useHistory(); const keyring = useSelector(getCurrentKeyring); const chainId = useSelector(getCurrentChainId); const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider); const selectedIdentity = useSelector(getSelectedIdentity); const { address } = selectedIdentity; const addressLink = getAccountLink(address, chainId, rpcPrefs); const { blockExplorerUrl } = rpcPrefs; const blockExplorerUrlSubTitle = getURLHostName(blockExplorerUrl); const trackEvent = useContext(MetaMetricsContext); const blockExplorerLinkText = useSelector(getBlockExplorerLinkText); const isRemovable = keyring.type !== KeyringType.hdKeyTree; const routeToAddBlockExplorerUrl = () => { history.push(`${NETWORKS_ROUTE}#blockExplorerUrl`); }; const openBlockExplorer = () => { trackEvent({ event: MetaMetricsEventName.ExternalLinkClicked, category: MetaMetricsEventCategory.Navigation, properties: { link_type: MetaMetricsEventLinkType.AccountTracker, location: 'Account Options', url_domain: getURLHostName(addressLink), }, }); global.platform.openTab({ url: addressLink, }); onClose(); }; return (
); } AccountOptionsMenu.propTypes = { anchorElement: PropTypes.instanceOf(window.Element), onClose: PropTypes.func.isRequired, }; AccountOptionsMenu.defaultProps = { anchorElement: undefined, };