1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 00:28:06 +01:00
metamask-extension/ui/app/components/app-header/app-header.component.js

137 lines
3.6 KiB
JavaScript
Raw Normal View History

2018-08-19 03:41:19 +02:00
import React, { PureComponent } from 'react'
2018-05-11 01:51:26 +02:00
import PropTypes from 'prop-types'
import classnames from 'classnames'
import { matchPath } from 'react-router-dom'
2018-05-11 01:51:26 +02:00
const {
ENVIRONMENT_TYPE_NOTIFICATION,
ENVIRONMENT_TYPE_POPUP,
} = require('../../../../app/scripts/lib/enums')
const { DEFAULT_ROUTE, INITIALIZE_ROUTE, CONFIRM_TRANSACTION_ROUTE } = require('../../routes')
2018-05-11 01:51:26 +02:00
const Identicon = require('../identicon')
const NetworkIndicator = require('../network')
2018-08-19 03:41:19 +02:00
export default class AppHeader extends PureComponent {
2018-05-11 01:51:26 +02:00
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,
}))
}
2018-05-11 01:51:26 +02:00
renderAccountMenu () {
const { isUnlocked, toggleAccountMenu, selectedAddress } = this.props
return isUnlocked && (
<div
className={classnames('account-menu__icon', {
'account-menu__icon--disabled': this.isConfirming(),
})}
onClick={() => this.isConfirming() || toggleAccountMenu()}
2018-05-11 01:51:26 +02:00
>
<Identicon
address={selectedAddress}
diameter={32}
/>
</div>
)
}
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
}
}
2018-05-11 01:51:26 +02:00
render () {
const {
network,
provider,
history,
isUnlocked,
} = this.props
if (this.hideAppHeader()) {
2018-05-11 01:51:26 +02:00
return null
}
return (
<div
className={classnames('app-header', { 'app-header--back-drop': isUnlocked })}>
<div className="app-header__contents">
<div
className="app-header__logo-container"
onClick={() => history.push(DEFAULT_ROUTE)}
>
<img
2018-08-19 03:41:19 +02:00
className="app-header__metafox-logo app-header__metafox-logo--horizontal"
src="/images/logo/metamask-logo-horizontal-beta.svg"
height={30}
/>
<img
className="app-header__metafox-logo app-header__metafox-logo--icon"
src="/images/logo/metamask-fox.svg"
2018-05-11 01:51:26 +02:00
height={42}
width={42}
/>
</div>
<div className="app-header__account-menu-container">
2018-08-19 03:41:19 +02:00
<div className="app-header__network-component-wrapper">
2018-05-11 01:51:26 +02:00
<NetworkIndicator
network={network}
provider={provider}
onClick={event => this.handleNetworkIndicatorClick(event)}
2018-06-26 06:29:16 +02:00
disabled={this.isConfirming()}
2018-05-11 01:51:26 +02:00
/>
</div>
{ this.renderAccountMenu() }
</div>
</div>
</div>
)
}
}