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

106 lines
2.9 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 Identicon from '../identicon'
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,
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 () {
const { isUnlocked, toggleAccountMenu, selectedAddress, disabled } = this.props
2018-05-11 01:51:26 +02:00
return isUnlocked && (
<div
className={classnames('account-menu__icon', {
'account-menu__icon--disabled': disabled,
})}
onClick={() => disabled || toggleAccountMenu()}
2018-05-11 01:51:26 +02:00
>
<Identicon
address={selectedAddress}
diameter={32}
/>
</div>
)
}
render () {
const {
history,
2018-05-11 01:51:26 +02:00
network,
provider,
isUnlocked,
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">
{
!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>
)
}
}