1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

[FIX #12760] Highlighting on search (#13730)

This commit is contained in:
amerkadicE 2022-02-24 20:06:30 +01:00 committed by GitHub
parent 028850899e
commit 3ed08a09e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 138 additions and 63 deletions

View File

@ -10,9 +10,6 @@ import {
EXPERIMENTAL_ROUTE, EXPERIMENTAL_ROUTE,
} from '../constants/routes'; } from '../constants/routes';
const MENU_TAB = 'menu-tab';
const MENU_SECTION = 'menu-section';
function showHideSettings(t, settings) { function showHideSettings(t, settings) {
if (!process.env.COLLECTIBLES_V1) { if (!process.env.COLLECTIBLES_V1) {
return settings.filter( return settings.filter(
@ -32,6 +29,7 @@ export function getSettingsRoutes(t) {
description: '', description: '',
route: `${GENERAL_ROUTE}#currency-conversion`, route: `${GENERAL_ROUTE}#currency-conversion`,
image: 'general-icon.svg', image: 'general-icon.svg',
id: 1,
}, },
{ {
tab: t('general'), tab: t('general'),
@ -39,6 +37,7 @@ export function getSettingsRoutes(t) {
description: t('primaryCurrencySettingDescription'), description: t('primaryCurrencySettingDescription'),
route: `${GENERAL_ROUTE}#primary-currency`, route: `${GENERAL_ROUTE}#primary-currency`,
image: 'general-icon.svg', image: 'general-icon.svg',
id: 2,
}, },
{ {
tab: t('general'), tab: t('general'),
@ -46,6 +45,7 @@ export function getSettingsRoutes(t) {
description: '', description: '',
route: `${GENERAL_ROUTE}#current-language`, route: `${GENERAL_ROUTE}#current-language`,
image: 'general-icon.svg', image: 'general-icon.svg',
id: 3,
}, },
{ {
tab: t('general'), tab: t('general'),
@ -53,6 +53,7 @@ export function getSettingsRoutes(t) {
description: '', description: '',
route: `${GENERAL_ROUTE}#account-identicon`, route: `${GENERAL_ROUTE}#account-identicon`,
image: 'general-icon.svg', image: 'general-icon.svg',
id: 4,
}, },
{ {
tab: t('general'), tab: t('general'),
@ -60,6 +61,7 @@ export function getSettingsRoutes(t) {
description: '', description: '',
route: `${GENERAL_ROUTE}#zero-balancetokens`, route: `${GENERAL_ROUTE}#zero-balancetokens`,
image: 'general-icon.svg', image: 'general-icon.svg',
id: 5,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -67,6 +69,7 @@ export function getSettingsRoutes(t) {
description: t('stateLogsDescription'), description: t('stateLogsDescription'),
route: `${ADVANCED_ROUTE}#state-logs`, route: `${ADVANCED_ROUTE}#state-logs`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 6,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -74,6 +77,7 @@ export function getSettingsRoutes(t) {
description: '', description: '',
route: `${ADVANCED_ROUTE}#sync-withmobile`, route: `${ADVANCED_ROUTE}#sync-withmobile`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 7,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -81,6 +85,7 @@ export function getSettingsRoutes(t) {
description: t('resetAccountDescription'), description: t('resetAccountDescription'),
route: `${ADVANCED_ROUTE}#reset-account`, route: `${ADVANCED_ROUTE}#reset-account`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 8,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -88,6 +93,7 @@ export function getSettingsRoutes(t) {
description: t('showAdvancedGasInlineDescription'), description: t('showAdvancedGasInlineDescription'),
route: `${ADVANCED_ROUTE}#advanced-gascontrols`, route: `${ADVANCED_ROUTE}#advanced-gascontrols`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 9,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -95,6 +101,7 @@ export function getSettingsRoutes(t) {
description: t('showHexDataDescription'), description: t('showHexDataDescription'),
route: `${ADVANCED_ROUTE}#show-hexdata`, route: `${ADVANCED_ROUTE}#show-hexdata`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 10,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -102,6 +109,7 @@ export function getSettingsRoutes(t) {
description: t('showFiatConversionInTestnetsDescription'), description: t('showFiatConversionInTestnetsDescription'),
route: `${ADVANCED_ROUTE}#conversion-testnetworks`, route: `${ADVANCED_ROUTE}#conversion-testnetworks`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 11,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -109,6 +117,7 @@ export function getSettingsRoutes(t) {
description: t('showTestnetNetworksDescription'), description: t('showTestnetNetworksDescription'),
route: `${ADVANCED_ROUTE}#show-testnets`, route: `${ADVANCED_ROUTE}#show-testnets`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 12,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -116,6 +125,7 @@ export function getSettingsRoutes(t) {
description: t('nonceFieldDescription'), description: t('nonceFieldDescription'),
route: `${ADVANCED_ROUTE}#customize-nonce`, route: `${ADVANCED_ROUTE}#customize-nonce`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 13,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -123,6 +133,7 @@ export function getSettingsRoutes(t) {
description: t('autoLockTimeLimitDescription'), description: t('autoLockTimeLimitDescription'),
route: `${ADVANCED_ROUTE}#autolock-timer`, route: `${ADVANCED_ROUTE}#autolock-timer`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 14,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -130,6 +141,7 @@ export function getSettingsRoutes(t) {
description: t('syncWithThreeBoxDescription'), description: t('syncWithThreeBoxDescription'),
route: `${ADVANCED_ROUTE}#sync-with3box`, route: `${ADVANCED_ROUTE}#sync-with3box`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 15,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -137,6 +149,7 @@ export function getSettingsRoutes(t) {
description: t('ipfsGatewayDescription'), description: t('ipfsGatewayDescription'),
route: `${ADVANCED_ROUTE}#ipfs-gateway`, route: `${ADVANCED_ROUTE}#ipfs-gateway`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 16,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -144,6 +157,7 @@ export function getSettingsRoutes(t) {
description: t('preferredLedgerConnectionType'), description: t('preferredLedgerConnectionType'),
route: `${ADVANCED_ROUTE}#ledger-connection`, route: `${ADVANCED_ROUTE}#ledger-connection`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 17,
}, },
{ {
tab: t('advanced'), tab: t('advanced'),
@ -151,6 +165,7 @@ export function getSettingsRoutes(t) {
description: t('dismissReminderDescriptionField'), description: t('dismissReminderDescriptionField'),
route: `${ADVANCED_ROUTE}#dimiss-secretrecovery`, route: `${ADVANCED_ROUTE}#dimiss-secretrecovery`,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
id: 18,
}, },
{ {
tab: t('contacts'), tab: t('contacts'),
@ -158,6 +173,7 @@ export function getSettingsRoutes(t) {
description: t('contacts'), description: t('contacts'),
route: CONTACT_LIST_ROUTE, route: CONTACT_LIST_ROUTE,
image: 'contacts-icon.svg', image: 'contacts-icon.svg',
id: 19,
}, },
{ {
tab: t('securityAndPrivacy'), tab: t('securityAndPrivacy'),
@ -165,6 +181,7 @@ export function getSettingsRoutes(t) {
description: t('revealSeedWords'), description: t('revealSeedWords'),
route: `${SECURITY_ROUTE}#reveal-secretrecovery`, route: `${SECURITY_ROUTE}#reveal-secretrecovery`,
image: 'security-icon.svg', image: 'security-icon.svg',
id: 20,
}, },
{ {
tab: t('securityAndPrivacy'), tab: t('securityAndPrivacy'),
@ -172,6 +189,7 @@ export function getSettingsRoutes(t) {
description: t('showIncomingTransactionsDescription'), description: t('showIncomingTransactionsDescription'),
route: `${SECURITY_ROUTE}#incoming-transaction`, route: `${SECURITY_ROUTE}#incoming-transaction`,
image: 'security-icon.svg', image: 'security-icon.svg',
id: 21,
}, },
{ {
tab: t('securityAndPrivacy'), tab: t('securityAndPrivacy'),
@ -179,6 +197,7 @@ export function getSettingsRoutes(t) {
description: t('usePhishingDetectionDescription'), description: t('usePhishingDetectionDescription'),
route: `${SECURITY_ROUTE}#phishing-detection`, route: `${SECURITY_ROUTE}#phishing-detection`,
image: 'security-icon.svg', image: 'security-icon.svg',
id: 22,
}, },
{ {
tab: t('securityAndPrivacy'), tab: t('securityAndPrivacy'),
@ -186,6 +205,7 @@ export function getSettingsRoutes(t) {
description: t('participateInMetaMetricsDescription'), description: t('participateInMetaMetricsDescription'),
route: `${SECURITY_ROUTE}#metrametrics`, route: `${SECURITY_ROUTE}#metrametrics`,
image: 'security-icon.svg', image: 'security-icon.svg',
id: 23,
}, },
{ {
tab: t('alerts'), tab: t('alerts'),
@ -193,6 +213,7 @@ export function getSettingsRoutes(t) {
description: t('alertSettingsUnconnectedAccount'), description: t('alertSettingsUnconnectedAccount'),
route: `${ALERTS_ROUTE}#unconnected-account`, route: `${ALERTS_ROUTE}#unconnected-account`,
image: 'alerts-icon.svg', image: 'alerts-icon.svg',
id: 24,
}, },
{ {
tab: t('alerts'), tab: t('alerts'),
@ -200,6 +221,7 @@ export function getSettingsRoutes(t) {
description: t('alertSettingsWeb3ShimUsage'), description: t('alertSettingsWeb3ShimUsage'),
route: `${ALERTS_ROUTE}#web3-shimusage`, route: `${ALERTS_ROUTE}#web3-shimusage`,
image: 'alerts-icon.svg', image: 'alerts-icon.svg',
id: 25,
}, },
{ {
tab: t('networks'), tab: t('networks'),
@ -207,6 +229,7 @@ export function getSettingsRoutes(t) {
description: t('mainnet'), description: t('mainnet'),
route: `${NETWORKS_ROUTE}#networks-mainnet`, route: `${NETWORKS_ROUTE}#networks-mainnet`,
image: 'network-icon.svg', image: 'network-icon.svg',
id: 26,
}, },
{ {
tab: t('networks'), tab: t('networks'),
@ -214,6 +237,7 @@ export function getSettingsRoutes(t) {
description: t('ropsten'), description: t('ropsten'),
route: `${NETWORKS_ROUTE}#networks-ropsten`, route: `${NETWORKS_ROUTE}#networks-ropsten`,
image: 'network-icon.svg', image: 'network-icon.svg',
id: 27,
}, },
{ {
tab: t('networks'), tab: t('networks'),
@ -221,6 +245,7 @@ export function getSettingsRoutes(t) {
description: t('rinkeby'), description: t('rinkeby'),
route: `${NETWORKS_ROUTE}#networks-rinkeby`, route: `${NETWORKS_ROUTE}#networks-rinkeby`,
image: 'network-icon.svg', image: 'network-icon.svg',
id: 28,
}, },
{ {
tab: t('networks'), tab: t('networks'),
@ -228,6 +253,7 @@ export function getSettingsRoutes(t) {
description: t('goerli'), description: t('goerli'),
route: `${NETWORKS_ROUTE}#networks-goerli`, route: `${NETWORKS_ROUTE}#networks-goerli`,
image: 'network-icon.svg', image: 'network-icon.svg',
id: 29,
}, },
{ {
tab: t('networks'), tab: t('networks'),
@ -235,6 +261,7 @@ export function getSettingsRoutes(t) {
description: t('kovan'), description: t('kovan'),
route: `${NETWORKS_ROUTE}#networtks-kovan`, route: `${NETWORKS_ROUTE}#networtks-kovan`,
image: 'network-icon.svg', image: 'network-icon.svg',
id: 30,
}, },
{ {
tab: t('networks'), tab: t('networks'),
@ -242,6 +269,7 @@ export function getSettingsRoutes(t) {
description: t('localhost'), description: t('localhost'),
route: `${NETWORKS_ROUTE}#network-localhost`, route: `${NETWORKS_ROUTE}#network-localhost`,
image: 'network-icon.svg', image: 'network-icon.svg',
id: 31,
}, },
{ {
tab: t('experimental'), tab: t('experimental'),
@ -249,6 +277,7 @@ export function getSettingsRoutes(t) {
description: t('useTokenDetectionDescription'), description: t('useTokenDetectionDescription'),
route: `${EXPERIMENTAL_ROUTE}#token-description`, route: `${EXPERIMENTAL_ROUTE}#token-description`,
image: 'experimental-icon.svg', image: 'experimental-icon.svg',
id: 32,
}, },
{ {
tab: t('experimental'), tab: t('experimental'),
@ -256,6 +285,7 @@ export function getSettingsRoutes(t) {
description: t('enableOpenSeaAPIDescription'), description: t('enableOpenSeaAPIDescription'),
route: `${EXPERIMENTAL_ROUTE}#opensea-api`, route: `${EXPERIMENTAL_ROUTE}#opensea-api`,
image: 'experimental-icon.svg', image: 'experimental-icon.svg',
id: 33,
}, },
{ {
tab: t('experimental'), tab: t('experimental'),
@ -263,6 +293,7 @@ export function getSettingsRoutes(t) {
description: t('useCollectibleDetectionDescription'), description: t('useCollectibleDetectionDescription'),
route: `${EXPERIMENTAL_ROUTE}#autodetect-nfts`, route: `${EXPERIMENTAL_ROUTE}#autodetect-nfts`,
image: 'experimental-icon.svg', image: 'experimental-icon.svg',
id: 34,
}, },
{ {
@ -271,6 +302,7 @@ export function getSettingsRoutes(t) {
description: t('builtAroundTheWorld'), description: t('builtAroundTheWorld'),
route: `${ABOUT_US_ROUTE}#version`, route: `${ABOUT_US_ROUTE}#version`,
image: 'info-icon.svg', image: 'info-icon.svg',
id: 35,
}, },
{ {
tab: t('about'), tab: t('about'),
@ -278,6 +310,7 @@ export function getSettingsRoutes(t) {
description: '', description: '',
route: `${ABOUT_US_ROUTE}#links`, route: `${ABOUT_US_ROUTE}#links`,
image: 'info-icon.svg', image: 'info-icon.svg',
id: 36,
}, },
{ {
tab: t('about'), tab: t('about'),
@ -285,6 +318,7 @@ export function getSettingsRoutes(t) {
description: t('privacyMsg'), description: t('privacyMsg'),
route: `${ABOUT_US_ROUTE}#privacy-policy`, route: `${ABOUT_US_ROUTE}#privacy-policy`,
image: 'info-icon.svg', image: 'info-icon.svg',
id: 37,
}, },
{ {
tab: t('about'), tab: t('about'),
@ -292,6 +326,7 @@ export function getSettingsRoutes(t) {
description: t('terms'), description: t('terms'),
route: `${ABOUT_US_ROUTE}#terms`, route: `${ABOUT_US_ROUTE}#terms`,
image: 'info-icon.svg', image: 'info-icon.svg',
id: 38,
}, },
{ {
@ -300,6 +335,7 @@ export function getSettingsRoutes(t) {
description: t('attributions'), description: t('attributions'),
route: `${ABOUT_US_ROUTE}#attributions`, route: `${ABOUT_US_ROUTE}#attributions`,
image: 'info-icon.svg', image: 'info-icon.svg',
id: 39,
}, },
{ {
@ -308,6 +344,7 @@ export function getSettingsRoutes(t) {
description: t('supportCenter'), description: t('supportCenter'),
route: `${ABOUT_US_ROUTE}#supportcenter`, route: `${ABOUT_US_ROUTE}#supportcenter`,
image: 'info-icon.svg', image: 'info-icon.svg',
id: 40,
}, },
{ {
@ -316,6 +353,7 @@ export function getSettingsRoutes(t) {
description: t('visitWebSite'), description: t('visitWebSite'),
route: `${ABOUT_US_ROUTE}#visitwebsite`, route: `${ABOUT_US_ROUTE}#visitwebsite`,
image: 'info-icon.svg', image: 'info-icon.svg',
id: 41,
}, },
{ {
@ -324,6 +362,7 @@ export function getSettingsRoutes(t) {
description: t('contactUs'), description: t('contactUs'),
route: `${ABOUT_US_ROUTE}#contactus`, route: `${ABOUT_US_ROUTE}#contactus`,
image: 'info-icon.svg', image: 'info-icon.svg',
id: 42,
}, },
]; ];
@ -392,16 +431,21 @@ function colorText(menuElement, regex) {
); );
} }
} }
export function highlightSearchedText(menuIndex) { export function highlightSearchedText() {
const menuTabElement = document.getElementById(`${MENU_TAB}_${menuIndex}`); const searchElem = document.getElementById('search-settings');
const menuSectionElement = document.getElementById( const searchRegex = new RegExp(searchElem.value, 'gi');
`${MENU_SECTION}_${menuIndex}`, const results = document.querySelectorAll(
'.settings-page__header__search__list__item',
);
[...results].forEach((element) => {
const menuTabElement = element.querySelector(
'.settings-page__header__search__list__item__tab',
);
const menuSectionElement = element.querySelector(
'.settings-page__header__search__list__item__section',
); );
const searchElem = document.getElementById('search-settings');
searchElem.addEventListener('input', (event) => {
const searchQuery = event.target.value;
const searchRegex = new RegExp(searchQuery, 'gi');
colorText(menuTabElement, searchRegex); colorText(menuTabElement, searchRegex);
colorText(menuSectionElement, searchRegex); colorText(menuSectionElement, searchRegex);
}); });

View File

@ -155,6 +155,7 @@ describe('Settings Search Utils', () => {
const settingsListExcepted = [ const settingsListExcepted = [
{ {
description: '', description: '',
id: 1,
image: 'general-icon.svg', image: 'general-icon.svg',
route: '/settings/general#currency-conversion', route: '/settings/general#currency-conversion',
section: 'Currency Conversion', section: 'Currency Conversion',
@ -163,6 +164,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Select native to prioritize displaying values in the native currency of the chain (e.g. ETH). Select Fiat to prioritize displaying values in your selected fiat currency.', 'Select native to prioritize displaying values in the native currency of the chain (e.g. ETH). Select Fiat to prioritize displaying values in your selected fiat currency.',
id: 2,
image: 'general-icon.svg', image: 'general-icon.svg',
route: '/settings/general#primary-currency', route: '/settings/general#primary-currency',
section: 'Primary Currenc', section: 'Primary Currenc',
@ -170,6 +172,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: '', description: '',
id: 3,
image: 'general-icon.svg', image: 'general-icon.svg',
route: '/settings/general#current-language', route: '/settings/general#current-language',
section: 'Current Language', section: 'Current Language',
@ -177,6 +180,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: '', description: '',
id: 4,
image: 'general-icon.svg', image: 'general-icon.svg',
route: '/settings/general#account-identicon', route: '/settings/general#account-identicon',
section: 'Current Language"', section: 'Current Language"',
@ -184,6 +188,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: '', description: '',
id: 5,
image: 'general-icon.svg', image: 'general-icon.svg',
route: '/settings/general#zero-balancetokens', route: '/settings/general#zero-balancetokens',
section: 'Hide Tokens Without Balance', section: 'Hide Tokens Without Balance',
@ -192,6 +197,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'State logs contain your public account addresses and sent transactions.', 'State logs contain your public account addresses and sent transactions.',
id: 6,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#state-logs', route: '/settings/advanced#state-logs',
section: 'State Logs', section: 'State Logs',
@ -199,6 +205,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: '', description: '',
id: 7,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#sync-withmobile', route: '/settings/advanced#sync-withmobile',
section: 'Sync with mobile', section: 'Sync with mobile',
@ -207,6 +214,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Resetting your account will clear your transaction history. This will not change the balances in your accounts or require you to re-enter your Secret Recovery Phrase.', 'Resetting your account will clear your transaction history. This will not change the balances in your accounts or require you to re-enter your Secret Recovery Phrase.',
id: 8,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#reset-account', route: '/settings/advanced#reset-account',
section: 'Reset Account', section: 'Reset Account',
@ -215,6 +223,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Select this to show gas price and limit controls directly on the send and confirm screens.', 'Select this to show gas price and limit controls directly on the send and confirm screens.',
id: 9,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#advanced-gascontrols', route: '/settings/advanced#advanced-gascontrols',
section: 'Advanced gas controls', section: 'Advanced gas controls',
@ -223,6 +232,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Select this to show the hex data field on the send screen', 'Select this to show the hex data field on the send screen',
id: 10,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#show-hexdata', route: '/settings/advanced#show-hexdata',
section: 'Show Hex Data', section: 'Show Hex Data',
@ -230,6 +240,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Select this to show fiat conversion on test network', description: 'Select this to show fiat conversion on test network',
id: 11,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#conversion-testnetworks', route: '/settings/advanced#conversion-testnetworks',
section: 'Show Conversion on test networks', section: 'Show Conversion on test networks',
@ -237,6 +248,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Select this to show test networks in network list', description: 'Select this to show test networks in network list',
id: 12,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#show-testnets', route: '/settings/advanced#show-testnets',
section: 'Show test networks', section: 'Show test networks',
@ -245,6 +257,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Turn this on to change the nonce (transaction number) on confirmation screens. This is an advanced feature, use cautiously.', 'Turn this on to change the nonce (transaction number) on confirmation screens. This is an advanced feature, use cautiously.',
id: 13,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#customize-nonce', route: '/settings/advanced#customize-nonce',
section: 'Customize transaction nonce', section: 'Customize transaction nonce',
@ -253,6 +266,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Set the idle time in minutes before MetaMask will become locked.', 'Set the idle time in minutes before MetaMask will become locked.',
id: 14,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#autolock-timer', route: '/settings/advanced#autolock-timer',
section: 'Auto-Lock Timer (minutes)', section: 'Auto-Lock Timer (minutes)',
@ -261,6 +275,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Turn on to have your settings backed up with 3Box. This feature is currently experimental; use at your own risk.', 'Turn on to have your settings backed up with 3Box. This feature is currently experimental; use at your own risk.',
id: 15,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#sync-with3box', route: '/settings/advanced#sync-with3box',
section: 'Sync data with 3Box (experimental)', section: 'Sync data with 3Box (experimental)',
@ -269,6 +284,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Enter the URL of the IPFS CID gateway to use for ENS content resolution.', 'Enter the URL of the IPFS CID gateway to use for ENS content resolution.',
id: 16,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#ipfs-gateway', route: '/settings/advanced#ipfs-gateway',
section: 'IPFS Gateway', section: 'IPFS Gateway',
@ -276,6 +292,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Preferred Ledger Connection Type', description: 'Preferred Ledger Connection Type',
id: 17,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#ledger-connection', route: '/settings/advanced#ledger-connection',
section: 'Preferred Ledger Connection Type', section: 'Preferred Ledger Connection Type',
@ -284,6 +301,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Turn this on to dismiss the Secret Recovery Phrase backup reminder message. We highly recommend that you back up your Secret Recovery Phrase to avoid loss of funds', 'Turn this on to dismiss the Secret Recovery Phrase backup reminder message. We highly recommend that you back up your Secret Recovery Phrase to avoid loss of funds',
id: 18,
image: 'advanced-icon.svg', image: 'advanced-icon.svg',
route: '/settings/advanced#dimiss-secretrecovery', route: '/settings/advanced#dimiss-secretrecovery',
section: 'Dismiss Secret Recovery Phrase backup reminder', section: 'Dismiss Secret Recovery Phrase backup reminder',
@ -291,6 +309,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: '', description: '',
id: 19,
image: 'contacts-icon.svg', image: 'contacts-icon.svg',
route: '/settings/contact-list', route: '/settings/contact-list',
section: '', section: '',
@ -298,6 +317,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Reveal Secret Recovery Phrase', description: 'Reveal Secret Recovery Phrase',
id: 20,
image: 'security-icon.svg', image: 'security-icon.svg',
route: '/settings/security#reveal-secretrecovery', route: '/settings/security#reveal-secretrecovery',
section: 'Reveal Secret Recovery Phrase', section: 'Reveal Secret Recovery Phrase',
@ -306,6 +326,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Select this to use Etherscan to show incoming transactions in the transactions list', 'Select this to use Etherscan to show incoming transactions in the transactions list',
id: 21,
image: 'security-icon.svg', image: 'security-icon.svg',
route: '/settings/security#incoming-transaction', route: '/settings/security#incoming-transaction',
section: 'Show Incoming Transactions', section: 'Show Incoming Transactions',
@ -314,6 +335,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Display a warning for phishing domains targeting Ethereum users', 'Display a warning for phishing domains targeting Ethereum users',
id: 22,
image: 'security-icon.svg', image: 'security-icon.svg',
route: '/settings/security#phishing-detection', route: '/settings/security#phishing-detection',
section: 'Use Phishing Detection', section: 'Use Phishing Detection',
@ -322,6 +344,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Participate in MetaMetrics to help us make MetaMask better', 'Participate in MetaMetrics to help us make MetaMask better',
id: 23,
image: 'security-icon.svg', image: 'security-icon.svg',
route: '/settings/security#metrametrics', route: '/settings/security#metrametrics',
section: 'Participate in MetaMetrics', section: 'Participate in MetaMetrics',
@ -330,6 +353,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'Browsing a website with an unconnected account selected', 'Browsing a website with an unconnected account selected',
id: 24,
image: 'alerts-icon.svg', image: 'alerts-icon.svg',
route: '/settings/alerts#unconnected-account', route: '/settings/alerts#unconnected-account',
section: 'Browsing a website with an unconnected account selected', section: 'Browsing a website with an unconnected account selected',
@ -338,6 +362,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'When a website tries to use the removed window.web3 API', 'When a website tries to use the removed window.web3 API',
id: 25,
image: 'alerts-icon.svg', image: 'alerts-icon.svg',
route: '/settings/alerts#web3-shimusage', route: '/settings/alerts#web3-shimusage',
section: 'When a website tries to use the removed window.web3 API', section: 'When a website tries to use the removed window.web3 API',
@ -345,6 +370,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Ethereum Mainnet', description: 'Ethereum Mainnet',
id: 26,
image: 'network-icon.svg', image: 'network-icon.svg',
route: '/settings/networks#networks-mainnet', route: '/settings/networks#networks-mainnet',
section: 'Ethereum Mainnet', section: 'Ethereum Mainnet',
@ -352,6 +378,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Ropsten Test Network', description: 'Ropsten Test Network',
id: 27,
image: 'network-icon.svg', image: 'network-icon.svg',
route: '/settings/networks#networks-ropsten', route: '/settings/networks#networks-ropsten',
section: 'Ropsten Test Network', section: 'Ropsten Test Network',
@ -359,6 +386,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Rinkeby Test Network', description: 'Rinkeby Test Network',
id: 28,
image: 'network-icon.svg', image: 'network-icon.svg',
route: '/settings/networks#networks-rinkeby', route: '/settings/networks#networks-rinkeby',
section: 'Rinkeby Test Network', section: 'Rinkeby Test Network',
@ -366,6 +394,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Goerli Test Network', description: 'Goerli Test Network',
id: 29,
image: 'network-icon.svg', image: 'network-icon.svg',
route: '/settings/networks#networks-goerli', route: '/settings/networks#networks-goerli',
section: 'Goerli Test Network', section: 'Goerli Test Network',
@ -373,6 +402,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Kovan Test Network', description: 'Kovan Test Network',
id: 30,
image: 'network-icon.svg', image: 'network-icon.svg',
route: '/settings/networks#networtks-kovan', route: '/settings/networks#networtks-kovan',
section: 'Kovan Test Network', section: 'Kovan Test Network',
@ -380,6 +410,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Localhost 8545', description: 'Localhost 8545',
id: 31,
image: 'network-icon.svg', image: 'network-icon.svg',
route: '/settings/networks#network-localhost', route: '/settings/networks#network-localhost',
section: 'Localhost 8545', section: 'Localhost 8545',
@ -388,6 +419,7 @@ describe('Settings Search Utils', () => {
{ {
description: description:
'We use third-party APIs to detect and display new tokens sent to your wallet. Turn off if you dont want MetaMask to pull data from those services.', 'We use third-party APIs to detect and display new tokens sent to your wallet. Turn off if you dont want MetaMask to pull data from those services.',
id: 32,
image: 'experimental-icon.svg', image: 'experimental-icon.svg',
route: '/settings/experimental#token-description', route: '/settings/experimental#token-description',
section: 'Use Token Detection', section: 'Use Token Detection',
@ -395,6 +427,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'MetaMask is designed and built around the world.', description: 'MetaMask is designed and built around the world.',
id: 35,
image: 'info-icon.svg', image: 'info-icon.svg',
route: '/settings/about-us#version', route: '/settings/about-us#version',
section: 'MetaMask Version', section: 'MetaMask Version',
@ -402,6 +435,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: '', description: '',
id: 36,
image: 'info-icon.svg', image: 'info-icon.svg',
route: '/settings/about-us#links', route: '/settings/about-us#links',
section: 'Links', section: 'Links',
@ -409,6 +443,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Privacy Policy', description: 'Privacy Policy',
id: 37,
image: 'info-icon.svg', image: 'info-icon.svg',
route: '/settings/about-us#privacy-policy', route: '/settings/about-us#privacy-policy',
section: 'Privacy Policy', section: 'Privacy Policy',
@ -416,6 +451,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Terms of Use', description: 'Terms of Use',
id: 38,
image: 'info-icon.svg', image: 'info-icon.svg',
route: '/settings/about-us#terms', route: '/settings/about-us#terms',
section: 'Terms of Use', section: 'Terms of Use',
@ -423,6 +459,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Attributions', description: 'Attributions',
id: 39,
image: 'info-icon.svg', image: 'info-icon.svg',
route: '/settings/about-us#attributions', route: '/settings/about-us#attributions',
section: 'Attributions', section: 'Attributions',
@ -430,6 +467,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Visit our Support Center', description: 'Visit our Support Center',
id: 40,
image: 'info-icon.svg', image: 'info-icon.svg',
route: '/settings/about-us#supportcenter', route: '/settings/about-us#supportcenter',
section: 'Visit our Support Center', section: 'Visit our Support Center',
@ -437,6 +475,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Visit our web site', description: 'Visit our web site',
id: 41,
image: 'info-icon.svg', image: 'info-icon.svg',
route: '/settings/about-us#visitwebsite', route: '/settings/about-us#visitwebsite',
section: 'Visit our web site', section: 'Visit our web site',
@ -444,6 +483,7 @@ describe('Settings Search Utils', () => {
}, },
{ {
description: 'Contact us', description: 'Contact us',
id: 42,
image: 'info-icon.svg', image: 'info-icon.svg',
route: '/settings/about-us#contactus', route: '/settings/about-us#contactus',
section: 'Contact us', section: 'Contact us',

View File

@ -7,26 +7,18 @@ import { I18nContext } from '../../../contexts/i18n';
export default function SettingsSearchList({ results, onClickSetting }) { export default function SettingsSearchList({ results, onClickSetting }) {
const t = useContext(I18nContext); const t = useContext(I18nContext);
useEffect(() => { useEffect(highlightSearchedText, [results]);
results.forEach((_, i) => {
highlightSearchedText(i);
});
}, [results]);
return ( return (
<div className="settings-page__header__search__list"> <div className="settings-page__header__search__list">
{Array(5) {results.slice(0, 5).map((result) => {
.fill(undefined) const { image, tab, section, id } = result;
.map((_, i) => {
const { image, tab, section } = results[i] || {};
return ( return (
Boolean(image || tab || section) && ( Boolean(image || tab || section) && (
<div key={`settings_${i}`}> <div key={`settings_${id}`}>
<div <div
key={`res_${i}`}
className="settings-page__header__search__list__item" className="settings-page__header__search__list__item"
onClick={() => onClickSetting(results[i])} onClick={() => onClickSetting(result)}
> >
<img <img
className="settings-page__header__search__list__item__icon" className="settings-page__header__search__list__item__icon"
@ -34,7 +26,7 @@ export default function SettingsSearchList({ results, onClickSetting }) {
/> />
<span <span
id={`menu-tab_${i}`} id={`menu-tab_${id}`}
className={classnames( className={classnames(
'settings-page__header__search__list__item__tab', 'settings-page__header__search__list__item__tab',
{ {
@ -47,13 +39,12 @@ export default function SettingsSearchList({ results, onClickSetting }) {
</span> </span>
<div className="settings-page__header__search__list__item__caret" /> <div className="settings-page__header__search__list__item__caret" />
<span <span
id={`menu-section_${i}`} id={`menu-section_${id}`}
className={classnames( className={classnames(
'settings-page__header__search__list__item__section', 'settings-page__header__search__list__item__section',
{ {
'settings-page__header__search__list__item__section-multiple-lines': 'settings-page__header__search__list__item__section-multiple-lines':
tab === t('securityAndPrivacy') || tab === t('securityAndPrivacy') || tab === t('alerts'),
tab === t('alerts'),
}, },
)} )}
> >

View File

@ -144,7 +144,7 @@ class SettingsPage extends PureComponent {
}} }}
settingsRoutesList={getSettingsRoutes(t)} settingsRoutesList={getSettingsRoutes(t)}
/> />
{isSearchList && searchText.length >= 2 && ( {isSearchList && searchText.length >= 3 && (
<SettingsSearchList <SettingsSearchList
key="" key=""
results={searchResults} results={searchResults}