-
-
Notifications
You must be signed in to change notification settings - Fork 220
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: fetch networks with transaction activity by accounts #5551
base: main
Are you sure you want to change the base?
Conversation
… controller, renamed variables/keys to be more descriptive
d7c63ef
to
a038b1f
Compare
Add CAIP-10 account formatting and network activity fetching with full test coverage. Includes error handling and future-proofing for BTC/Solana support.
@metamask-bot @metamaskbot publish-preview |
can you pls fix the broken unit test |
packages/multichain-network-controller/src/MultichainNetworkController.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/MultichainNetworkController.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/MultichainNetworkController.ts
Outdated
Show resolved
Hide resolved
… and fix Solana address validation This commit improves the test coverage and fixes issues with Solana address validation in the multichain network controller. The changes ensure proper handling of both EVM and non-EVM network addresses. Key Changes: - Fixed Solana address format in tests to use base58 instead of hex format - Updated test expectations for mixed EVM and non-EVM network responses - Corrected validation regex for Solana addresses
…k/core into feat-4469-active-networks-method
Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
- Extract repeated mock addresses and CAIP IDs into reusable constants - Add proper TypeScript types for mock data and test helpers - Create reusable createMockAccount helper function - Remove should from test descriptions for better readability - Update test names to be more action-oriented and specific
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing and then I'm good :)
packages/multichain-network-controller/src/MultichainNetworkController.test.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/MultichainNetworkController.test.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/MultichainNetworkController.test.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/MultichainNetworkController.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/MultichainNetworkController.ts
Outdated
Show resolved
Hide resolved
…troller - Use PublicInterface pattern for network service dependency instead of concrete implementation. - This improves testability and reduces coupling between the controller and service implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
packages/multichain-network-controller/src/MultichainNetworkController.test.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/MultichainNetworkController.test.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/MultichainNetworkController.test.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/MultichainNetworkController.test.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/MultichainNetworkService.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/MultichainNetworkService.ts
Outdated
Show resolved
Hide resolved
- Replace regex pattern validation with CaipAccountIdStruct from @metamask/utils - Remove assertCaipAccountIds utility function in favor of superstruct validation - Update error handling in MultichainNetworkService to use assert for better errors - Fix Solana chain reference in tests to use proper mainnet identifier This change leverages existing superstruct validation from utils package, reducing duplicate validation logic and providing better error messages.
…ests into accounts-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final review round 💪
I did left a bunch of suggestions (mainly for tests that I didn't review during last reviews)
The code looks really great now, thanks a lot for making all those changes 😄
...chain-network-controller/src/MultichainNetworkController/MultichainNetworkController.test.ts
Show resolved
Hide resolved
...chain-network-controller/src/MultichainNetworkController/MultichainNetworkController.test.ts
Outdated
Show resolved
Hide resolved
...chain-network-controller/src/MultichainNetworkController/MultichainNetworkController.test.ts
Outdated
Show resolved
Hide resolved
it('uses default block explorer index when undefined', () => { | ||
const network: NetworkConfiguration = { | ||
chainId: '0x1', | ||
name: 'Ethereum Mainnet', | ||
nativeCurrency: 'ETH', | ||
blockExplorerUrls: ['https://etherscan.io'], | ||
defaultBlockExplorerUrlIndex: undefined, | ||
rpcEndpoints: [], | ||
defaultRpcEndpointIndex: 0, | ||
}; | ||
expect(toMultichainNetworkConfiguration(network)).toStrictEqual({ | ||
chainId: 'eip155:1', | ||
isEvm: true, | ||
name: 'Ethereum Mainnet', | ||
nativeCurrency: 'ETH', | ||
blockExplorerUrls: ['https://etherscan.io'], | ||
defaultBlockExplorerUrlIndex: 0, | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, was this a missing test? It doesn't feel related to this PR's scope 😄 (that's probably ok, especially this was missing 👍)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I just saw a missing test case and decided to add it. Might as well add it if I'm here but I can remove since it doesn't relate to the scope
packages/multichain-network-controller/src/api/accounts-api.test.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/api/accounts-api.test.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/api/accounts-api.test.ts
Outdated
Show resolved
Hide resolved
packages/multichain-network-controller/src/api/accounts-api.test.ts
Outdated
Show resolved
Hide resolved
.../multichain-network-controller/src/MultichainNetworkService/MultichainNetworkService.test.ts
Outdated
Show resolved
Hide resolved
…rvice/MultichainNetworkService.test.ts Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
…st.ts Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
…st.ts Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
…st.ts Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
…st.ts Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
…ntroller/MultichainNetworkController.test.ts Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
…ntroller/MultichainNetworkController.test.ts Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
…ntroller/MultichainNetworkController.test.ts Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
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:
Key additions:
getNetworksWithTransactionActivityByAccounts
: Fetches active networks for accountsMultichainNetworkService
: New service layer handling network activity fetchingThe new implementation:
PRs for Client Integration
Extension
Mobile
References
Related to #4469
Changelog
@metamask/multichain-network-controller
ADDED: New method
getNetworksWithTransactionActivityByAccounts
to fetch active networks for accountsADDED: New
MultichainNetworkServiceController
for handling network activity fetchingADDED: 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