Skip to content

Commit

Permalink
gist based changes for getProviderConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
NidhiKJha committed Jan 8, 2025
1 parent 2760f5a commit 516919e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
56 changes: 35 additions & 21 deletions ui/ducks/metamask/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import * as actionConstants from '../../store/actionConstants';
import { updateTransactionGasFees } from '../../store/actions';
import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck';
import { ORIGIN_METAMASK } from '../../../shared/constants/app';

const initialState = {
isInitialized: false,
Expand Down Expand Up @@ -279,36 +280,49 @@ export const getAlertEnabledness = (state) => state.metamask.alertEnabledness;
* @param {object} state - Redux state object.
*/
export const getProviderConfig = createSelector(
(state) => getNetworkConfigurationsByChainId(state),
(state) => getSelectedNetworkClientId(state),
(networkConfigurationsByChainId, selectedNetworkClientId) => {
(state) => ({
networkConfigurationsByChainId: getNetworkConfigurationsByChainId(state),
selectedNetworkClientId: getSelectedNetworkClientId(state),
metamask: state.metamask,
activeTabOrigin: state.activeTab?.origin || ORIGIN_METAMASK,
}),
({
networkConfigurationsByChainId,
selectedNetworkClientId,
metamask,
activeTabOrigin,
}) => {
const networkClientId = metamask.domains[activeTabOrigin];

const networkClientIdToUse = networkClientId || 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,
}),
};
if (rpcEndpoint.networkClientId === networkClientIdToUse) {
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,
}),
};
}
}
}
return undefined; // should not be reachable
},
);


export const getUnconnectedAccountAlertEnabledness = (state) =>
getAlertEnabledness(state)[AlertTypes.unconnectedAccount];

Expand Down
4 changes: 2 additions & 2 deletions ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async function startApp(metamaskState, backgroundConnection, opts) {

async function runInitialActions(store) {
const state = store.getState();

/*
// This block autoswitches chains based on the last chain used
// for a given dapp, when there are no pending confimrations
// This allows the user to be connected on one chain
Expand All @@ -240,7 +240,7 @@ async function runInitialActions(store) {
// if the user didn't just change the dapp network
await store.dispatch(actions.clearSwitchedNetworkDetails());
}

*/
// Register this window as the current popup
// and set in background state
if (
Expand Down
4 changes: 2 additions & 2 deletions ui/pages/routes/routes.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export default class Routes extends Component {
if (prevProps.account?.address !== account?.address) {
this.setState({ hideConnectAccountToast: false });
}

/*
// Automatically switch the network if the user
// no longer has unapproved transactions and they
// should be on a different network for the
Expand All @@ -289,7 +289,7 @@ export default class Routes extends Component {
activeTabOrigin,
);
}

*/
// Terminate the popup when another popup is opened
// if the user is using RPC queueing
if (
Expand Down

0 comments on commit 516919e

Please sign in to comment.