Skip to content
Merged
4 changes: 4 additions & 0 deletions packages/controller-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `DEFAULT_INFURA_NETWORKS` with Infura network names to be enabled by default ([#8767](https://github.com/MetaMask/core/pull/8767))

## [12.0.0]

### Changed
Expand Down
1 change: 1 addition & 0 deletions packages/controller-utils/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('@metamask/controller-utils', () => {
"weiHexToGweiDec",
"isEqualCaseInsensitive",
"InfuraNetworkType",
"DEFAULT_INFURA_NETWORKS",
"CustomNetworkType",
"NetworkType",
"isNetworkType",
Expand Down
21 changes: 21 additions & 0 deletions packages/controller-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ export const InfuraNetworkType = {
export type InfuraNetworkType =
(typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];

/**
* The default set of Infura networks to include in the wallet.
*
* This is a subset of the full list of {@link InfuraNetworkType}, and can be used to determine
* which Infura networks to enable by default.
*/
export const DEFAULT_INFURA_NETWORKS = [
InfuraNetworkType.mainnet,
InfuraNetworkType.goerli,
InfuraNetworkType.sepolia,
InfuraNetworkType['linea-goerli'],
InfuraNetworkType['linea-sepolia'],
InfuraNetworkType['linea-mainnet'],
InfuraNetworkType['base-mainnet'],
InfuraNetworkType['arbitrum-mainnet'],
InfuraNetworkType['bsc-mainnet'],
InfuraNetworkType['optimism-mainnet'],
InfuraNetworkType['polygon-mainnet'],
InfuraNetworkType['monad-mainnet'],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m leaving Monad here intentionally as requested by the Money team

cc @Matt561

] as const satisfies InfuraNetworkType[];

/**
* Custom network types that are not part of Infura.
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/network-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- **BREAKING:** Remove Sei, MegaETH, Avalanche, and ZKSync from list of default networks ([#8767](https://github.com/MetaMask/core/pull/8767))
- You will need to add them as network configurations first before switching to them.

## [31.1.0]

### Added
Expand Down
58 changes: 30 additions & 28 deletions packages/network-controller/src/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
NetworkNickname,
BUILT_IN_CUSTOM_NETWORKS_RPC,
BUILT_IN_NETWORKS,
DEFAULT_INFURA_NETWORKS,
} from '@metamask/controller-utils';
import type { PollingBlockTrackerOptions } from '@metamask/eth-block-tracker';
import EthQuery from '@metamask/eth-query';
Expand Down Expand Up @@ -807,37 +808,38 @@ function getDefaultInfuraNetworkConfigurationsByChainId(): Record<
Hex,
NetworkConfiguration
> {
return Object.values(InfuraNetworkType).reduce<
Record<Hex, NetworkConfiguration>
>((obj, infuraNetworkType) => {
const chainId = ChainId[infuraNetworkType];
return DEFAULT_INFURA_NETWORKS.reduce<Record<Hex, NetworkConfiguration>>(
(obj, infuraNetworkType) => {
const chainId = ChainId[infuraNetworkType];

// Skip deprecated network as default network.
if (DEPRECATED_NETWORKS.has(chainId)) {
return obj;
}

const rpcEndpointUrl =
`https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}` as const;
// Skip deprecated network as default network.
if (DEPRECATED_NETWORKS.has(chainId)) {
return obj;
}

const networkConfiguration: NetworkConfiguration = {
blockExplorerUrls: [],
chainId,
defaultRpcEndpointIndex: 0,
name: NetworkNickname[infuraNetworkType],
nativeCurrency: NetworksTicker[infuraNetworkType],
rpcEndpoints: [
{
failoverUrls: [],
networkClientId: infuraNetworkType,
type: RpcEndpointType.Infura,
url: rpcEndpointUrl,
},
],
};
const rpcEndpointUrl =
`https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}` as const;

const networkConfiguration: NetworkConfiguration = {
blockExplorerUrls: [],
chainId,
defaultRpcEndpointIndex: 0,
name: NetworkNickname[infuraNetworkType],
nativeCurrency: NetworksTicker[infuraNetworkType],
rpcEndpoints: [
{
failoverUrls: [],
networkClientId: infuraNetworkType,
type: RpcEndpointType.Infura,
url: rpcEndpointUrl,
},
],
};

return { ...obj, [chainId]: networkConfiguration };
}, {});
return { ...obj, [chainId]: networkConfiguration };
},
{},
);
}

/**
Expand Down
Loading
Loading