Skip to content

chore: create network order controller #6022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

salimtb
Copy link
Contributor

@salimtb salimtb commented Jun 23, 2025

Explanation

The NetworkOrderController is a core implementation of network ordering functionality that was previously only available in the extension. This PR moves and expands this functionality from the extension's NetworkOrder controller to core, enabling network ordering features across both extension and mobile platforms. It also renames it to NetworkOrderController to more accurately represent what it does. Maybe in the future this can be expanded to include other UX enhancements that don't need to be tightly coupled with the NetworkController

Key motivations for this change:

  1. Platform Parity: Network ordering was previously only implemented in the extension via NetworkOrder controller, leaving mobile without this functionality. Moving this to core will unlock the ability to have this feature built on mobile.

  2. Code Quality Improvements: The move to core has provided an opportunity to:

    • Improve test coverage of the existing network ordering logic

The controller now handles three key aspects:

  • Network ordering (preserved from extension implementation)

References

  • Moves functionality from NetworkOrder controller in extension to core
  • Related to ongoing work related to Global Network Selector Removal

Changelog

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, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@salimtb salimtb force-pushed the chore/create-network-order-controller branch from 0f98de3 to 66114bc Compare June 24, 2025 11:26
@salimtb salimtb force-pushed the chore/create-network-order-controller branch from 445dd16 to d2a8ef8 Compare June 24, 2025 12:36
@salimtb salimtb marked this pull request as ready for review June 24, 2025 12:59
@salimtb salimtb requested a review from a team as a code owner June 24, 2025 12:59
Comment on lines +26 to +29

// Currently the tests for NetworkController have a race condition which
// causes intermittent failures. This seems to fix it.
testEnvironment: 'jsdom',
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: do you think we can drop this as may not be related to this controller ?

@@ -0,0 +1,15 @@
# `@metamask/network-order-controller`

Provides an interface to the currently network order via a MetaMask-compatible provider object
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: what do you think about rephrasing this to ?

Suggested change
Provides an interface to the currently network order via a MetaMask-compatible provider object
Provides an interface to the current network display order via a MetaMask-compatible provider object

{
"name": "@metamask/network-order-controller",
"version": "0.0.0",
"description": "Provides an interface to the currently network order via a MetaMask-compatible provider object",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: to align with README, if you opt in for the suggestion

Suggested change
"description": "Provides an interface to the currently network order via a MetaMask-compatible provider object",
"description": "Provides an interface to the current network display order via a MetaMask-compatible provider object",

Comment on lines +30 to +33
export type NetworkOrderStateChange = {
type: `${typeof controllerName}:stateChange`;
payload: [NetworkOrderControllerState, Patch[]];
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export type NetworkOrderStateChange = {
type: `${typeof controllerName}:stateChange`;
payload: [NetworkOrderControllerState, Patch[]];
};
export type NetworkOrderStateControllerChangeEvent = ControllerStateChangeEvent<
typeof controllerName,
NetworkOrderControllerState
>;
export type NetworkOrderControllerEvents = NetworkOrderStateControllerChangeEvent;
/**
* All events that {@link NetworkOrderController} calls internally.
*/
type AllowedEvents = NetworkControllerStateChangeEvent;

};

// Describes the action for updating the networks list
export type NetworkOrderControllerupdateNetworksListAction = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export type NetworkOrderControllerupdateNetworksListAction = {
export type NetworkOrderControllerUpdateNetworksListAction = {

* @param networkControllerState - The state of the network controller.
* @param networkControllerState.networkConfigurationsByChainId - The network configurations by chain id.
*/
onNetworkControllerStateChange({
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this method can be private ?

Suggested change
onNetworkControllerStateChange({
#onNetworkControllerStateChange({

Copy link
Contributor

Choose a reason for hiding this comment

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

can we move this file under src directory ?

Comment on lines +8 to +18
"references": [
{
"path": "../../packages/base-controller/tsconfig.build.json"
},
{
"path": "../../packages/network-controller/tsconfig.build.json"
},
{
"path": "../../packages/multichain-network-controller/tsconfig.build.json"
}
],
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"references": [
{
"path": "../../packages/base-controller/tsconfig.build.json"
},
{
"path": "../../packages/network-controller/tsconfig.build.json"
},
{
"path": "../../packages/multichain-network-controller/tsconfig.build.json"
}
],
"references": [
{ "path": "../base-controller/tsconfig.build.json" },
{ "path": "../network-controller/tsconfig.build.json" },
{ "path": "../multichain-network-controller/tsconfig.build.json" }
],

Comment on lines +7 to +17
"references": [
{
"path": "../../packages/base-controller"
},
{
"path": "../../packages/network-controller"
},
{
"path": "../../packages/multichain-network-controller"
}
],
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"references": [
{
"path": "../../packages/base-controller"
},
{
"path": "../../packages/network-controller"
},
{
"path": "../../packages/multichain-network-controller"
}
],
"references": [
{ "path": "../base-controller" },
{ "path": "../network-controller" },
{ "path": "../multichain-network-controller" }
],

"path": "../../packages/multichain-network-controller"
}
],
"include": ["../../types", "./src", "tests/NetworkOrderController.test.ts"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: if you opt in for the suggestion to move NetworkOrderController.test.ts to test folder this can be dropped

Suggested change
"include": ["../../types", "./src", "tests/NetworkOrderController.test.ts"]
"include": ["../../types", "./src"]

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Looks good! As for the suggestions by @cryptodev-2s, I think they make sense, except perhaps we want to keep NetworkOrderController.ts as-is? We can consider aligning this controller with other controllers in another PR.

Comment on lines +4 to +8
'0xaa36a7',
'0xe705',
'0x539',
'0x18c6',
'0x279f',
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add comments to document what these are?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this file be called constants.ts?

"@metamask/keyring-api": "^18.0.0",
"@metamask/multichain-network-controller": "^0.9.0",
"@metamask/utils": "^11.2.0",
"@metamask/network-controller": "^24.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this controller talks to NetworkController, should this be a peer dependency instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you re-run yarn update-readme-content? It looks like some dependencies are not reflected here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants