2021-02-04 19:15:23 +01:00
|
|
|
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';
|
2018-05-11 01:51:26 +02:00
|
|
|
|
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,
|
|
|
|
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,
|
2020-10-06 20:28:38 +02:00
|
|
|
disableNetworkIndicator: PropTypes.bool,
|
2019-03-05 16:45:01 +01:00
|
|
|
isAccountMenuOpen: PropTypes.bool,
|
2020-10-06 20:28:38 +02:00
|
|
|
onClick: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-11 01:51:26 +02:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2019-03-05 16:45:01 +01:00
|
|
|
metricsEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-11 01:51:26 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
handleNetworkIndicatorClick(event) {
|
2021-02-04 19:15:23 +01:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2018-05-11 01:51:26 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
networkDropdownOpen,
|
|
|
|
showNetworkDropdown,
|
|
|
|
hideNetworkDropdown,
|
2021-01-27 17:51:59 +01:00
|
|
|
disabled,
|
|
|
|
disableNetworkIndicator,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-05-11 01:51:26 +02:00
|
|
|
|
2021-01-27 17:51:59 +01:00
|
|
|
if (disabled || disableNetworkIndicator) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return;
|
2021-01-27 17:51:59 +01:00
|
|
|
}
|
|
|
|
|
2019-03-05 16:45:01 +01:00
|
|
|
if (networkDropdownOpen === false) {
|
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Navigation',
|
|
|
|
action: 'Home',
|
|
|
|
name: 'Opened Network Menu',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
showNetworkDropdown();
|
2019-03-05 16:45:01 +01:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
hideNetworkDropdown();
|
2019-03-05 16:45:01 +01:00
|
|
|
}
|
2018-05-11 01:51:26 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderAccountMenu() {
|
|
|
|
const {
|
|
|
|
isUnlocked,
|
|
|
|
toggleAccountMenu,
|
|
|
|
selectedAddress,
|
|
|
|
disabled,
|
|
|
|
isAccountMenuOpen,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-05-11 01:51:26 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
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',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
toggleAccountMenu();
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Identicon address={selectedAddress} diameter={32} addBorder />
|
|
|
|
</div>
|
|
|
|
)
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-05-11 01:51:26 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2018-05-11 01:51:26 +02:00
|
|
|
const {
|
2019-01-23 16:25:34 +01:00
|
|
|
history,
|
2018-05-11 01:51:26 +02:00
|
|
|
isUnlocked,
|
2019-01-23 16:25:34 +01:00
|
|
|
hideNetworkIndicator,
|
2020-10-06 20:28:38 +02:00
|
|
|
disableNetworkIndicator,
|
2019-01-23 16:25:34 +01:00
|
|
|
disabled,
|
2020-10-06 20:28:38 +02:00
|
|
|
onClick,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-05-11 01:51:26 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2020-11-03 00:41:28 +01:00
|
|
|
className={classnames('app-header', {
|
|
|
|
'app-header--back-drop': isUnlocked,
|
|
|
|
})}
|
2019-12-03 17:35:44 +01:00
|
|
|
>
|
2018-05-11 01:51:26 +02:00
|
|
|
<div className="app-header__contents">
|
2019-07-09 19:17:58 +02:00
|
|
|
<MetaFoxLogo
|
2019-11-19 00:23:41 +01:00
|
|
|
unsetIconHeight
|
2020-10-06 20:28:38 +02:00
|
|
|
onClick={async () => {
|
|
|
|
if (onClick) {
|
2021-02-04 19:15:23 +01:00
|
|
|
await onClick();
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
history.push(DEFAULT_ROUTE);
|
2020-10-06 20:28:38 +02:00
|
|
|
}}
|
2019-07-09 19:17:58 +02:00
|
|
|
/>
|
2018-05-11 01:51:26 +02:00
|
|
|
<div className="app-header__account-menu-container">
|
2020-11-03 00:41:28 +01:00
|
|
|
{!hideNetworkIndicator && (
|
|
|
|
<div className="app-header__network-component-wrapper">
|
2021-01-27 17:51:59 +01:00
|
|
|
<NetworkDisplay
|
|
|
|
colored={false}
|
|
|
|
outline
|
|
|
|
iconClassName="app-header__network-down-arrow"
|
2020-11-03 00:41:28 +01:00
|
|
|
onClick={(event) => this.handleNetworkIndicatorClick(event)}
|
|
|
|
disabled={disabled || disableNetworkIndicator}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{this.renderAccountMenu()}
|
2018-05-11 01:51:26 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-05-11 01:51:26 +02:00
|
|
|
}
|
|
|
|
}
|