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'
|
2018-10-25 11:21:41 +02:00
|
|
|
import Identicon from '../identicon'
|
2019-01-23 16:25:34 +01:00
|
|
|
import { DEFAULT_ROUTE } from '../../routes'
|
2018-05-11 01:51:26 +02:00
|
|
|
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,
|
|
|
|
network: PropTypes.string,
|
|
|
|
provider: PropTypes.object,
|
|
|
|
networkDropdownOpen: PropTypes.bool,
|
|
|
|
showNetworkDropdown: PropTypes.func,
|
|
|
|
hideNetworkDropdown: PropTypes.func,
|
|
|
|
toggleAccountMenu: PropTypes.func,
|
|
|
|
selectedAddress: PropTypes.string,
|
|
|
|
isUnlocked: PropTypes.bool,
|
2019-01-23 16:25:34 +01:00
|
|
|
hideNetworkIndicator: PropTypes.bool,
|
|
|
|
disabled: PropTypes.bool,
|
2018-05-11 01:51:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
handleNetworkIndicatorClick (event) {
|
|
|
|
event.preventDefault()
|
|
|
|
event.stopPropagation()
|
|
|
|
|
|
|
|
const { networkDropdownOpen, showNetworkDropdown, hideNetworkDropdown } = this.props
|
|
|
|
|
|
|
|
return networkDropdownOpen === false
|
|
|
|
? showNetworkDropdown()
|
|
|
|
: hideNetworkDropdown()
|
|
|
|
}
|
|
|
|
|
|
|
|
renderAccountMenu () {
|
2019-01-23 16:25:34 +01:00
|
|
|
const { isUnlocked, toggleAccountMenu, selectedAddress, disabled } = this.props
|
2018-05-11 01:51:26 +02:00
|
|
|
|
|
|
|
return isUnlocked && (
|
|
|
|
<div
|
2018-05-14 23:34:10 +02:00
|
|
|
className={classnames('account-menu__icon', {
|
2019-01-23 16:25:34 +01:00
|
|
|
'account-menu__icon--disabled': disabled,
|
2018-05-14 23:34:10 +02:00
|
|
|
})}
|
2019-01-23 16:25:34 +01:00
|
|
|
onClick={() => disabled || toggleAccountMenu()}
|
2018-05-11 01:51:26 +02:00
|
|
|
>
|
|
|
|
<Identicon
|
|
|
|
address={selectedAddress}
|
|
|
|
diameter={32}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {
|
2019-01-23 16:25:34 +01:00
|
|
|
history,
|
2018-05-11 01:51:26 +02:00
|
|
|
network,
|
|
|
|
provider,
|
|
|
|
isUnlocked,
|
2019-01-23 16:25:34 +01:00
|
|
|
hideNetworkIndicator,
|
|
|
|
disabled,
|
2018-05-11 01:51:26 +02:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
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"
|
2018-09-24 20:17:45 +02:00
|
|
|
src="/images/logo/metamask-logo-horizontal.svg"
|
2018-08-19 03:41:19 +02:00
|
|
|
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">
|
2019-01-23 16:25:34 +01:00
|
|
|
{
|
|
|
|
!hideNetworkIndicator && (
|
|
|
|
<div className="app-header__network-component-wrapper">
|
|
|
|
<NetworkIndicator
|
|
|
|
network={network}
|
|
|
|
provider={provider}
|
|
|
|
onClick={event => this.handleNetworkIndicatorClick(event)}
|
|
|
|
disabled={disabled}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2018-05-11 01:51:26 +02:00
|
|
|
{ this.renderAccountMenu() }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|