2022-03-14 19:12:38 +01:00
|
|
|
import React, { useState, useContext } 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';
|
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();
|
2022-07-31 20:26:40 +02:00
|
|
|
const [accountOptionsButtonElement, setAccountOptionsButtonElement] =
|
|
|
|
useState(null);
|
2021-02-04 19:15:23 +01:00
|
|
|
const [accountOptionsMenuOpen, setAccountOptionsMenuOpen] = useState(false);
|
|
|
|
const origin = useSelector(getOriginOfCurrentTab);
|
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 />
|
|
|
|
|
2020-05-22 19:42:09 +02:00
|
|
|
<button
|
|
|
|
className="fas fa-ellipsis-v menu-bar__account-options"
|
2020-05-27 17:31:53 +02:00
|
|
|
data-testid="account-options-menu-button"
|
|
|
|
ref={setAccountOptionsButtonElement}
|
2020-05-22 19:42:09 +02:00
|
|
|
title={t('accountOptions')}
|
|
|
|
onClick={() => {
|
2022-03-14 19:12:38 +01:00
|
|
|
trackEvent({
|
2022-08-16 18:39:23 +02:00
|
|
|
event: EVENT_NAMES.NAV_ACCOUNT_MENU_OPENED,
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.NAVIGATION,
|
2022-03-14 19:12:38 +01:00
|
|
|
properties: {
|
2022-08-16 18:39:23 +02:00
|
|
|
location: 'Home',
|
2022-03-14 19:12:38 +01:00
|
|
|
},
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
setAccountOptionsMenuOpen(true);
|
2020-05-22 19:42:09 +02:00
|
|
|
}}
|
|
|
|
/>
|
2020-05-22 19:11:42 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
{accountOptionsMenuOpen && (
|
|
|
|
<AccountOptionsMenu
|
|
|
|
anchorElement={accountOptionsButtonElement}
|
|
|
|
onClose={() => setAccountOptionsMenuOpen(false)}
|
|
|
|
/>
|
|
|
|
)}
|
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
|
|
|
}
|