Skip to content

chore: upgrade multichain-networks-controllers-v0.5.1 #31414

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

Merged
merged 41 commits into from
Apr 23, 2025

Conversation

vinnyhoward
Copy link
Contributor

@vinnyhoward vinnyhoward commented Mar 28, 2025

Description

upgrade multichain networks controllers to 0.5.1
core: MetaMask/core#5551

This PR updates the multichain network controller to implement the new getNetworksWithActivityByAccounts method from our core library and adds the necessary state management. The changes include:

  1. Added networksWithActivityByAccounts to the MultichainNetworkControllerState
  2. Updated test stubs and mocks to include the new state property
  3. Fixed type definitions and linting errors related to the networks by activity state changes
  4. Added method binding in MetaMask controller for the new functionality

Open in GitHub Codespaces

Related issues

Related to #4469

Manual testing steps

  1. Launch app, observe everything works as usual
  2. If you want to see the state changes, goto ui/components/multichain/account-list-menu/account-list-menu.tsx
  3. import
import { getNetworksWithActivity } from '../../../selectors/multichain/networks';
  1. Declare
  const networksWithActivity = useSelector(getNetworksWithActivity);
  console.log(networksWithActivity);
  1. Observe the networks with transaction activity shows

Screenshots/Recordings

Screenshot 2025-04-01 at 12 05 34 PM

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

…yAccounts. The method handles it internally now
@vinnyhoward vinnyhoward marked this pull request as ready for review March 31, 2025 18:37
@vinnyhoward vinnyhoward requested a review from a team as a code owner April 1, 2025 18:16
@metamaskbot
Copy link
Collaborator

metamaskbot commented Apr 1, 2025

✨ Files requiring CODEOWNER review ✨

🧩 @MetaMask/extension-devs

  • lavamoat/browserify/beta/policy.json
  • lavamoat/browserify/flask/policy.json
  • lavamoat/browserify/main/policy.json
  • lavamoat/browserify/mmi/policy.json

📜 @MetaMask/policy-reviewers

  • lavamoat/browserify/beta/policy.json
  • lavamoat/browserify/flask/policy.json
  • lavamoat/browserify/main/policy.json
  • lavamoat/browserify/mmi/policy.json

🔗 @MetaMask/supply-chain

  • lavamoat/browserify/beta/policy.json
  • lavamoat/browserify/flask/policy.json
  • lavamoat/browserify/main/policy.json
  • lavamoat/browserify/mmi/policy.json

🖥️ @MetaMask/wallet-ux

  • ui/components/multichain/account-list-menu/account-list-menu.tsx

vinnyhoward added a commit to MetaMask/core that referenced this pull request Apr 16, 2025
## Explanation

Currently, our client manually adds networks and checks user activity
one network at a time. This is inefficient and doesn't scale well.

This PR introduces a more efficient approach by:
1. Adding a new API integration that fetches active networks for
multiple accounts in a single request
2. Managing network activity state through the controller
3. Adding type-safe methods to handle both EVM and non-EVM accounts
4. Extracting network fetching logic into a dedicated service layer

Key additions:
- `getNetworksWithTransactionActivityByAccounts`: Fetches active
networks for accounts
- `MultichainNetworkService`: New service layer handling network
activity fetching
- Enhanced state management for network configurations and activity
- Improved error handling and fallback mechanisms

The new implementation:
- Reduces API calls through batch fetching
- Improves separation of concerns with dedicated service layer
- Enhances type safety and error handling
- Provides better state management with fallbacks

PRs for Client Integration
[Extension](MetaMask/metamask-extension#31414)
[Mobile](MetaMask/metamask-mobile#14348)

## References

Related to [#4469
](MetaMask/MetaMask-planning#4469)

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/multichain-network-controller`

- **ADDED**: New method `getNetworksWithTransactionActivityByAccounts`
to fetch active networks for accounts
- **ADDED**: New `MultichainNetworkServiceController` for handling
network activity fetching
- **ADDED**: New types for network activity state and responses

- **CHANGED**: Enhanced error handling for network requests
- **CHANGED**: Improved type safety for messenger actions
- **CHANGED**: Updated state management for network activity

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes

---------

Co-authored-by: Charly Chevalier <[email protected]>
@metamaskbot
Copy link
Collaborator

Builds ready [7e2baa5]
UI Startup Metrics (1212 ± 57 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1212109313955712451309
load104493912185310721139
domContentLoaded103993312115310661134
domInteractive17146761729
firstPaint66081115642010581123
backgroundConnect649179
firstReactRender21164262237
getState1454992029
initialActions001001
loadScripts80070196953826889
setupStore84303812
WebpackHomeuiStartup20681703257117321662311
load15901313195812716781771
domContentLoaded15831309193512516731765
domInteractive151160101240
firstPaint1779237657196304
backgroundConnect23977132357
firstReactRender20755379118340359
getState124214211223
initialActions317135
loadScripts15781308191112416701763
setupStore1574061726
FirefoxBrowserifyHomeuiStartup13651185171910214171592
load12131049151310212711437
domContentLoaded12131049151310212711437
domInteractive1043823534122175
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect20136662030
firstReactRender24206052529
getState7438489
initialActions001001
loadScripts11941035150010312501422
setupStore741711768
WebpackHomeuiStartup1478133917479115391650
load1262113715198313211413
domContentLoaded1261113515188313201413
domInteractive78391642086126
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect22144962234
firstReactRender34285343643
getState94516913
initialActions001011
loadScripts1242112415008313021398
setupStore85546816
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 985 Bytes (0.02%)
  • ui: 228 Bytes (0%)
  • common: 5.93 KiB (0.06%)

@metamaskbot
Copy link
Collaborator

Builds ready [890ab5a]
UI Startup Metrics (1183 ± 52 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1183109813305212121281
load102191411464610531100
domContentLoaded101590811384610471095
domInteractive181365101738
firstPaint723133114439710361085
backgroundConnect73293714
firstReactRender20156671932
getState1353272028
initialActions001001
loadScripts77966488046812857
setupStore74182811
WebpackHomeuiStartup21451780238114522472359
load16601380214112217531846
domContentLoaded16531376213612217491837
domInteractive171188131351
firstPaint1967062386253338
backgroundConnect251071133055
firstReactRender22855398118339359
getState1132961424
initialActions316135
loadScripts16491375213312217471835
setupStore217285322037
FirefoxBrowserifyHomeuiStartup13371139166511114091552
load11931019153811712711427
domContentLoaded11931018153811712711427
domInteractive993618026116146
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect191394101936
firstReactRender23195072248
getState6419279
initialActions001001
loadScripts11761004152411612551397
setupStore8415515618
WebpackHomeuiStartup15111326218514115841784
load12951139190012413621535
domContentLoaded12941137190012413621535
domInteractive81372532790140
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect221484102346
firstReactRender35294443741
getState84314914
initialActions102111
loadScripts12751124182612113451515
setupStore95598828
Benchmark value 338 exceeds gate value 334 for chrome webpack home p95 firstPaint
Sum of mean exceeds: 0ms | Sum of p95 exceeds: 4ms
Sum of all benchmark exceeds: 4ms

Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 985 Bytes (0.02%)
  • ui: 228 Bytes (0%)
  • common: 5.93 KiB (0.06%)

@vinnyhoward vinnyhoward changed the title feat(4469): networks with activity integration chore: upgrade multichain-networks-controllers-v0.5.1 Apr 21, 2025
@davidmurdoch davidmurdoch self-requested a review April 22, 2025 14:45
@vinnyhoward vinnyhoward added this pull request to the merge queue Apr 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 23, 2025
@vinnyhoward vinnyhoward added this pull request to the merge queue Apr 23, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 23, 2025
salimtb pushed a commit to MetaMask/core that referenced this pull request Apr 23, 2025
## Explanation

Currently, our client manually adds networks and checks user activity
one network at a time. This is inefficient and doesn't scale well.

This PR introduces a more efficient approach by:
1. Adding a new API integration that fetches active networks for
multiple accounts in a single request
2. Managing network activity state through the controller
3. Adding type-safe methods to handle both EVM and non-EVM accounts
4. Extracting network fetching logic into a dedicated service layer

Key additions:
- `getNetworksWithTransactionActivityByAccounts`: Fetches active
networks for accounts
- `MultichainNetworkService`: New service layer handling network
activity fetching
- Enhanced state management for network configurations and activity
- Improved error handling and fallback mechanisms

The new implementation:
- Reduces API calls through batch fetching
- Improves separation of concerns with dedicated service layer
- Enhances type safety and error handling
- Provides better state management with fallbacks

PRs for Client Integration
[Extension](MetaMask/metamask-extension#31414)
[Mobile](MetaMask/metamask-mobile#14348)

## References

Related to [#4469
](MetaMask/MetaMask-planning#4469)

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/multichain-network-controller`

- **ADDED**: New method `getNetworksWithTransactionActivityByAccounts`
to fetch active networks for accounts
- **ADDED**: New `MultichainNetworkServiceController` for handling
network activity fetching
- **ADDED**: New types for network activity state and responses

- **CHANGED**: Enhanced error handling for network requests
- **CHANGED**: Improved type safety for messenger actions
- **CHANGED**: Updated state management for network activity

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes

---------

Co-authored-by: Charly Chevalier <[email protected]>
@metamaskbot
Copy link
Collaborator

Builds ready [f68a82e]
UI Startup Metrics (1225 ± 62 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1225110614376212541376
load105292512105910911161
domContentLoaded104791912005810821152
domInteractive18146681729
firstPaint672146121442010661116
backgroundConnect74192812
firstReactRender2516130152550
getState1464181828
initialActions005101
loadScripts80768396356841916
setupStore95233917
WebpackHomeuiStartup21351712257618422562455
load16581345227416717531956
domContentLoaded16511341227116717471952
domInteractive151182101342
firstPaint1936864982238316
backgroundConnect251072133058
firstReactRender21155381124342362
getState174256341533
initialActions317135
loadScripts16461340226716517461941
setupStore177176171933
FirefoxBrowserifyHomeuiStartup13921216192511714431601
load12391032175411713081471
domContentLoaded12391032175411713081471
domInteractive1053723529114155
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect221393102347
firstReactRender24195662432
getState84434811
initialActions001001
loadScripts12201018173511812901459
setupStore64445610
WebpackHomeuiStartup15091342222214915681828
load12891151196813713211524
domContentLoaded12881151196813713201524
domInteractive81391822290126
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect2415104132445
firstReactRender35284743743
getState12427927931
initialActions002111
loadScripts12671129194613613021503
setupStore85212811
Benchmark value 25 exceeds gate value 23 for chrome browserify home mean firstReactRender
Benchmark value 1377 exceeds gate value 1365 for chrome browserify home p95 uiStartup
Benchmark value 50 exceeds gate value 45 for chrome browserify home p95 firstReactRender
Benchmark value 2455 exceeds gate value 2454 for chrome webpack home p95 uiStartup
Benchmark value 1240 exceeds gate value 1239 for firefox browserify home mean domContentLoaded
Sum of mean exceeds: 3ms | Sum of p95 exceeds: 18ms
Sum of all benchmark exceeds: 21ms

Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 985 Bytes (0.02%)
  • ui: 224 Bytes (0%)
  • common: 5.93 KiB (0.06%)

@vinnyhoward vinnyhoward added this pull request to the merge queue Apr 23, 2025
github-merge-queue bot pushed a commit that referenced this pull request Apr 23, 2025
## **Description**

upgrade multichain networks controllers to 0.5.1
core: MetaMask/core#5551

This PR updates the multichain network controller to implement the new
`getNetworksWithActivityByAccounts` method from our core library and
adds the necessary state management. The changes include:

1. Added `networksWithActivityByAccounts` to the
MultichainNetworkControllerState
2. Updated test stubs and mocks to include the new state property
3. Fixed type definitions and linting errors related to the networks by
activity state changes
4. Added method binding in MetaMask controller for the new functionality

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/31414?quickstart=1)

## **Related issues**

Related to [#4469
](MetaMask/MetaMask-planning#4469)

## **Manual testing steps**

1. Launch app, observe everything works as usual
2. If you want to see the state changes, goto
`ui/components/multichain/account-list-menu/account-list-menu.tsx`
3. import 
```typescript
import { getNetworksWithActivity } from '../../../selectors/multichain/networks';
```
4. Declare 
```typescript
  const networksWithActivity = useSelector(getNetworksWithActivity);
  console.log(networksWithActivity);
  ```
5. Observe the networks with transaction activity shows

## **Screenshots/Recordings**

<img width="1840" alt="Screenshot 2025-04-01 at 12 05 34 PM" src="https://github.com/user-attachments/assets/9f019f6c-90ed-4134-be92-aef65b51e096" />

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable
- [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors.

## **Pre-merge reviewer checklist**

- [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
- [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
Merged via the queue into main with commit 9404b57 Apr 23, 2025
169 checks passed
@vinnyhoward vinnyhoward deleted the feat-4469-networks-with-activity branch April 23, 2025 20:12
@github-actions github-actions bot locked and limited conversation to collaborators Apr 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants