Skip to content

Commit bb1349e

Browse files
mikespositomcmire
andauthored
feat: use defaultInfuraNetworks as default networks list (MetaMask#8767)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> Some new Infura network have been added to `InfuraNetworkType` (MetaMask#8680), but `NetworkController` uses the same list of networks to: - Build the default list of networks when creating the initial default state - Validate new Infura networks being enabled This has been fine until now because additional networks that can be enabled by users were added as "custom" networks. However, with the addition of new Infura networks, we have some networks that can be enabled by users but are not included in the default list of networks. This causes validation to fail when users try to enable those networks (via the Additional Networks list). ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes the set of networks that are auto-included on initialization, which is a breaking behavioral change that can affect users’ ability to switch to previously-default networks without first adding configurations. > > **Overview** > Introduces `DEFAULT_INFURA_NETWORKS` (a curated subset of `InfuraNetworkType`) in `@metamask/controller-utils` and exports it for consumers. > > Updates `NetworkController` to build its default `networkConfigurationsByChainId` from `DEFAULT_INFURA_NETWORKS` instead of `Object.values(InfuraNetworkType)`, effectively **removing Sei, MegaETH, Avalanche, and ZKSync from the default network set** while keeping them available as Infura-supported networks. > > Adjusts controller-utils export snapshots and network-controller tests/changelogs to reflect the new default-network behavior (**breaking**). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 0f8fa8c. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
1 parent e1f408e commit bb1349e

6 files changed

Lines changed: 61 additions & 388 deletions

File tree

packages/controller-utils/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `DEFAULT_INFURA_NETWORKS` with Infura network names to be enabled by default ([#8767](https://github.com/MetaMask/core/pull/8767))
13+
1014
## [12.0.0]
1115

1216
### Changed

packages/controller-utils/src/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ describe('@metamask/controller-utils', () => {
8181
"weiHexToGweiDec",
8282
"isEqualCaseInsensitive",
8383
"InfuraNetworkType",
84+
"DEFAULT_INFURA_NETWORKS",
8485
"CustomNetworkType",
8586
"NetworkType",
8687
"isNetworkType",

packages/controller-utils/src/types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ export const InfuraNetworkType = {
2323
export type InfuraNetworkType =
2424
(typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];
2525

26+
/**
27+
* The default set of Infura networks to include in the wallet.
28+
*
29+
* This is a subset of the full list of {@link InfuraNetworkType}, and can be used to determine
30+
* which Infura networks to enable by default.
31+
*/
32+
export const DEFAULT_INFURA_NETWORKS = [
33+
InfuraNetworkType.mainnet,
34+
InfuraNetworkType.goerli,
35+
InfuraNetworkType.sepolia,
36+
InfuraNetworkType['linea-goerli'],
37+
InfuraNetworkType['linea-sepolia'],
38+
InfuraNetworkType['linea-mainnet'],
39+
InfuraNetworkType['base-mainnet'],
40+
InfuraNetworkType['arbitrum-mainnet'],
41+
InfuraNetworkType['bsc-mainnet'],
42+
InfuraNetworkType['optimism-mainnet'],
43+
InfuraNetworkType['polygon-mainnet'],
44+
InfuraNetworkType['monad-mainnet'],
45+
] as const satisfies InfuraNetworkType[];
46+
2647
/**
2748
* Custom network types that are not part of Infura.
2849
*/

packages/network-controller/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

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

1217
### Added

packages/network-controller/src/NetworkController.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
NetworkNickname,
1717
BUILT_IN_CUSTOM_NETWORKS_RPC,
1818
BUILT_IN_NETWORKS,
19+
DEFAULT_INFURA_NETWORKS,
1920
} from '@metamask/controller-utils';
2021
import type { PollingBlockTrackerOptions } from '@metamask/eth-block-tracker';
2122
import EthQuery from '@metamask/eth-query';
@@ -807,37 +808,38 @@ function getDefaultInfuraNetworkConfigurationsByChainId(): Record<
807808
Hex,
808809
NetworkConfiguration
809810
> {
810-
return Object.values(InfuraNetworkType).reduce<
811-
Record<Hex, NetworkConfiguration>
812-
>((obj, infuraNetworkType) => {
813-
const chainId = ChainId[infuraNetworkType];
811+
return DEFAULT_INFURA_NETWORKS.reduce<Record<Hex, NetworkConfiguration>>(
812+
(obj, infuraNetworkType) => {
813+
const chainId = ChainId[infuraNetworkType];
814814

815-
// Skip deprecated network as default network.
816-
if (DEPRECATED_NETWORKS.has(chainId)) {
817-
return obj;
818-
}
819-
820-
const rpcEndpointUrl =
821-
`https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}` as const;
815+
// Skip deprecated network as default network.
816+
if (DEPRECATED_NETWORKS.has(chainId)) {
817+
return obj;
818+
}
822819

823-
const networkConfiguration: NetworkConfiguration = {
824-
blockExplorerUrls: [],
825-
chainId,
826-
defaultRpcEndpointIndex: 0,
827-
name: NetworkNickname[infuraNetworkType],
828-
nativeCurrency: NetworksTicker[infuraNetworkType],
829-
rpcEndpoints: [
830-
{
831-
failoverUrls: [],
832-
networkClientId: infuraNetworkType,
833-
type: RpcEndpointType.Infura,
834-
url: rpcEndpointUrl,
835-
},
836-
],
837-
};
820+
const rpcEndpointUrl =
821+
`https://${infuraNetworkType}.infura.io/v3/{infuraProjectId}` as const;
822+
823+
const networkConfiguration: NetworkConfiguration = {
824+
blockExplorerUrls: [],
825+
chainId,
826+
defaultRpcEndpointIndex: 0,
827+
name: NetworkNickname[infuraNetworkType],
828+
nativeCurrency: NetworksTicker[infuraNetworkType],
829+
rpcEndpoints: [
830+
{
831+
failoverUrls: [],
832+
networkClientId: infuraNetworkType,
833+
type: RpcEndpointType.Infura,
834+
url: rpcEndpointUrl,
835+
},
836+
],
837+
};
838838

839-
return { ...obj, [chainId]: networkConfiguration };
840-
}, {});
839+
return { ...obj, [chainId]: networkConfiguration };
840+
},
841+
{},
842+
);
841843
}
842844

843845
/**

0 commit comments

Comments
 (0)