1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00
metamask-extension/ui/components/app/menu-bar/account-options-menu.js
Akintayo A. Olusegun 08dff86be0
Add target object word to "View on Etherscan" links (#12100)
* Add target object word to "View on Etherscan" links
Fix for: #9476

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Fix Swap tests checking for View $1 at or View $1 on

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Linter Fixes

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Fix  ui/hooks/useTransactionDisplayData.test.js expected result should
be May 13, 2020

Update Jest snapshot for view on etherscan test

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Add description of the variables in messages.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* 1. localize all of the blockExplorerViewAction values
2. Apply this nit. https://github.com/MetaMask/metamask-extension/pull/12100#discussion_r708343532

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Fix locale value not used on GUI error lint error.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Reverted this commit, on circle ci, the date is May 12.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Add description to link block explore actions to where it's used.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Fix missing messages.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
2021-09-24 21:14:07 +04:00

164 lines
4.7 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { useHistory } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import { getAccountLink } from '@metamask/etherscan-link';
import { showModal } from '../../../store/actions';
import { CONNECTED_ROUTE } from '../../../helpers/constants/routes';
import { getURLHostName } from '../../../helpers/utils/util';
import { Menu, MenuItem } from '../../ui/menu';
import {
getCurrentChainId,
getCurrentKeyring,
getRpcPrefsForCurrentProvider,
getSelectedIdentity,
} from '../../../selectors';
import { useI18nContext } from '../../../hooks/useI18nContext';
import {
useMetricEvent,
useNewMetricEvent,
} from '../../../hooks/useMetricEvent';
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../shared/constants/app';
export default function AccountOptionsMenu({ anchorElement, onClose }) {
const t = useI18nContext();
const dispatch = useDispatch();
const history = useHistory();
const keyring = useSelector(getCurrentKeyring);
const chainId = useSelector(getCurrentChainId);
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider);
const selectedIdentity = useSelector(getSelectedIdentity);
const { address } = selectedIdentity;
const addressLink = getAccountLink(address, chainId, rpcPrefs);
const { blockExplorerUrl } = rpcPrefs;
const blockExplorerUrlSubTitle = getURLHostName(blockExplorerUrl);
const openFullscreenEvent = useMetricEvent({
eventOpts: {
category: 'Navigation',
action: 'Account Options',
name: 'Clicked Expand View',
},
});
const viewAccountDetailsEvent = useMetricEvent({
eventOpts: {
category: 'Navigation',
action: 'Account Options',
name: 'Viewed Account Details',
},
});
const openConnectedSitesEvent = useMetricEvent({
eventOpts: {
category: 'Navigation',
action: 'Account Options',
name: 'Opened Connected Sites',
},
});
const blockExplorerLinkClickedEvent = useNewMetricEvent({
category: 'Navigation',
event: 'Clicked Block Explorer Link',
properties: {
link_type: 'Account Tracker',
action: 'Account Options',
block_explorer_domain: getURLHostName(addressLink),
},
});
const isRemovable = keyring.type !== 'HD Key Tree';
return (
<Menu
anchorElement={anchorElement}
className="account-options-menu"
onHide={onClose}
>
{getEnvironmentType() === ENVIRONMENT_TYPE_FULLSCREEN ? null : (
<MenuItem
onClick={() => {
openFullscreenEvent();
global.platform.openExtensionInBrowser();
onClose();
}}
iconClassName="fas fa-expand-alt"
>
{t('expandView')}
</MenuItem>
)}
<MenuItem
data-testid="account-options-menu__account-details"
onClick={() => {
dispatch(showModal({ name: 'ACCOUNT_DETAILS' }));
viewAccountDetailsEvent();
onClose();
}}
iconClassName="fas fa-qrcode"
>
{t('accountDetails')}
</MenuItem>
<MenuItem
onClick={() => {
blockExplorerLinkClickedEvent();
global.platform.openTab({
url: addressLink,
});
onClose();
}}
subtitle={
blockExplorerUrlSubTitle ? (
<span className="account-options-menu__explorer-origin">
{blockExplorerUrlSubTitle}
</span>
) : null
}
iconClassName="fas fa-external-link-alt"
>
{rpcPrefs.blockExplorerUrl
? t('viewinExplorer', [t('blockExplorerAccountAction')])
: t('viewOnEtherscan', [t('blockExplorerAccountAction')])}
</MenuItem>
<MenuItem
data-testid="account-options-menu__connected-sites"
onClick={() => {
openConnectedSitesEvent();
history.push(CONNECTED_ROUTE);
onClose();
}}
iconClassName="account-options-menu__connected-sites"
>
{t('connectedSites')}
</MenuItem>
{isRemovable ? (
<MenuItem
data-testid="account-options-menu__remove-account"
onClick={() => {
dispatch(
showModal({
name: 'CONFIRM_REMOVE_ACCOUNT',
identity: selectedIdentity,
}),
);
onClose();
}}
iconClassName="fas fa-trash-alt"
>
{t('removeAccount')}
</MenuItem>
) : null}
</Menu>
);
}
AccountOptionsMenu.propTypes = {
anchorElement: PropTypes.instanceOf(window.Element),
onClose: PropTypes.func.isRequired,
};
AccountOptionsMenu.defaultProps = {
anchorElement: undefined,
};