2023-03-28 21:59:18 +02:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
import {
|
|
|
|
CONNECTED_ROUTE,
|
|
|
|
SETTINGS_ROUTE,
|
|
|
|
DEFAULT_ROUTE,
|
|
|
|
} from '../../../helpers/constants/routes';
|
|
|
|
import { lockMetamask } from '../../../store/actions';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2023-04-04 18:48:04 +02:00
|
|
|
import { ICON_NAMES } from '../../component-library/icon/deprecated';
|
2023-03-28 21:59:18 +02:00
|
|
|
import { Menu, MenuItem } from '../../ui/menu';
|
|
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
|
|
|
|
import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../shared/constants/app';
|
|
|
|
import { SUPPORT_LINK } from '../../../../shared/lib/ui-utils';
|
|
|
|
|
|
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
|
|
|
import {
|
2023-04-03 17:31:04 +02:00
|
|
|
MetaMetricsEventName,
|
|
|
|
MetaMetricsEventCategory,
|
|
|
|
MetaMetricsContextProp,
|
2023-03-28 21:59:18 +02:00
|
|
|
} from '../../../../shared/constants/metametrics';
|
|
|
|
|
|
|
|
export const GlobalMenu = ({ closeMenu, anchorElement }) => {
|
|
|
|
const t = useI18nContext();
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const trackEvent = useContext(MetaMetricsContext);
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Menu anchorElement={anchorElement} onHide={closeMenu}>
|
|
|
|
<MenuItem
|
|
|
|
iconName={ICON_NAMES.CONNECT}
|
|
|
|
onClick={() => {
|
|
|
|
history.push(CONNECTED_ROUTE);
|
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
event: MetaMetricsEventName.NavConnectedSitesOpened,
|
|
|
|
category: MetaMetricsEventCategory.Navigation,
|
2023-03-28 21:59:18 +02:00
|
|
|
properties: {
|
|
|
|
location: 'Account Options',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
closeMenu();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('connectedSites')}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem
|
|
|
|
iconName={ICON_NAMES.DIAGRAM}
|
|
|
|
onClick={() => {
|
|
|
|
const portfolioUrl = process.env.PORTFOLIO_URL;
|
|
|
|
global.platform.openTab({
|
|
|
|
url: `${portfolioUrl}?metamaskEntry=ext`,
|
|
|
|
});
|
|
|
|
trackEvent(
|
|
|
|
{
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Home,
|
|
|
|
event: MetaMetricsEventName.PortfolioLinkClicked,
|
2023-03-28 21:59:18 +02:00
|
|
|
properties: {
|
|
|
|
url: portfolioUrl,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-04-03 17:31:04 +02:00
|
|
|
contextPropsIntoEventProperties: [
|
|
|
|
MetaMetricsContextProp.PageTitle,
|
|
|
|
],
|
2023-03-28 21:59:18 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
closeMenu();
|
|
|
|
}}
|
|
|
|
data-testid="global-menu-portfolio"
|
|
|
|
>
|
|
|
|
{t('portfolioView')}
|
|
|
|
</MenuItem>
|
|
|
|
{getEnvironmentType() === ENVIRONMENT_TYPE_FULLSCREEN ? null : (
|
|
|
|
<MenuItem
|
|
|
|
iconName={ICON_NAMES.EXPAND}
|
|
|
|
onClick={() => {
|
|
|
|
global.platform.openExtensionInBrowser();
|
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
event: MetaMetricsEventName.AppWindowExpanded,
|
|
|
|
category: MetaMetricsEventCategory.Navigation,
|
2023-03-28 21:59:18 +02:00
|
|
|
properties: {
|
|
|
|
location: 'Account Options',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
closeMenu();
|
|
|
|
}}
|
|
|
|
data-testid="global-menu-expand"
|
|
|
|
>
|
|
|
|
{t('expandView')}
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
|
|
|
<MenuItem
|
|
|
|
iconName={ICON_NAMES.MESSAGE_QUESTION}
|
|
|
|
onClick={() => {
|
|
|
|
global.platform.openTab({ url: SUPPORT_LINK });
|
|
|
|
trackEvent(
|
|
|
|
{
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Home,
|
|
|
|
event: MetaMetricsEventName.SupportLinkClicked,
|
2023-03-28 21:59:18 +02:00
|
|
|
properties: {
|
|
|
|
url: SUPPORT_LINK,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-04-03 17:31:04 +02:00
|
|
|
contextPropsIntoEventProperties: [
|
|
|
|
MetaMetricsContextProp.PageTitle,
|
|
|
|
],
|
2023-03-28 21:59:18 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
closeMenu();
|
|
|
|
}}
|
|
|
|
data-testid="global-menu-support"
|
|
|
|
>
|
|
|
|
{t('support')}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem
|
|
|
|
iconName={ICON_NAMES.SETTING}
|
|
|
|
onClick={() => {
|
|
|
|
history.push(SETTINGS_ROUTE);
|
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
|
|
event: MetaMetricsEventName.NavSettingsOpened,
|
2023-03-28 21:59:18 +02:00
|
|
|
properties: {
|
|
|
|
location: 'Main Menu',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
closeMenu();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('settings')}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem
|
|
|
|
iconName={ICON_NAMES.LOCK}
|
|
|
|
onClick={() => {
|
|
|
|
dispatch(lockMetamask());
|
|
|
|
history.push(DEFAULT_ROUTE);
|
|
|
|
closeMenu();
|
|
|
|
}}
|
|
|
|
data-testid="global-menu-lock"
|
|
|
|
>
|
|
|
|
{t('lockMetaMask')}
|
|
|
|
</MenuItem>
|
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
GlobalMenu.propTypes = {
|
|
|
|
/**
|
|
|
|
* The element that the menu should display next to
|
|
|
|
*/
|
|
|
|
anchorElement: PropTypes.instanceOf(window.Element),
|
|
|
|
/**
|
|
|
|
* Function that closes this menu
|
|
|
|
*/
|
|
|
|
closeMenu: PropTypes.func.isRequired,
|
|
|
|
};
|