import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import Identicon from '../../ui/identicon'; import MetaFoxLogo from '../../ui/metafox-logo'; import { DEFAULT_ROUTE } from '../../../helpers/constants/routes'; import { MetaMetricsEventCategory, MetaMetricsEventName, } from '../../../../shared/constants/metametrics'; import NetworkDisplay from '../network-display'; ///: BEGIN:ONLY_INCLUDE_IN(build-beta) import BetaHeader from '../beta-header'; ///: END:ONLY_INCLUDE_IN export default class AppHeader extends PureComponent { static propTypes = { history: PropTypes.object, networkDropdownOpen: PropTypes.bool, showNetworkDropdown: PropTypes.func, hideNetworkDropdown: PropTypes.func, toggleAccountMenu: PropTypes.func, selectedAddress: PropTypes.string, isUnlocked: PropTypes.bool, hideNetworkIndicator: PropTypes.bool, disabled: PropTypes.bool, disableNetworkIndicator: PropTypes.bool, isAccountMenuOpen: PropTypes.bool, ///: BEGIN:ONLY_INCLUDE_IN(snaps) unreadNotificationsCount: PropTypes.number, ///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(desktop) desktopEnabled: PropTypes.bool, ///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(build-beta) showBetaHeader: PropTypes.bool, ///: END:ONLY_INCLUDE_IN onClick: PropTypes.func, ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) custodianIcon: PropTypes.string, ///: END:ONLY_INCLUDE_IN }; static contextTypes = { t: PropTypes.func, trackEvent: PropTypes.func, }; handleNetworkIndicatorClick(event) { event.preventDefault(); event.stopPropagation(); const { networkDropdownOpen, showNetworkDropdown, hideNetworkDropdown, disabled, disableNetworkIndicator, } = this.props; if (disabled || disableNetworkIndicator) { return; } if (networkDropdownOpen === false) { this.context.trackEvent({ category: MetaMetricsEventCategory.Navigation, event: MetaMetricsEventName.NavNetworkMenuOpened, properties: {}, }); showNetworkDropdown(); } else { hideNetworkDropdown(); } } renderAccountMenu() { const { isUnlocked, toggleAccountMenu, selectedAddress, disabled, isAccountMenuOpen, ///: BEGIN:ONLY_INCLUDE_IN(snaps) unreadNotificationsCount, ///: END:ONLY_INCLUDE_IN } = this.props; return ( isUnlocked && ( ) ); } render() { const { history, hideNetworkIndicator, disableNetworkIndicator, disabled, onClick, ///: BEGIN:ONLY_INCLUDE_IN(build-beta) showBetaHeader, ///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(desktop) desktopEnabled, ///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) custodianIcon, isUnlocked, ///: END:ONLY_INCLUDE_IN } = this.props; return ( <> { ///: BEGIN:ONLY_INCLUDE_IN(build-beta) showBetaHeader ? : null ///: END:ONLY_INCLUDE_IN }
{ if (onClick) { await onClick(); } history.push(DEFAULT_ROUTE); }} ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) custodyImgSrc={custodianIcon} isUnlocked={isUnlocked} ///: END:ONLY_INCLUDE_IN /> { ///: BEGIN:ONLY_INCLUDE_IN(desktop) desktopEnabled && process.env.METAMASK_DEBUG && (
) ///: END:ONLY_INCLUDE_IN }
{!hideNetworkIndicator && (
this.handleNetworkIndicatorClick(event)} disabled={disabled || disableNetworkIndicator} />
)} {this.renderAccountMenu()}
); } }