You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
4.4 KiB
150 lines
4.4 KiB
4 years ago
|
import React from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import { useHistory } from 'react-router-dom';
|
||
|
import { useDispatch, useSelector } from 'react-redux';
|
||
5 years ago
|
|
||
4 years ago
|
import { showModal } from '../../../store/actions';
|
||
|
import { CONNECTED_ROUTE } from '../../../helpers/constants/routes';
|
||
|
import { Menu, MenuItem } from '../../ui/menu';
|
||
4 years ago
|
import getAccountLink from '../../../helpers/utils/account-link';
|
||
4 years ago
|
import {
|
||
4 years ago
|
getCurrentChainId,
|
||
4 years ago
|
getCurrentKeyring,
|
||
|
getRpcPrefsForCurrentProvider,
|
||
|
getSelectedIdentity,
|
||
4 years ago
|
} from '../../../selectors';
|
||
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
||
|
import { useMetricEvent } from '../../../hooks/useMetricEvent';
|
||
4 years ago
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
|
||
|
import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../shared/constants/app';
|
||
5 years ago
|
|
||
4 years ago
|
export default function AccountOptionsMenu({ anchorElement, onClose }) {
|
||
4 years ago
|
const t = useI18nContext();
|
||
|
const dispatch = useDispatch();
|
||
|
const history = useHistory();
|
||
5 years ago
|
const openFullscreenEvent = useMetricEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Navigation',
|
||
|
action: 'Account Options',
|
||
|
name: 'Clicked Expand View',
|
||
|
},
|
||
4 years ago
|
});
|
||
5 years ago
|
const viewAccountDetailsEvent = useMetricEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Navigation',
|
||
|
action: 'Account Options',
|
||
|
name: 'Viewed Account Details',
|
||
|
},
|
||
4 years ago
|
});
|
||
5 years ago
|
const viewOnEtherscanEvent = useMetricEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Navigation',
|
||
|
action: 'Account Options',
|
||
|
name: 'Clicked View on Etherscan',
|
||
|
},
|
||
4 years ago
|
});
|
||
5 years ago
|
const openConnectedSitesEvent = useMetricEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Navigation',
|
||
|
action: 'Account Options',
|
||
|
name: 'Opened Connected Sites',
|
||
|
},
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
4 years ago
|
const keyring = useSelector(getCurrentKeyring);
|
||
4 years ago
|
const chainId = useSelector(getCurrentChainId);
|
||
4 years ago
|
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider);
|
||
|
const selectedIdentity = useSelector(getSelectedIdentity);
|
||
5 years ago
|
|
||
4 years ago
|
const { address } = selectedIdentity;
|
||
|
const isRemovable = keyring.type !== 'HD Key Tree';
|
||
5 years ago
|
|
||
|
return (
|
||
|
<Menu
|
||
|
anchorElement={anchorElement}
|
||
|
className="account-options-menu"
|
||
|
onHide={onClose}
|
||
|
>
|
||
4 years ago
|
{getEnvironmentType() === ENVIRONMENT_TYPE_FULLSCREEN ? null : (
|
||
|
<MenuItem
|
||
|
onClick={() => {
|
||
4 years ago
|
openFullscreenEvent();
|
||
|
global.platform.openExtensionInBrowser();
|
||
|
onClose();
|
||
4 years ago
|
}}
|
||
|
iconClassName="fas fa-expand-alt"
|
||
|
>
|
||
|
{t('expandView')}
|
||
|
</MenuItem>
|
||
|
)}
|
||
5 years ago
|
<MenuItem
|
||
5 years ago
|
data-testid="account-options-menu__account-details"
|
||
5 years ago
|
onClick={() => {
|
||
4 years ago
|
dispatch(showModal({ name: 'ACCOUNT_DETAILS' }));
|
||
|
viewAccountDetailsEvent();
|
||
|
onClose();
|
||
5 years ago
|
}}
|
||
|
iconClassName="fas fa-qrcode"
|
||
|
>
|
||
4 years ago
|
{t('accountDetails')}
|
||
5 years ago
|
</MenuItem>
|
||
|
<MenuItem
|
||
|
onClick={() => {
|
||
4 years ago
|
viewOnEtherscanEvent();
|
||
4 years ago
|
global.platform.openTab({
|
||
4 years ago
|
url: getAccountLink(address, chainId, rpcPrefs),
|
||
4 years ago
|
});
|
||
|
onClose();
|
||
5 years ago
|
}}
|
||
|
subtitle={
|
||
4 years ago
|
rpcPrefs.blockExplorerUrl ? (
|
||
|
<span className="account-options-menu__explorer-origin">
|
||
|
{rpcPrefs.blockExplorerUrl.match(/^https?:\/\/(.+)/u)[1]}
|
||
|
</span>
|
||
|
) : null
|
||
5 years ago
|
}
|
||
|
iconClassName="fas fa-external-link-alt"
|
||
|
>
|
||
4 years ago
|
{rpcPrefs.blockExplorerUrl ? t('viewinExplorer') : t('viewOnEtherscan')}
|
||
5 years ago
|
</MenuItem>
|
||
|
<MenuItem
|
||
5 years ago
|
data-testid="account-options-menu__connected-sites"
|
||
5 years ago
|
onClick={() => {
|
||
4 years ago
|
openConnectedSitesEvent();
|
||
|
history.push(CONNECTED_ROUTE);
|
||
|
onClose();
|
||
5 years ago
|
}}
|
||
|
iconClassName="account-options-menu__connected-sites"
|
||
|
>
|
||
4 years ago
|
{t('connectedSites')}
|
||
5 years ago
|
</MenuItem>
|
||
4 years ago
|
{isRemovable ? (
|
||
|
<MenuItem
|
||
|
data-testid="account-options-menu__remove-account"
|
||
|
onClick={() => {
|
||
|
dispatch(
|
||
|
showModal({
|
||
|
name: 'CONFIRM_REMOVE_ACCOUNT',
|
||
|
identity: selectedIdentity,
|
||
|
}),
|
||
4 years ago
|
);
|
||
|
onClose();
|
||
4 years ago
|
}}
|
||
|
iconClassName="fas fa-trash-alt"
|
||
|
>
|
||
|
{t('removeAccount')}
|
||
|
</MenuItem>
|
||
|
) : null}
|
||
5 years ago
|
</Menu>
|
||
4 years ago
|
);
|
||
5 years ago
|
}
|
||
|
|
||
|
AccountOptionsMenu.propTypes = {
|
||
|
anchorElement: PropTypes.instanceOf(window.Element),
|
||
|
onClose: PropTypes.func.isRequired,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
|
AccountOptionsMenu.defaultProps = {
|
||
|
anchorElement: undefined,
|
||
4 years ago
|
};
|