2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2020-05-27 17:31:53 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import { showModal } from '../../../store/actions';
|
|
|
|
import { CONNECTED_ROUTE } from '../../../helpers/constants/routes';
|
|
|
|
import { Menu, MenuItem } from '../../ui/menu';
|
2021-04-28 21:53:59 +02:00
|
|
|
import getAccountLink from '../../../helpers/utils/account-link';
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
2021-03-10 18:21:52 +01:00
|
|
|
getCurrentChainId,
|
2020-11-03 00:41:28 +01:00
|
|
|
getCurrentKeyring,
|
|
|
|
getRpcPrefsForCurrentProvider,
|
|
|
|
getSelectedIdentity,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../selectors';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
|
|
import { useMetricEvent } from '../../../hooks/useMetricEvent';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
|
|
|
|
import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../shared/constants/app';
|
2020-05-27 17:31:53 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function AccountOptionsMenu({ anchorElement, onClose }) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = useI18nContext();
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const history = useHistory();
|
2020-05-27 17:31:53 +02:00
|
|
|
const openFullscreenEvent = useMetricEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Navigation',
|
|
|
|
action: 'Account Options',
|
|
|
|
name: 'Clicked Expand View',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-27 17:31:53 +02:00
|
|
|
const viewAccountDetailsEvent = useMetricEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Navigation',
|
|
|
|
action: 'Account Options',
|
|
|
|
name: 'Viewed Account Details',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-27 17:31:53 +02:00
|
|
|
const viewOnEtherscanEvent = useMetricEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Navigation',
|
|
|
|
action: 'Account Options',
|
|
|
|
name: 'Clicked View on Etherscan',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-27 17:31:53 +02:00
|
|
|
const openConnectedSitesEvent = useMetricEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Navigation',
|
|
|
|
action: 'Account Options',
|
|
|
|
name: 'Opened Connected Sites',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-05-27 17:31:53 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const keyring = useSelector(getCurrentKeyring);
|
2021-03-10 18:21:52 +01:00
|
|
|
const chainId = useSelector(getCurrentChainId);
|
2021-02-04 19:15:23 +01:00
|
|
|
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider);
|
|
|
|
const selectedIdentity = useSelector(getSelectedIdentity);
|
2020-05-27 17:31:53 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { address } = selectedIdentity;
|
|
|
|
const isRemovable = keyring.type !== 'HD Key Tree';
|
2020-05-27 17:31:53 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Menu
|
|
|
|
anchorElement={anchorElement}
|
|
|
|
className="account-options-menu"
|
|
|
|
onHide={onClose}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{getEnvironmentType() === ENVIRONMENT_TYPE_FULLSCREEN ? null : (
|
|
|
|
<MenuItem
|
|
|
|
onClick={() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
openFullscreenEvent();
|
|
|
|
global.platform.openExtensionInBrowser();
|
|
|
|
onClose();
|
2020-11-03 00:41:28 +01:00
|
|
|
}}
|
|
|
|
iconClassName="fas fa-expand-alt"
|
|
|
|
>
|
|
|
|
{t('expandView')}
|
|
|
|
</MenuItem>
|
|
|
|
)}
|
2020-05-27 17:31:53 +02:00
|
|
|
<MenuItem
|
2020-05-27 22:28:33 +02:00
|
|
|
data-testid="account-options-menu__account-details"
|
2020-05-27 17:31:53 +02:00
|
|
|
onClick={() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showModal({ name: 'ACCOUNT_DETAILS' }));
|
|
|
|
viewAccountDetailsEvent();
|
|
|
|
onClose();
|
2020-05-27 17:31:53 +02:00
|
|
|
}}
|
|
|
|
iconClassName="fas fa-qrcode"
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('accountDetails')}
|
2020-05-27 17:31:53 +02:00
|
|
|
</MenuItem>
|
|
|
|
<MenuItem
|
|
|
|
onClick={() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
viewOnEtherscanEvent();
|
2020-11-03 00:41:28 +01:00
|
|
|
global.platform.openTab({
|
2021-03-10 18:21:52 +01:00
|
|
|
url: getAccountLink(address, chainId, rpcPrefs),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
onClose();
|
2020-05-27 17:31:53 +02:00
|
|
|
}}
|
|
|
|
subtitle={
|
2020-11-03 00:41:28 +01:00
|
|
|
rpcPrefs.blockExplorerUrl ? (
|
|
|
|
<span className="account-options-menu__explorer-origin">
|
|
|
|
{rpcPrefs.blockExplorerUrl.match(/^https?:\/\/(.+)/u)[1]}
|
|
|
|
</span>
|
|
|
|
) : null
|
2020-05-27 17:31:53 +02:00
|
|
|
}
|
|
|
|
iconClassName="fas fa-external-link-alt"
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{rpcPrefs.blockExplorerUrl ? t('viewinExplorer') : t('viewOnEtherscan')}
|
2020-05-27 17:31:53 +02:00
|
|
|
</MenuItem>
|
|
|
|
<MenuItem
|
2020-05-27 22:28:33 +02:00
|
|
|
data-testid="account-options-menu__connected-sites"
|
2020-05-27 17:31:53 +02:00
|
|
|
onClick={() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
openConnectedSitesEvent();
|
|
|
|
history.push(CONNECTED_ROUTE);
|
|
|
|
onClose();
|
2020-05-27 17:31:53 +02:00
|
|
|
}}
|
|
|
|
iconClassName="account-options-menu__connected-sites"
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('connectedSites')}
|
2020-05-27 17:31:53 +02:00
|
|
|
</MenuItem>
|
2020-11-03 00:41:28 +01:00
|
|
|
{isRemovable ? (
|
|
|
|
<MenuItem
|
|
|
|
data-testid="account-options-menu__remove-account"
|
|
|
|
onClick={() => {
|
|
|
|
dispatch(
|
|
|
|
showModal({
|
|
|
|
name: 'CONFIRM_REMOVE_ACCOUNT',
|
|
|
|
identity: selectedIdentity,
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
onClose();
|
2020-11-03 00:41:28 +01:00
|
|
|
}}
|
|
|
|
iconClassName="fas fa-trash-alt"
|
|
|
|
>
|
|
|
|
{t('removeAccount')}
|
|
|
|
</MenuItem>
|
|
|
|
) : null}
|
2020-05-27 17:31:53 +02:00
|
|
|
</Menu>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-05-27 17:31:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AccountOptionsMenu.propTypes = {
|
|
|
|
anchorElement: PropTypes.instanceOf(window.Element),
|
|
|
|
onClose: PropTypes.func.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-27 17:31:53 +02:00
|
|
|
|
|
|
|
AccountOptionsMenu.defaultProps = {
|
|
|
|
anchorElement: undefined,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|