Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: update network controller
  • Loading branch information
stanleyyconsensys committed Dec 8, 2025
commit db01d69a655ed8bd1a5efad73405ed774189beb3
13 changes: 13 additions & 0 deletions packages/network-controller/src/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { v4 as uuidV4 } from 'uuid';
import {
DEPRECATED_NETWORKS,
INFURA_BLOCKED_KEY,
FALLBACK_INFURA_NETWORK_TYPE_MAPPING,
NetworkStatus,
} from './constants';
import type {
Expand Down Expand Up @@ -1118,6 +1119,18 @@ function deriveInfuraNetworkNameFromRpcEndpointUrl(
return match.groups.networkName;
}

// Infura URL can be inserted by user manually,
// in case the network name extra from URL is not mapped to InfuraNetworkType,
// we should add a fallback mapping here.
if (
hasProperty(
FALLBACK_INFURA_NETWORK_TYPE_MAPPING,
match.groups.networkName,
)
) {
return FALLBACK_INFURA_NETWORK_TYPE_MAPPING[match.groups.networkName];
}

throw new Error(`Unknown Infura network '${match.groups.networkName}'`);
}

Expand Down
12 changes: 12 additions & 0 deletions packages/network-controller/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { InfuraNetworkType } from "@metamask/controller-utils";

Check failure on line 1 in packages/network-controller/src/constants.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Replace `"@metamask/controller-utils"` with `'@metamask/controller-utils'`

/**
* Represents the availability status of an RPC endpoint. (Regrettably, the
* name of this type is a misnomer.)
Expand Down Expand Up @@ -41,3 +43,13 @@
* without the need to remove the network from constant list of controller-utils.
*/
export const DEPRECATED_NETWORKS = new Set<string>(['0xe704', '0x5']);

/**
* A mapping of network keys to their corresponding InfuraNetworkType keys.
* This is used to map the network keys to the InfuraNetworkType keys.
* For example, `monad-testnet` is mapped to `monad-testnet-infura`.
* This is used to map the network keys to the InfuraNetworkType keys.
*/
export const FALLBACK_INFURA_NETWORK_TYPE_MAPPING: Record<string, InfuraNetworkType> = {

Check failure on line 53 in packages/network-controller/src/constants.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Replace `string,·InfuraNetworkType` with `⏎··string,⏎··InfuraNetworkType⏎`
'monad-testnet': 'monad-testnet-infura',
}

Check failure on line 55 in packages/network-controller/src/constants.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (22.x)

Insert `;`
Loading