import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import classnames from 'classnames' import { matchPath } from 'react-router-dom' const { ENVIRONMENT_TYPE_NOTIFICATION, ENVIRONMENT_TYPE_POPUP, } = require('../../../../app/scripts/lib/enums') const { DEFAULT_ROUTE, INITIALIZE_ROUTE, CONFIRM_TRANSACTION_ROUTE } = require('../../routes') const Identicon = require('../identicon') const NetworkIndicator = require('../network') export default class AppHeader extends PureComponent { static propTypes = { history: PropTypes.object, location: PropTypes.object, network: PropTypes.string, provider: PropTypes.object, networkDropdownOpen: PropTypes.bool, showNetworkDropdown: PropTypes.func, hideNetworkDropdown: PropTypes.func, toggleAccountMenu: PropTypes.func, selectedAddress: PropTypes.string, isUnlocked: PropTypes.bool, } static contextTypes = { t: PropTypes.func, } handleNetworkIndicatorClick (event) { event.preventDefault() event.stopPropagation() const { networkDropdownOpen, showNetworkDropdown, hideNetworkDropdown } = this.props return networkDropdownOpen === false ? showNetworkDropdown() : hideNetworkDropdown() } isConfirming () { const { location } = this.props return Boolean(matchPath(location.pathname, { path: CONFIRM_TRANSACTION_ROUTE, exact: false, })) } renderAccountMenu () { const { isUnlocked, toggleAccountMenu, selectedAddress } = this.props return isUnlocked && (
this.isConfirming() || toggleAccountMenu()} >
) } hideAppHeader () { const { location } = this.props const isInitializing = Boolean(matchPath(location.pathname, { path: INITIALIZE_ROUTE, exact: false, })) if (isInitializing) { return true } if (window.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION) { return true } if (window.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_POPUP && this.isConfirming()) { return true } } render () { const { network, provider, history, isUnlocked, } = this.props if (this.hideAppHeader()) { return null } return (
history.push(DEFAULT_ROUTE)} >
this.handleNetworkIndicatorClick(event)} disabled={this.isConfirming()} />
{ this.renderAccountMenu() }
) } }