You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
3.6 KiB
140 lines
3.6 KiB
4 years ago
|
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 NetworkDisplay from '../network-display';
|
||
7 years ago
|
|
||
6 years ago
|
export default class AppHeader extends PureComponent {
|
||
7 years ago
|
static propTypes = {
|
||
|
history: PropTypes.object,
|
||
|
networkDropdownOpen: PropTypes.bool,
|
||
|
showNetworkDropdown: PropTypes.func,
|
||
|
hideNetworkDropdown: PropTypes.func,
|
||
|
toggleAccountMenu: PropTypes.func,
|
||
|
selectedAddress: PropTypes.string,
|
||
|
isUnlocked: PropTypes.bool,
|
||
6 years ago
|
hideNetworkIndicator: PropTypes.bool,
|
||
|
disabled: PropTypes.bool,
|
||
4 years ago
|
disableNetworkIndicator: PropTypes.bool,
|
||
6 years ago
|
isAccountMenuOpen: PropTypes.bool,
|
||
4 years ago
|
onClick: PropTypes.func,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
6 years ago
|
metricsEvent: PropTypes.func,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
handleNetworkIndicatorClick(event) {
|
||
4 years ago
|
event.preventDefault();
|
||
|
event.stopPropagation();
|
||
7 years ago
|
|
||
4 years ago
|
const {
|
||
|
networkDropdownOpen,
|
||
|
showNetworkDropdown,
|
||
|
hideNetworkDropdown,
|
||
4 years ago
|
disabled,
|
||
|
disableNetworkIndicator,
|
||
4 years ago
|
} = this.props;
|
||
7 years ago
|
|
||
4 years ago
|
if (disabled || disableNetworkIndicator) {
|
||
4 years ago
|
return;
|
||
4 years ago
|
}
|
||
|
|
||
6 years ago
|
if (networkDropdownOpen === false) {
|
||
|
this.context.metricsEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Navigation',
|
||
|
action: 'Home',
|
||
|
name: 'Opened Network Menu',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
showNetworkDropdown();
|
||
6 years ago
|
} else {
|
||
4 years ago
|
hideNetworkDropdown();
|
||
6 years ago
|
}
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
renderAccountMenu() {
|
||
|
const {
|
||
|
isUnlocked,
|
||
|
toggleAccountMenu,
|
||
|
selectedAddress,
|
||
|
disabled,
|
||
|
isAccountMenuOpen,
|
||
4 years ago
|
} = this.props;
|
||
7 years ago
|
|
||
4 years ago
|
return (
|
||
|
isUnlocked && (
|
||
|
<div
|
||
|
className={classnames('account-menu__icon', {
|
||
|
'account-menu__icon--disabled': disabled,
|
||
|
})}
|
||
|
onClick={() => {
|
||
|
if (!disabled) {
|
||
|
!isAccountMenuOpen &&
|
||
|
this.context.metricsEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Navigation',
|
||
|
action: 'Home',
|
||
|
name: 'Opened Main Menu',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
toggleAccountMenu();
|
||
4 years ago
|
}
|
||
|
}}
|
||
|
>
|
||
|
<Identicon address={selectedAddress} diameter={32} addBorder />
|
||
|
</div>
|
||
|
)
|
||
4 years ago
|
);
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
render() {
|
||
7 years ago
|
const {
|
||
6 years ago
|
history,
|
||
7 years ago
|
isUnlocked,
|
||
6 years ago
|
hideNetworkIndicator,
|
||
4 years ago
|
disableNetworkIndicator,
|
||
6 years ago
|
disabled,
|
||
4 years ago
|
onClick,
|
||
4 years ago
|
} = this.props;
|
||
7 years ago
|
|
||
|
return (
|
||
|
<div
|
||
4 years ago
|
className={classnames('app-header', {
|
||
|
'app-header--back-drop': isUnlocked,
|
||
|
})}
|
||
5 years ago
|
>
|
||
7 years ago
|
<div className="app-header__contents">
|
||
5 years ago
|
<MetaFoxLogo
|
||
5 years ago
|
unsetIconHeight
|
||
4 years ago
|
onClick={async () => {
|
||
|
if (onClick) {
|
||
4 years ago
|
await onClick();
|
||
4 years ago
|
}
|
||
4 years ago
|
history.push(DEFAULT_ROUTE);
|
||
4 years ago
|
}}
|
||
5 years ago
|
/>
|
||
7 years ago
|
<div className="app-header__account-menu-container">
|
||
4 years ago
|
{!hideNetworkIndicator && (
|
||
|
<div className="app-header__network-component-wrapper">
|
||
4 years ago
|
<NetworkDisplay
|
||
|
colored={false}
|
||
|
outline
|
||
|
iconClassName="app-header__network-down-arrow"
|
||
4 years ago
|
onClick={(event) => this.handleNetworkIndicatorClick(event)}
|
||
|
disabled={disabled || disableNetworkIndicator}
|
||
|
/>
|
||
|
</div>
|
||
|
)}
|
||
|
{this.renderAccountMenu()}
|
||
7 years ago
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
7 years ago
|
}
|
||
|
}
|