Skip to content

Commit

Permalink
experiment with performance via createDeepEqualSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
bergeron committed Sep 12, 2024
1 parent 2d18c86 commit f57dc52
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
55 changes: 28 additions & 27 deletions ui/ducks/metamask/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion ui/ducks/send/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -3556,7 +3556,7 @@ export const getIsSwapAndSendDisabledForNetwork = createSelector(
);

export const getSendAnalyticProperties = createSelector(
getProviderConfig,
(state) => getProviderConfig(state),
getCurrentDraftTransaction,
getBestQuote,
({ chainId, ticker: nativeCurrencySymbol }, draftTransaction, bestQuote) => {
Expand Down

0 comments on commit f57dc52

Please sign in to comment.