Skip to content
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

feat: Add MultichainNetworkController to handle both EVM and non-EVM network and account switching #5215

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

Conversation

Cal-L
Copy link
Contributor

@Cal-L Cal-L commented Jan 30, 2025

Explanation

This PR updates both the MultichainNetworkController and AccountsController to handle network switching as well as account switching. The logic handles the following logic:

  • Switching accounts on AccountsController will notify MultichainNetworkController to update if the account belongs to evm vs non-evm network (MultichainNetworkController subscribes to AccountsController event)
  • Switching between networks on MultichainNetworkController will notify AccountsController to update accounts based on which network the account belongs to (AccountsController subscribes to MultichainNetworkController event)

References

Fixes https://github.com/MetaMask/accounts-planning/issues/804

Changelog

@metamask/accounts-controller

  • BREAKING:
    • Added MultichainNetworkSetActiveNetworkEvent to allowed events. This is used to subscribe to the setActiveNetwork event from the MultichainNetworkController and is responsible for updating selected account based on network changes (both EVM and non-EVM).

@metamask/multichain-network-controller

  • ADDED:
    • Allowed actions - NetworkControllerGetStateAction | NetworkControllerSetActiveNetworkAction. The MultichainNetworkController acts as a proxy for the NetworkController and will update it based on EVM network changes.
    • Allowed events - AccountsControllerSelectedAccountChangeEvent to allowed events. This is used to subscribe to the selectedAccountChange event from the AccountsController and is responsible for updating active network based on account changes (both EVM and non-EVM).

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 highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@Cal-L Cal-L requested a review from a team as a code owner January 30, 2025 06:01
@tommasini
Copy link
Contributor

This looks amazing! Lets align today with the review made on the PR #5209

@Cal-L Cal-L marked this pull request as draft February 3, 2025 18:29
@Cal-L Cal-L changed the title feat: Feat/handle multichain network and account switching feat: Add MultichainNetworkController to handle both EVM and non-EVM network and account switching Feb 4, 2025
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.

Hello! I left some comments. I'm still trying to understand the changes introduced here. I know more changes are coming, but I am still curious why some things are being introduced here without being explicitly used, when they could be introduced later. Other than that I had some improvements we could make to the types, and some naming adjustments.

@mcmire
Copy link
Contributor

mcmire commented Feb 6, 2025

@Cal-L Can you run yarn update-readme-content when you get a chance? This should add the controller to the README and update the graph there.

@Cal-L Cal-L requested a review from a team as a code owner February 12, 2025 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs dev review
Development

Successfully merging this pull request may close these issues.

4 participants