2023-02-15 15:39:46 +01:00
|
|
|
import React, { useState, useContext, useRef } from 'react';
|
2022-03-18 20:07:05 +01:00
|
|
|
import browser from 'webextension-polyfill';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import SelectedAccount from '../selected-account';
|
|
|
|
import ConnectedStatusIndicator from '../connected-status-indicator';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
|
|
|
|
import { ENVIRONMENT_TYPE_POPUP } from '../../../../shared/constants/app';
|
2022-08-16 18:39:23 +02:00
|
|
|
import { EVENT, EVENT_NAMES } from '../../../../shared/constants/metametrics';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { CONNECTED_ACCOUNTS_ROUTE } from '../../../helpers/constants/routes';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
|
|
import { getOriginOfCurrentTab } from '../../../selectors';
|
2022-04-01 21:11:12 +02:00
|
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
2023-02-15 15:39:46 +01:00
|
|
|
import { ButtonIcon, ICON_NAMES } from '../../component-library';
|
2021-02-04 19:15:23 +01:00
|
|
|
import AccountOptionsMenu from './account-options-menu';
|
2020-05-22 19:11:42 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function MenuBar() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = useI18nContext();
|
2022-03-14 19:12:38 +01:00
|
|
|
const trackEvent = useContext(MetaMetricsContext);
|
2021-02-04 19:15:23 +01:00
|
|
|
const history = useHistory();
|
|
|
|
const [accountOptionsMenuOpen, setAccountOptionsMenuOpen] = useState(false);
|
|
|
|
const origin = useSelector(getOriginOfCurrentTab);
|
2023-02-15 15:39:46 +01:00
|
|
|
const ref = useRef(false);
|
2020-05-29 20:14:25 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const showStatus =
|
|
|
|
getEnvironmentType() === ENVIRONMENT_TYPE_POPUP &&
|
|
|
|
origin &&
|
2022-03-18 20:07:05 +01:00
|
|
|
origin !== browser.runtime.id;
|
2020-05-22 19:11:42 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="menu-bar">
|
2020-11-03 00:41:28 +01:00
|
|
|
{showStatus ? (
|
|
|
|
<ConnectedStatusIndicator
|
|
|
|
onClick={() => history.push(CONNECTED_ACCOUNTS_ROUTE)}
|
|
|
|
/>
|
|
|
|
) : null}
|
2020-05-22 19:11:42 +02:00
|
|
|
<SelectedAccount />
|
2023-02-15 15:39:46 +01:00
|
|
|
<span style={{ display: 'inherit' }} ref={ref}>
|
|
|
|
<ButtonIcon
|
|
|
|
iconName={ICON_NAMES.MORE_VERTICAL}
|
|
|
|
className="menu-bar__account-options"
|
|
|
|
data-testid="account-options-menu-button"
|
|
|
|
ariaLabel={t('accountOptions')}
|
|
|
|
onClick={() => {
|
|
|
|
trackEvent({
|
|
|
|
event: EVENT_NAMES.NAV_ACCOUNT_MENU_OPENED,
|
|
|
|
category: EVENT.CATEGORIES.NAVIGATION,
|
|
|
|
properties: {
|
|
|
|
location: 'Home',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
setAccountOptionsMenuOpen(true);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
{accountOptionsMenuOpen ? (
|
2020-11-03 00:41:28 +01:00
|
|
|
<AccountOptionsMenu
|
2023-02-15 15:39:46 +01:00
|
|
|
anchorElement={ref.current}
|
2020-11-03 00:41:28 +01:00
|
|
|
onClose={() => setAccountOptionsMenuOpen(false)}
|
|
|
|
/>
|
2023-02-15 15:39:46 +01:00
|
|
|
) : null}
|
2020-05-22 19:11:42 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-05-22 19:11:42 +02:00
|
|
|
}
|