diff --git a/ui/components/multichain/account-list-menu/account-list-menu.js b/ui/components/multichain/account-list-menu/account-list-menu.js index ff0f6b236..4e942d823 100644 --- a/ui/components/multichain/account-list-menu/account-list-menu.js +++ b/ui/components/multichain/account-list-menu/account-list-menu.js @@ -1,4 +1,4 @@ -import React, { useState, useContext, useRef, useEffect } from 'react'; +import React, { useState, useContext } from 'react'; import PropTypes from 'prop-types'; import { useHistory } from 'react-router-dom'; import Fuse from 'fuse.js'; @@ -9,6 +9,10 @@ import { TextFieldSearch, Text, Box, + Modal, + ModalContent, + ModalOverlay, + ModalHeader, } from '../../component-library'; import { AccountListItem, CreateAccount, ImportAccount } from '..'; import { @@ -18,7 +22,6 @@ import { } from '../../../helpers/constants/design-system'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { MetaMetricsContext } from '../../../contexts/metametrics'; -import Popover from '../../ui/popover'; import { getSelectedAccount, getMetaMaskAccountsOrdered, @@ -52,7 +55,6 @@ export const AccountListMenu = ({ onClose }) => { const currentTabOrigin = useSelector(getOriginOfCurrentTab); const history = useHistory(); const dispatch = useDispatch(); - const inputRef = useRef(); const [searchQuery, setSearchQuery] = useState(''); const [actionMode, setActionMode] = useState(''); @@ -71,13 +73,6 @@ export const AccountListMenu = ({ onClose }) => { 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]); - let title = t('selectAnAccount'); if (actionMode === 'add') { title = t('addAccount'); @@ -86,225 +81,244 @@ export const AccountListMenu = ({ onClose }) => { } return ( - setActionMode('')} - className="multichain-account-menu-popover" - > - {actionMode === 'add' ? ( - - { - if (confirmed) { - dispatch(toggleAccountMenu()); - } else { - setActionMode(''); - } - }} - /> - - ) : null} - {actionMode === 'import' ? ( - - { - if (confirmed) { - dispatch(toggleAccountMenu()); - } else { - setActionMode(''); - } - }} - /> - - ) : null} - {actionMode === '' ? ( - - {/* Search box */} - {accounts.length > 1 ? ( - - setSearchQuery(e.target.value)} - clearButtonOnClick={() => setSearchQuery('')} - clearButtonProps={{ - size: Size.SM, - }} - /> - - ) : null} - {/* Account list block */} - - {searchResults.length === 0 && searchQuery !== '' ? ( - + + + setActionMode('')} + > + {title} + + {actionMode === 'add' ? ( + + { + if (confirmed) { + dispatch(toggleAccountMenu()); + } else { + setActionMode(''); + } + }} + /> + + ) : null} + {actionMode === 'import' ? ( + + { + if (confirmed) { + dispatch(toggleAccountMenu()); + } else { + setActionMode(''); + } + }} + /> + + ) : null} + {actionMode === '' ? ( + + {/* Search box */} + {accounts.length > 1 ? ( + - {t('noAccountsFound')} - + setSearchQuery(e.target.value)} + clearButtonOnClick={() => setSearchQuery('')} + clearButtonProps={{ + size: Size.SM, + }} + inputProps={{ autoFocus: true }} + /> + ) : null} - {searchResults.map((account) => { - const connectedSite = connectedSites[account.address]?.find( - ({ origin }) => origin === currentTabOrigin, - ); + {/* Account list block */} + + {searchResults.length === 0 && searchQuery !== '' ? ( + + {t('noAccountsFound')} + + ) : null} + {searchResults.map((account) => { + const connectedSite = connectedSites[account.address]?.find( + ({ origin }) => origin === currentTabOrigin, + ); - return ( - { + 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} + /> + ); + })} + + {/* Add / Import / Hardware */} + + + { - dispatch(toggleAccountMenu()); trackEvent({ category: MetaMetricsEventCategory.Navigation, - event: MetaMetricsEventName.NavAccountSwitched, + event: MetaMetricsEventName.AccountAddSelected, properties: { + account_type: MetaMetricsEventAccountType.Default, location: 'Main Menu', }, }); - dispatch(setSelectedAccount(account.address)); + setActionMode('add'); }} - identity={account} - key={account.address} - selected={selectedAccount.address === account.address} - closeMenu={onClose} - connectedAvatar={connectedSite?.iconUrl} - connectedAvatarName={connectedSite?.name} - /> - ); - })} - - {/* Add / Import / Hardware */} - - - { - trackEvent({ - category: MetaMetricsEventCategory.Navigation, - event: MetaMetricsEventName.AccountAddSelected, - properties: { - account_type: MetaMetricsEventAccountType.Default, - location: 'Main Menu', - }, - }); - setActionMode('add'); - }} - data-testid="multichain-account-menu-popover-add-account" - > - {t('addAccount')} - - - - { - trackEvent({ - category: MetaMetricsEventCategory.Navigation, - event: MetaMetricsEventName.AccountAddSelected, - properties: { - account_type: MetaMetricsEventAccountType.Imported, - location: 'Main Menu', - }, - }); - setActionMode('import'); - }} - > - {t('importAccount')} - - - - { - 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')} - - - { - ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) - <> - - { - dispatch(toggleAccountMenu()); - getEnvironmentType() === ENVIRONMENT_TYPE_POPUP - ? global.platform.openExtensionInBrowser( - ADD_SNAP_ACCOUNT_ROUTE, - null, - true, - ) - : history.push(ADD_SNAP_ACCOUNT_ROUTE); - }} - > - {t('settingAddSnapAccount')} - - - - ///: END:ONLY_INCLUDE_IN - } - { - ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) - + data-testid="multichain-account-menu-popover-add-account" + > + {t('addAccount')} + + + { + trackEvent({ + category: MetaMetricsEventCategory.Navigation, + event: MetaMetricsEventName.AccountAddSelected, + properties: { + account_type: MetaMetricsEventAccountType.Imported, + location: 'Main Menu', + }, + }); + setActionMode('import'); + }} + > + {t('importAccount')} + + + + { dispatch(toggleAccountMenu()); trackEvent({ category: MetaMetricsEventCategory.Navigation, - event: - MetaMetricsEventName.UserClickedConnectCustodialAccount, + event: MetaMetricsEventName.AccountAddSelected, + properties: { + account_type: MetaMetricsEventAccountType.Hardware, + location: 'Main Menu', + }, }); if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) { global.platform.openExtensionInBrowser( - CUSTODY_ACCOUNT_ROUTE, + CONNECT_HARDWARE_ROUTE, ); } else { - history.push(CUSTODY_ACCOUNT_ROUTE); + history.push(CONNECT_HARDWARE_ROUTE); } }} > - {t('connectCustodialAccountMenu')} + {t('hardwareWallet')} - ///: END:ONLY_INCLUDE_IN - } + { + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + <> + + { + dispatch(toggleAccountMenu()); + getEnvironmentType() === ENVIRONMENT_TYPE_POPUP + ? global.platform.openExtensionInBrowser( + ADD_SNAP_ACCOUNT_ROUTE, + null, + true, + ) + : history.push(ADD_SNAP_ACCOUNT_ROUTE); + }} + > + {t('settingAddSnapAccount')} + + + + ///: END:ONLY_INCLUDE_IN + } + { + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + + { + 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')} + + + ///: END:ONLY_INCLUDE_IN + } + - - ) : null} - + ) : null} + + ); };