From f57dc5268300e4acd1baed0c714efc547dfb3d63 Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Thu, 12 Sep 2024 16:11:47 -0700 Subject: [PATCH] experiment with performance via `createDeepEqualSelector` --- ui/ducks/metamask/metamask.js | 55 ++++++++++++++++++----------------- ui/ducks/send/send.js | 2 +- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/ui/ducks/metamask/metamask.js b/ui/ducks/metamask/metamask.js index 40291858214a..811c110ff8d9 100644 --- a/ui/ducks/metamask/metamask.js +++ b/ui/ducks/metamask/metamask.js @@ -24,6 +24,7 @@ import { import * as actionConstants from '../../store/actionConstants'; import { updateTransactionGasFees } from '../../store/actions'; import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck'; +import { createDeepEqualSelector } from '../../selectors/util'; const initialState = { isInitialized: false, @@ -280,35 +281,35 @@ export const getAlertEnabledness = (state) => state.metamask.alertEnabledness; * * @param {object} state - Redux state object. */ -export function getProviderConfig(state) { - const selectedNetworkClientId = getSelectedNetworkClientId(state); - const networkConfigurationsByChainId = - getNetworkConfigurationsByChainId(state); - - for (const network of Object.values(networkConfigurationsByChainId)) { - for (const rpcEndpoint of network.rpcEndpoints) { - if (rpcEndpoint.networkClientId === selectedNetworkClientId) { - const blockExplorerUrl = - network.blockExplorerUrls?.[network.defaultBlockExplorerUrlIndex]; - - return { - chainId: network.chainId, - ticker: network.nativeCurrency, - rpcPrefs: { ...(blockExplorerUrl && { blockExplorerUrl }) }, - type: - rpcEndpoint.type === RpcEndpointType.Custom - ? 'rpc' - : rpcEndpoint.networkClientId, - ...(rpcEndpoint.type === RpcEndpointType.Custom && { - id: rpcEndpoint.networkClientId, - nickname: network.name, - rpcUrl: rpcEndpoint.url, - }), - }; +export const getProviderConfig = createDeepEqualSelector( + (state) => getNetworkConfigurationsByChainId(state), + (state) => getSelectedNetworkClientId(state), + (networkConfigurationsByChainId, selectedNetworkClientId) => { + for (const network of Object.values(networkConfigurationsByChainId)) { + for (const rpcEndpoint of network.rpcEndpoints) { + if (rpcEndpoint.networkClientId === selectedNetworkClientId) { + const blockExplorerUrl = + network.blockExplorerUrls?.[network.defaultBlockExplorerUrlIndex]; + + return { + chainId: network.chainId, + ticker: network.nativeCurrency, + rpcPrefs: { ...(blockExplorerUrl && { blockExplorerUrl }) }, + type: + rpcEndpoint.type === RpcEndpointType.Custom + ? 'rpc' + : rpcEndpoint.networkClientId, + ...(rpcEndpoint.type === RpcEndpointType.Custom && { + id: rpcEndpoint.networkClientId, + nickname: network.name, + rpcUrl: rpcEndpoint.url, + }), + }; + } } } - } -} + }, +); export const getUnconnectedAccountAlertEnabledness = (state) => getAlertEnabledness(state)[AlertTypes.unconnectedAccount]; diff --git a/ui/ducks/send/send.js b/ui/ducks/send/send.js index 92eb9fb507b9..35b424e17d88 100644 --- a/ui/ducks/send/send.js +++ b/ui/ducks/send/send.js @@ -3556,7 +3556,7 @@ export const getIsSwapAndSendDisabledForNetwork = createSelector( ); export const getSendAnalyticProperties = createSelector( - getProviderConfig, + (state) => getProviderConfig(state), getCurrentDraftTransaction, getBestQuote, ({ chainId, ticker: nativeCurrencySymbol }, draftTransaction, bestQuote) => {