2021-02-04 19:15:23 +01:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import extension from 'extensionizer';
|
|
|
|
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';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { CONNECTED_ACCOUNTS_ROUTE } from '../../../helpers/constants/routes';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
|
|
import { useMetricEvent } from '../../../hooks/useMetricEvent';
|
|
|
|
import { getOriginOfCurrentTab } from '../../../selectors';
|
|
|
|
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();
|
2020-05-22 19:11:42 +02:00
|
|
|
const openAccountOptionsEvent = useMetricEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Navigation',
|
|
|
|
action: 'Home',
|
|
|
|
name: 'Opened Account Options',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
const history = useHistory();
|
2020-11-03 00:41:28 +01:00
|
|
|
const [
|
|
|
|
accountOptionsButtonElement,
|
|
|
|
setAccountOptionsButtonElement,
|
2021-02-04 19:15:23 +01:00
|
|
|
] = useState(null);
|
|
|
|
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 &&
|
2021-02-04 19:15:23 +01:00
|
|
|
origin !== extension.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={() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
openAccountOptionsEvent();
|
|
|
|
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
|
|
|
}
|