mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 12:29:06 +01:00
b89630fdd2
* Show portfolio icon in ETH overview
* Show new copy button in QR code modal
* Show address copy button in wallet overview
* Update connected status component
* Remove legacy MenuBar
* Remove legacy ImportTokenLink
* Remove AssetListItem
* Remove DetectedTokensLink
* Remove legacy AppHeader
* Remove MULTICHAIN flag from builds.yml
* Remove legacy AccountMenu
* FIX: Token cell snapshot
* Add data-testid for Account Picker
* Remove multichain check in LoadingNetworkScreen
* Remove MULTICHAIN check for AccountDetailsModal
* Remove MULTICHAIN check for AssetList
* Update QR dimensions
* Remove MULTICHAIN declaration from metamaskrc.dist
* Implement PickerNetwork and NetworkListMenu in onboarding
* Remove legacy NetworkDropdown and Dropdown
* Remove documentation about legacy account menu
* FIX: Fixes route tests for missing data-testid=network-display
* Fix account-menu-icon data-testid
* Fix TokenCell test
* FIX Onboarding Flow tests
* Remove unused locales from AccountMenu removal
* E2E: Fix Import Secret Recovery Phrase: logs out of the vault
* E2E: Fix Show account details: should show the QR code for the account
* E2E: Fix add-account.spec.js
* E2E: Fix state-logs.spec.js
* E2E: Fix lock-account.spec.js
* E2E: Fix settings-general.spec.js
* E2E: Fix advanced-settings.spec.js
* E2E: Fix auto-lock.spec.js
* E2E: Fix backup-restore.spec.js
* E2E: Fix clear-activity.spec.js
* E2E: Fix settings-search.spec.js
* E2E: Fix encrypt-decrypt.spec.js
* E2E: Fix dapp-interactions.spec.js
* E2E: Fix test-snap-management.spec.js
* E2E: Fix add-custom-network.spec.js
* E2E: Fix from-import-ui.spec.js
* E2E: Fix provider-api.spec.js
* E2E: Fix chain-interactions.spec.js
* E2E: Fix custom-rpc-history.spec.js
* Remove network icon from overview components
* E2E: Fix user-actions-benchmark.js
* E2E: Fix benchmark.js
* E2E: Fix add-hide-token.spec.js
* E2E: Fix address-book.spec.js
* E2E: Fix custom-token-add-approve.spec.js
* E2E: Fix incremental-security.spec.js
* E2E: Fix metamask-responsive-ui.spec.js
* E2E: Onboarding.spec.js
* E2E: Fix permissions.spec.js
* E2E: Fix send-hex-address.spec.js
* E2E: Fix send-to-contract.spec.js
* Remove dead AccountOptionsMenu test
* E2E: Fix token-details.spec.js
* E2E: Fix switch-custom-network.spec.js
* E2E: Fix metamask-ui.spec.js
* Revert "UX Multichain: updated border top for activity list (#19176)"
This reverts commit 15598f2a23
.
* E2Es: Fix test-snap-management.spec.js and test-snap-notification.spec.js
* E2Es: Fix add-account.spec.js after flaky test fixes
* e2e flaky test
* adds back the mmi options
* scss fix
* test fix
* removes unnecessary double quotes
* Prevent double logos on login screen
* Update ui/components/ui/list-item/index.scss
Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
---------
Co-authored-by: seaona <mariona@gmx.es>
Co-authored-by: Antonio Regadas <antonio.regadas@consensys.net>
Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
304 lines
10 KiB
JavaScript
304 lines
10 KiB
JavaScript
import React, { useState, useContext, useRef, useEffect } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { useHistory } from 'react-router-dom';
|
|
import Fuse from 'fuse.js';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import Box from '../../ui/box/box';
|
|
import {
|
|
IconName,
|
|
ButtonLink,
|
|
TextFieldSearch,
|
|
Text,
|
|
} from '../../component-library';
|
|
import { AccountListItem } from '..';
|
|
import {
|
|
BLOCK_SIZES,
|
|
Size,
|
|
TextColor,
|
|
} from '../../../helpers/constants/design-system';
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
|
import Popover from '../../ui/popover';
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
import {
|
|
getMmiPortfolioEnabled,
|
|
getMmiPortfolioUrl,
|
|
} from '../../../selectors/institutional/selectors';
|
|
///: END:ONLY_INCLUDE_IN
|
|
import {
|
|
getSelectedAccount,
|
|
getMetaMaskAccountsOrdered,
|
|
getConnectedSubjectsForAllAddresses,
|
|
getOriginOfCurrentTab,
|
|
} from '../../../selectors';
|
|
import { toggleAccountMenu, setSelectedAccount } from '../../../store/actions';
|
|
import {
|
|
MetaMetricsEventAccountType,
|
|
MetaMetricsEventCategory,
|
|
MetaMetricsEventName,
|
|
} from '../../../../shared/constants/metametrics';
|
|
import {
|
|
IMPORT_ACCOUNT_ROUTE,
|
|
NEW_ACCOUNT_ROUTE,
|
|
CONNECT_HARDWARE_ROUTE,
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
CUSTODY_ACCOUNT_ROUTE,
|
|
COMPLIANCE_FEATURE_ROUTE,
|
|
///: END:ONLY_INCLUDE_IN
|
|
} from '../../../helpers/constants/routes';
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
|
|
import { ENVIRONMENT_TYPE_POPUP } from '../../../../shared/constants/app';
|
|
|
|
export const AccountListMenu = ({ onClose }) => {
|
|
const t = useI18nContext();
|
|
const trackEvent = useContext(MetaMetricsContext);
|
|
const accounts = useSelector(getMetaMaskAccountsOrdered);
|
|
const selectedAccount = useSelector(getSelectedAccount);
|
|
const connectedSites = useSelector(getConnectedSubjectsForAllAddresses);
|
|
const currentTabOrigin = useSelector(getOriginOfCurrentTab);
|
|
const history = useHistory();
|
|
const dispatch = useDispatch();
|
|
const inputRef = useRef();
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
const mmiPortfolioUrl = useSelector(getMmiPortfolioUrl);
|
|
const mmiPortfolioEnabled = useSelector(getMmiPortfolioEnabled);
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
const [searchQuery, setSearchQuery] = useState('');
|
|
|
|
let searchResults = accounts;
|
|
if (searchQuery) {
|
|
const fuse = new Fuse(accounts, {
|
|
threshold: 0.2,
|
|
location: 0,
|
|
distance: 100,
|
|
maxPatternLength: 32,
|
|
minMatchCharLength: 1,
|
|
keys: ['name', 'address'],
|
|
});
|
|
fuse.setCollection(accounts);
|
|
searchResults = fuse.search(searchQuery);
|
|
}
|
|
|
|
// Focus on the search box when the popover is opened
|
|
useEffect(() => {
|
|
if (inputRef.current) {
|
|
inputRef.current.rootNode.querySelector('input[type=search]')?.focus();
|
|
}
|
|
}, [inputRef]);
|
|
|
|
return (
|
|
<Popover
|
|
title={t('selectAnAccount')}
|
|
ref={inputRef}
|
|
centerTitle
|
|
onClose={onClose}
|
|
>
|
|
<Box className="multichain-account-menu">
|
|
{/* Search box */}
|
|
{accounts.length > 1 ? (
|
|
<Box
|
|
paddingLeft={4}
|
|
paddingRight={4}
|
|
paddingBottom={4}
|
|
paddingTop={0}
|
|
>
|
|
<TextFieldSearch
|
|
size={Size.SM}
|
|
width={BLOCK_SIZES.FULL}
|
|
placeholder={t('searchAccounts')}
|
|
value={searchQuery}
|
|
onChange={(e) => setSearchQuery(e.target.value)}
|
|
clearButtonOnClick={() => setSearchQuery('')}
|
|
clearButtonProps={{
|
|
size: Size.SM,
|
|
}}
|
|
/>
|
|
</Box>
|
|
) : null}
|
|
{/* Account list block */}
|
|
<Box className="multichain-account-menu__list">
|
|
{searchResults.length === 0 && searchQuery !== '' ? (
|
|
<Text
|
|
paddingLeft={4}
|
|
paddingRight={4}
|
|
color={TextColor.textMuted}
|
|
data-testid="multichain-account-menu-no-results"
|
|
>
|
|
{t('noAccountsFound')}
|
|
</Text>
|
|
) : null}
|
|
{searchResults.map((account) => {
|
|
const connectedSite = connectedSites[account.address]?.find(
|
|
({ origin }) => origin === currentTabOrigin,
|
|
);
|
|
|
|
return (
|
|
<AccountListItem
|
|
onClick={() => {
|
|
dispatch(toggleAccountMenu());
|
|
trackEvent({
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
event: MetaMetricsEventName.NavAccountSwitched,
|
|
properties: {
|
|
location: 'Main Menu',
|
|
},
|
|
});
|
|
dispatch(setSelectedAccount(account.address));
|
|
}}
|
|
identity={account}
|
|
key={account.address}
|
|
selected={selectedAccount.address === account.address}
|
|
closeMenu={onClose}
|
|
connectedAvatar={connectedSite?.iconUrl}
|
|
connectedAvatarName={connectedSite?.name}
|
|
/>
|
|
);
|
|
})}
|
|
</Box>
|
|
{/* Add / Import / Hardware */}
|
|
<Box padding={4}>
|
|
<Box marginBottom={4}>
|
|
<ButtonLink
|
|
size={Size.SM}
|
|
startIconName={IconName.Add}
|
|
onClick={() => {
|
|
dispatch(toggleAccountMenu());
|
|
trackEvent({
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
event: MetaMetricsEventName.AccountAddSelected,
|
|
properties: {
|
|
account_type: MetaMetricsEventAccountType.Default,
|
|
location: 'Main Menu',
|
|
},
|
|
});
|
|
history.push(NEW_ACCOUNT_ROUTE);
|
|
}}
|
|
data-testid="multichain-account-menu-add-account"
|
|
>
|
|
{t('addAccount')}
|
|
</ButtonLink>
|
|
</Box>
|
|
<Box marginBottom={4}>
|
|
<ButtonLink
|
|
size={Size.SM}
|
|
startIconName={IconName.Import}
|
|
onClick={() => {
|
|
dispatch(toggleAccountMenu());
|
|
trackEvent({
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
event: MetaMetricsEventName.AccountAddSelected,
|
|
properties: {
|
|
account_type: MetaMetricsEventAccountType.Imported,
|
|
location: 'Main Menu',
|
|
},
|
|
});
|
|
history.push(IMPORT_ACCOUNT_ROUTE);
|
|
}}
|
|
>
|
|
{t('importAccount')}
|
|
</ButtonLink>
|
|
</Box>
|
|
<Box>
|
|
<ButtonLink
|
|
size={Size.SM}
|
|
startIconName={IconName.Hardware}
|
|
onClick={() => {
|
|
dispatch(toggleAccountMenu());
|
|
trackEvent({
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
event: MetaMetricsEventName.AccountAddSelected,
|
|
properties: {
|
|
account_type: MetaMetricsEventAccountType.Hardware,
|
|
location: 'Main Menu',
|
|
},
|
|
});
|
|
if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) {
|
|
global.platform.openExtensionInBrowser(
|
|
CONNECT_HARDWARE_ROUTE,
|
|
);
|
|
} else {
|
|
history.push(CONNECT_HARDWARE_ROUTE);
|
|
}
|
|
}}
|
|
>
|
|
{t('hardwareWallet')}
|
|
</ButtonLink>
|
|
{
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
<>
|
|
<ButtonLink
|
|
size={Size.SM}
|
|
startIconName={IconName.Custody}
|
|
onClick={() => {
|
|
dispatch(toggleAccountMenu());
|
|
trackEvent({
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
event:
|
|
MetaMetricsEventName.UserClickedConnectCustodialAccount,
|
|
});
|
|
if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) {
|
|
global.platform.openExtensionInBrowser(
|
|
CUSTODY_ACCOUNT_ROUTE,
|
|
);
|
|
} else {
|
|
history.push(CUSTODY_ACCOUNT_ROUTE);
|
|
}
|
|
}}
|
|
>
|
|
{t('connectCustodialAccountMenu')}
|
|
</ButtonLink>
|
|
{mmiPortfolioEnabled && (
|
|
<ButtonLink
|
|
size={Size.SM}
|
|
startIconName={IconName.MmmiPortfolioDashboard}
|
|
onClick={() => {
|
|
dispatch(toggleAccountMenu());
|
|
trackEvent({
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
event: MetaMetricsEventName.UserClickedPortfolioButton,
|
|
});
|
|
window.open(mmiPortfolioUrl, '_blank');
|
|
}}
|
|
>
|
|
{t('portfolioDashboard')}
|
|
</ButtonLink>
|
|
)}
|
|
<ButtonLink
|
|
size={Size.SM}
|
|
startIconName={IconName.Compliance}
|
|
onClick={() => {
|
|
dispatch(toggleAccountMenu());
|
|
trackEvent({
|
|
category: MetaMetricsEventCategory.Navigation,
|
|
event: MetaMetricsEventName.UserClickedCompliance,
|
|
});
|
|
if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) {
|
|
global.platform.openExtensionInBrowser(
|
|
COMPLIANCE_FEATURE_ROUTE,
|
|
);
|
|
} else {
|
|
history.push(COMPLIANCE_FEATURE_ROUTE);
|
|
}
|
|
}}
|
|
>
|
|
{t('compliance')}
|
|
</ButtonLink>
|
|
</>
|
|
///: END:ONLY_INCLUDE_IN
|
|
}
|
|
</Box>
|
|
</Box>
|
|
</Box>
|
|
</Popover>
|
|
);
|
|
};
|
|
|
|
AccountListMenu.propTypes = {
|
|
/**
|
|
* Function that executes when the menu closes
|
|
*/
|
|
onClose: PropTypes.func.isRequired,
|
|
};
|