1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/app/app-header/app-header.component.js
Elliot Winkler 1304ec7af5
Convert shared/constants/metametrics to TS (#18353)
We want to convert NetworkController to TypeScript in order to be able
to compare differences in the controller between in this repo and the
core repo. To do this, however, we need to convert the dependencies of
the controller to TypeScript.

As a part of this effort, this commit converts
`shared/constants/metametrics` to TypeScript. Note that simple objects
have been largely replaced with enums. There are some cases where I even
split up some of these objects into multiple enums.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2023-04-03 09:31:04 -06:00

182 lines
5.0 KiB
JavaScript

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 {
MetaMetricsEventCategory,
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import NetworkDisplay from '../network-display';
///: BEGIN:ONLY_INCLUDE_IN(beta)
import BetaHeader from '../beta-header';
///: END:ONLY_INCLUDE_IN(beta)
export default class AppHeader extends PureComponent {
static propTypes = {
history: 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,
disableNetworkIndicator: PropTypes.bool,
isAccountMenuOpen: PropTypes.bool,
///: BEGIN:ONLY_INCLUDE_IN(flask)
unreadNotificationsCount: PropTypes.number,
desktopEnabled: PropTypes.bool,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(beta)
showBetaHeader: PropTypes.bool,
///: END:ONLY_INCLUDE_IN
onClick: PropTypes.func,
};
static contextTypes = {
t: PropTypes.func,
trackEvent: PropTypes.func,
};
handleNetworkIndicatorClick(event) {
event.preventDefault();
event.stopPropagation();
const {
networkDropdownOpen,
showNetworkDropdown,
hideNetworkDropdown,
disabled,
disableNetworkIndicator,
} = this.props;
if (disabled || disableNetworkIndicator) {
return;
}
if (networkDropdownOpen === false) {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: MetaMetricsEventName.NavNetworkMenuOpened,
properties: {},
});
showNetworkDropdown();
} else {
hideNetworkDropdown();
}
}
renderAccountMenu() {
const {
isUnlocked,
toggleAccountMenu,
selectedAddress,
disabled,
isAccountMenuOpen,
///: BEGIN:ONLY_INCLUDE_IN(flask)
unreadNotificationsCount,
///: END:ONLY_INCLUDE_IN
} = this.props;
return (
isUnlocked && (
<button
data-testid="account-menu-icon"
className={classnames('account-menu__icon', {
'account-menu__icon--disabled': disabled,
})}
onClick={() => {
if (!disabled) {
!isAccountMenuOpen &&
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: MetaMetricsEventName.NavMainMenuOpened,
properties: {},
});
toggleAccountMenu();
}
}}
>
<Identicon address={selectedAddress} diameter={32} addBorder />
{
///: BEGIN:ONLY_INCLUDE_IN(flask)
unreadNotificationsCount > 0 && (
<div className="account-menu__icon__notification-count">
{unreadNotificationsCount}
</div>
)
///: END:ONLY_INCLUDE_IN
}
</button>
)
);
}
render() {
const {
history,
hideNetworkIndicator,
disableNetworkIndicator,
disabled,
onClick,
///: BEGIN:ONLY_INCLUDE_IN(beta)
showBetaHeader,
///: END:ONLY_INCLUDE_IN(beta)
///: BEGIN:ONLY_INCLUDE_IN(flask)
desktopEnabled,
///: END:ONLY_INCLUDE_IN
} = this.props;
return (
<>
{
///: BEGIN:ONLY_INCLUDE_IN(beta)
showBetaHeader ? <BetaHeader /> : null
///: END:ONLY_INCLUDE_IN(beta)
}
<div className="app-header">
<div className="app-header__contents">
<MetaFoxLogo
unsetIconHeight
onClick={async () => {
if (onClick) {
await onClick();
}
history.push(DEFAULT_ROUTE);
}}
/>
{
///: BEGIN:ONLY_INCLUDE_IN(flask)
desktopEnabled && process.env.METAMASK_DEBUG && (
<div data-testid="app-header-desktop-dev-logo">
<MetaFoxLogo
unsetIconHeight
src="./images/logo/desktop.svg"
/>
</div>
)
///: END:ONLY_INCLUDE_IN
}
<div className="app-header__account-menu-container">
{!hideNetworkIndicator && (
<div className="app-header__network-component-wrapper">
<NetworkDisplay
onClick={(event) => this.handleNetworkIndicatorClick(event)}
disabled={disabled || disableNetworkIndicator}
/>
</div>
)}
{this.renderAccountMenu()}
</div>
</div>
</div>
</>
);
}
}