Skip to content

Commit 24285e8

Browse files
authored
fix(multichain-network): temporarily restrict network activity to EVM (#5677)
## Explanation This PR temporarily restricts the `getNetworksWithTransactionActivityByAccounts` method to EVM networks only. This change is necessary because: 1. The non-EVM network endpoint support is still being completed and needs additional work 2. We want to ensure reliable functionality for EVM networks while non-EVM support is being finalized 3. This allows us to maintain stable service for our primary use case (EVM networks) while API platform team completes the full multi-chain implementation ### Technical Details - Added a filter to exclude non-EVM accounts from network activity checks - Updated the `CHANGELOG` to reflect this temporary limitation - This is an interim solution that will be reverted once non-EVM endpoint support is complete (expected in the coming weeks) ## References - Related to [#4469](MetaMask/MetaMask-planning#4469) - Builds upon [#5551](#5551) ## Changelog ### `@metamask/multichain-network-controller` - **CHANGED**: `getNetworksWithTransactionActivityByAccounts` to only support EVM networks only for now ## 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 communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent 73dd621 commit 24285e8

File tree

4 files changed

+22
-65
lines changed

4 files changed

+22
-65
lines changed

packages/multichain-network-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Updated to restrict `getNetworksWithTransactionActivityByAccounts` to EVM networks only while non-EVM network endpoint support is being completed. Full multi-chain support will be restored in the coming weeks ([#5677](https://github.com/MetaMask/core/pull/5677))
13+
1014
## [0.5.0]
1115

1216
### Added

packages/multichain-network-controller/src/MultichainNetworkController/MultichainNetworkController.test.ts

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,8 @@ describe('MultichainNetworkController', () => {
575575

576576
describe('getNetworksWithTransactionActivityByAccounts', () => {
577577
const MOCK_EVM_ADDRESS = '0x1234567890123456789012345678901234567890';
578-
const MOCK_SOLANA_ADDRESS = 'solana123';
579578
const MOCK_EVM_CHAIN_1 = '1';
580579
const MOCK_EVM_CHAIN_137 = '137';
581-
const MOCK_SOLANA_CHAIN = '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
582580

583581
it('returns empty object when no accounts exist', async () => {
584582
const { controller, messenger } = setupController({
@@ -637,59 +635,5 @@ describe('MultichainNetworkController', () => {
637635
},
638636
});
639637
});
640-
641-
it('formats network activity for mixed EVM and non-EVM accounts', async () => {
642-
const mockResponse: ActiveNetworksResponse = {
643-
activeNetworks: [
644-
`${KnownCaipNamespace.Eip155}:${MOCK_EVM_CHAIN_1}:${MOCK_EVM_ADDRESS}`,
645-
`${KnownCaipNamespace.Solana}:${MOCK_SOLANA_CHAIN}:${MOCK_SOLANA_ADDRESS}`,
646-
],
647-
};
648-
649-
const mockNetworkService = createMockNetworkService(mockResponse);
650-
await mockNetworkService.fetchNetworkActivity([
651-
`${KnownCaipNamespace.Eip155}:${MOCK_EVM_CHAIN_1}:${MOCK_EVM_ADDRESS}`,
652-
`${KnownCaipNamespace.Solana}:${MOCK_SOLANA_CHAIN}:${MOCK_SOLANA_ADDRESS}`,
653-
]);
654-
655-
const { controller, messenger } = setupController({
656-
mockNetworkService,
657-
});
658-
659-
messenger.registerActionHandler(
660-
'AccountsController:listMultichainAccounts',
661-
() => [
662-
createMockInternalAccount({
663-
type: EthAccountType.Eoa,
664-
address: MOCK_EVM_ADDRESS,
665-
scopes: [EthScope.Eoa],
666-
}),
667-
createMockInternalAccount({
668-
type: SolAccountType.DataAccount,
669-
address: MOCK_SOLANA_ADDRESS,
670-
scopes: [SolScope.Mainnet],
671-
}),
672-
],
673-
);
674-
675-
const result =
676-
await controller.getNetworksWithTransactionActivityByAccounts();
677-
678-
expect(mockNetworkService.fetchNetworkActivity).toHaveBeenCalledWith([
679-
`${KnownCaipNamespace.Eip155}:0:${MOCK_EVM_ADDRESS}`,
680-
`${KnownCaipNamespace.Solana}:${MOCK_SOLANA_CHAIN}:${MOCK_SOLANA_ADDRESS}`,
681-
]);
682-
683-
expect(result).toStrictEqual({
684-
[MOCK_EVM_ADDRESS]: {
685-
namespace: KnownCaipNamespace.Eip155,
686-
activeChains: [MOCK_EVM_CHAIN_1],
687-
},
688-
[MOCK_SOLANA_ADDRESS]: {
689-
namespace: KnownCaipNamespace.Solana,
690-
activeChains: [MOCK_SOLANA_CHAIN],
691-
},
692-
});
693-
});
694638
});
695639
});

packages/multichain-network-controller/src/MultichainNetworkController/MultichainNetworkController.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,17 @@ export class MultichainNetworkController extends BaseController<
162162
* @returns A promise that resolves to the active networks for the available addresses
163163
*/
164164
async getNetworksWithTransactionActivityByAccounts(): Promise<ActiveNetworksByAddress> {
165-
const accounts = this.messagingSystem.call(
166-
'AccountsController:listMultichainAccounts',
167-
);
168-
if (!accounts || accounts.length === 0) {
165+
// TODO: We are filtering out non-EVN accounts for now
166+
// Support for non-EVM networks will be added in the coming weeks
167+
const evmAccounts = this.messagingSystem
168+
.call('AccountsController:listMultichainAccounts')
169+
.filter((account) => isEvmAccountType(account.type));
170+
171+
if (!evmAccounts || evmAccounts.length === 0) {
169172
return this.state.networksWithTransactionActivity;
170173
}
171174

172-
const formattedAccounts = accounts
175+
const formattedAccounts = evmAccounts
173176
.map((account: InternalAccount) => toAllowedCaipAccountIds(account))
174177
.flat();
175178

packages/multichain-network-controller/src/MultichainNetworkService/MultichainNetworkService.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CaipAccountId } from '@metamask/utils';
1+
import { KnownCaipNamespace, type CaipAccountId } from '@metamask/utils';
22

33
import { MultichainNetworkService } from './MultichainNetworkService';
44
import {
@@ -10,9 +10,12 @@ import {
1010

1111
describe('MultichainNetworkService', () => {
1212
const mockFetch = jest.fn();
13+
const MOCK_EVM_ADDRESS = '0x1234567890123456789012345678901234567890';
14+
const MOCK_EVM_CHAIN_1 = '1';
15+
const MOCK_EVM_CHAIN_137 = '137';
1316
const validAccountIds: CaipAccountId[] = [
14-
'eip155:1:0x1234567890123456789012345678901234567890',
15-
'solana:1:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
17+
`${KnownCaipNamespace.Eip155}:${MOCK_EVM_CHAIN_1}:${MOCK_EVM_ADDRESS}`,
18+
`${KnownCaipNamespace.Eip155}:${MOCK_EVM_CHAIN_137}:${MOCK_EVM_ADDRESS}`,
1619
];
1720

1821
describe('constructor', () => {
@@ -27,7 +30,10 @@ describe('MultichainNetworkService', () => {
2730
describe('fetchNetworkActivity', () => {
2831
it('makes request with correct URL and headers', async () => {
2932
const mockResponse: ActiveNetworksResponse = {
30-
activeNetworks: ['eip155:1:0x1234567890123456789012345678901234567890'],
33+
activeNetworks: [
34+
`${KnownCaipNamespace.Eip155}:${MOCK_EVM_CHAIN_1}:${MOCK_EVM_ADDRESS}`,
35+
`${KnownCaipNamespace.Eip155}:${MOCK_EVM_CHAIN_137}:${MOCK_EVM_ADDRESS}`,
36+
],
3137
};
3238

3339
mockFetch.mockResolvedValueOnce({

0 commit comments

Comments
 (0)