Skip to content

Commit 89d2744

Browse files
authored
refactor: remove BIP-44 flag from network hooks (MetaMask#26192)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> This PR is part of a series to remove the legacy code after BIP-44 was shipped, several components, hooks, views, etc. still uses the remote feature flag for BIP-44 causing an unnecessary overcomplexity that can be easily removed. The change includes updating the network hooks. ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/MUL-1461 ## **Manual testing steps** Not applicable ## **Screenshots/Recordings** Not applicable ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I've included tests if applicable - [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > This removes feature-flag gating around network enablement/selection hooks, so behavior now always follows the post-BIP-44 multichain path; mistakes could impact which networks are considered enabled or how enabling is applied. Changes are localized but touch core hooks used across network selection UI. > > **Overview** > **Network hooks no longer branch on the BIP-44/multichain state2 remote flag.** `useNetworksToUse` always derives `networksToUse` and the combined “all selected” state from selected internal accounts and per-namespace network lists, and drops the `isMultichainAccountsState2Enabled` return value. > > `useNetworkEnablement` now always enables via `NetworkEnablementController.enableNetwork` (no namespace-specific fallback), and `useCurrentNetworkInfo` always flattens `enabledNetworksByNamespace` when computing enabled networks. > > Tests were updated to remove flag mocks/expectations, a smoke test for adding popular networks was temporarily skipped pending BIP-44 UI updates, and a debounce wait comment/timeout rationale was clarified in `MultichainAccountSelectorList` tests. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8276e02. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 03597ba commit 89d2744

10 files changed

Lines changed: 21 additions & 226 deletions

File tree

app/component-library/components-temp/MultichainAccounts/MultichainAccountSelectorList/MultichainAccountSelectorList.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ describe('MultichainAccountSelectorList', () => {
9292
fireEvent.changeText(searchInput, searchTerm);
9393
});
9494

95-
// Wait for debounce to complete and filtering to occur
96-
// Check both visible and hidden items to ensure filtering has completed
95+
// Wait for debounce (1s) to complete and filtering to occur. Use a
96+
// generous timeout so CI has time for debounce + re-render + list update.
9797
await waitFor(
9898
() => {
9999
expectedVisible.forEach((text) => {

app/components/UI/CustomNetworkSelector/CustomNetworkSelector.test.tsx

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { render } from '@testing-library/react-native';
3-
import { Provider, useSelector } from 'react-redux';
3+
import { Provider } from 'react-redux';
44
import { createStore } from 'redux';
55
import { useNavigation } from '@react-navigation/native';
66
import { useSafeAreaInsets } from 'react-native-safe-area-context';
@@ -17,11 +17,7 @@ import { useNetworkSelection } from '../../hooks/useNetworkSelection/useNetworkS
1717
import { useNetworksToUse } from '../../hooks/useNetworksToUse/useNetworksToUse';
1818
import CustomNetworkSelector from './CustomNetworkSelector';
1919
import { CustomNetworkItem } from './CustomNetworkSelector.types';
20-
import {
21-
selectIsEvmNetworkSelected,
22-
selectSelectedNonEvmNetworkChainId,
23-
} from '../../../selectors/multichainNetworkController';
24-
import { selectEvmChainId } from '../../../selectors/networkController';
20+
import { selectIsEvmNetworkSelected } from '../../../selectors/multichainNetworkController';
2521
import { InternalAccount } from '@metamask/keyring-internal-api';
2622

2723
jest.mock('../../../core/Multichain/utils', () => ({
@@ -133,7 +129,6 @@ jest.mock('../../../util/device', () => ({
133129

134130
jest.mock('../../../selectors/networkController', () => ({
135131
selectEvmNetworkConfigurationsByChainId: jest.fn(),
136-
selectEvmChainId: jest.fn(),
137132
createProviderConfig: jest.fn(),
138133
}));
139134

@@ -175,7 +170,6 @@ jest.mock('@shopify/flash-list', () => {
175170

176171
jest.mock('../../../selectors/multichainNetworkController', () => ({
177172
selectIsEvmNetworkSelected: jest.fn(),
178-
selectSelectedNonEvmNetworkChainId: jest.fn(),
179173
}));
180174

181175
// Mock store setup
@@ -214,7 +208,6 @@ describe('CustomNetworkSelector', () => {
214208
const mockUseNetworksToUse = useNetworksToUse as jest.MockedFunction<
215209
typeof useNetworksToUse
216210
>;
217-
const mockUseSelector = jest.mocked(useSelector);
218211
const mockSelectIsEvmNetworkSelected =
219212
selectIsEvmNetworkSelected as jest.MockedFunction<
220213
typeof selectIsEvmNetworkSelected
@@ -296,7 +289,6 @@ describe('CustomNetworkSelector', () => {
296289
evmNetworks: mockNetworks,
297290
solanaNetworks: mockNetworks,
298291
bitcoinNetworks: mockNetworks,
299-
isMultichainAccountsState2Enabled: true,
300292
selectedEvmAccount: { id: 'evm-account' } as InternalAccount,
301293
selectedSolanaAccount: { id: 'solana-account' } as InternalAccount,
302294
selectedBitcoinAccount: { id: 'bitcoin-account' } as InternalAccount,
@@ -310,19 +302,6 @@ describe('CustomNetworkSelector', () => {
310302
});
311303

312304
mockSelectIsEvmNetworkSelected.mockReturnValue(true);
313-
314-
mockUseSelector.mockImplementation((selector) => {
315-
if (selector === mockSelectIsEvmNetworkSelected) {
316-
return true;
317-
}
318-
if (selector === selectEvmChainId) {
319-
return '0x1'; // Ethereum mainnet
320-
}
321-
if (selector === selectSelectedNonEvmNetworkChainId) {
322-
return 'solana:mainnet';
323-
}
324-
return undefined;
325-
});
326305
});
327306

328307
// Helper function to render with Redux provider
@@ -519,7 +498,6 @@ describe('CustomNetworkSelector', () => {
519498
evmNetworks: [networkWithMultipleRpcs],
520499
solanaNetworks: [],
521500
bitcoinNetworks: [],
522-
isMultichainAccountsState2Enabled: false,
523501
selectedEvmAccount: null,
524502
selectedSolanaAccount: null,
525503
selectedBitcoinAccount: null,
@@ -568,7 +546,6 @@ describe('CustomNetworkSelector', () => {
568546
evmNetworks: [networkWithSingleRpc],
569547
solanaNetworks: [],
570548
bitcoinNetworks: [],
571-
isMultichainAccountsState2Enabled: false,
572549
selectedEvmAccount: null,
573550
selectedSolanaAccount: null,
574551
selectedBitcoinAccount: null,

app/components/UI/NetworkMultiSelector/NetworkMultiSelector.test.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,7 @@ jest.mock('../../../component-library/components/Texts/Text', () => {
191191
});
192192

193193
// Mock store setup
194-
const mockStore = createStore(() => ({
195-
featureFlags: {
196-
multichainAccounts: {
197-
enabledMultichainAccounts: true,
198-
},
199-
},
200-
}));
194+
const mockStore = createStore(() => ({}));
201195

202196
describe('NetworkMultiSelector', () => {
203197
const mockOpenModal = jest.fn();
@@ -265,7 +259,6 @@ describe('NetworkMultiSelector', () => {
265259
: null,
266260
selectedBitcoinAccount: null,
267261
selectedTronAccount: null,
268-
isMultichainAccountsState2Enabled: true,
269262
areAllNetworksSelectedCombined: areAllSelected,
270263
areAllEvmNetworksSelected: false,
271264
areAllSolanaNetworksSelected: false,
@@ -394,7 +387,6 @@ describe('NetworkMultiSelector', () => {
394387
selectedSolanaAccount: { id: 'solana-account' } as InternalAccount,
395388
selectedBitcoinAccount: { id: 'bitcoin-account' } as InternalAccount,
396389
selectedTronAccount: { id: 'tron-account' } as InternalAccount,
397-
isMultichainAccountsState2Enabled: true,
398390
areAllNetworksSelectedCombined: false,
399391
areAllEvmNetworksSelected: false,
400392
areAllSolanaNetworksSelected: false,
@@ -725,9 +717,8 @@ describe('NetworkMultiSelector', () => {
725717
});
726718
});
727719

728-
it('calls useNetworksToUse when multichain is enabled', () => {
720+
it('calls useNetworksToUse', () => {
729721
mockUseSelector
730-
.mockReturnValueOnce(true) // isMultichainAccountsState2Enabled
731722
.mockReturnValueOnce(() => ({ id: 'evm-account' })) // selectedEvmAccount
732723
.mockReturnValueOnce(() => ({ id: 'solana-account' })); // selectedSolanaAccount
733724

@@ -793,7 +784,6 @@ describe('NetworkMultiSelector', () => {
793784
selectedEvmAccount: { id: 'evm-account' } as InternalAccount,
794785
selectedSolanaAccount: null,
795786
selectedBitcoinAccount: null,
796-
isMultichainAccountsState2Enabled: true,
797787
areAllNetworksSelectedCombined: true,
798788
areAllEvmNetworksSelected: true,
799789
areAllSolanaNetworksSelected: false,
@@ -879,7 +869,6 @@ describe('NetworkMultiSelector', () => {
879869
selectedTronAccount: null,
880870
areAllBitcoinNetworksSelected: false,
881871
areAllTronNetworksSelected: false,
882-
isMultichainAccountsState2Enabled: true,
883872
areAllNetworksSelectedCombined: true,
884873
areAllEvmNetworksSelected: false,
885874
areAllSolanaNetworksSelected: true,
@@ -958,7 +947,6 @@ describe('NetworkMultiSelector', () => {
958947
selectedEvmAccount: null,
959948
selectedSolanaAccount: null,
960949
selectedBitcoinAccount: null,
961-
isMultichainAccountsState2Enabled: true,
962950
areAllNetworksSelectedCombined: false,
963951
areAllEvmNetworksSelected: false,
964952
areAllSolanaNetworksSelected: false,
@@ -1033,7 +1021,6 @@ describe('NetworkMultiSelector', () => {
10331021
selectedSolanaAccount: null,
10341022
selectedBitcoinAccount: null,
10351023
selectedTronAccount: null,
1036-
isMultichainAccountsState2Enabled: true,
10371024
areAllNetworksSelectedCombined: false,
10381025
areAllEvmNetworksSelected: false,
10391026
areAllSolanaNetworksSelected: false,
@@ -1161,7 +1148,6 @@ describe('NetworkMultiSelector', () => {
11611148
});
11621149

11631150
mockUseSelector
1164-
.mockReturnValueOnce(true) // isMultichainAccountsState2Enabled
11651151
.mockReturnValueOnce(() => ({ id: 'evm-account' })) // selectedEvmAccount
11661152
.mockReturnValueOnce(() => ({ id: 'solana-account' })) // selectedSolanaAccount
11671153
.mockReturnValueOnce(() => ({ id: 'bitcoin-account' })); // selectedBitcoinAccount

app/components/Views/TrendingView/TrendingView.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ jest.mock(
9595
solanaNetworks: [],
9696
selectedEvmAccount: null,
9797
selectedSolanaAccount: null,
98-
isMultichainAccountsState2Enabled: false,
9998
areAllNetworksSelectedCombined: false,
10099
areAllEvmNetworksSelected: false,
101100
areAllSolanaNetworksSelected: false,

app/components/hooks/useCurrentNetworkInfo.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useSelector } from 'react-redux';
33
import { formatChainIdToCaip } from '@metamask/bridge-controller';
44
import { selectNetworkConfigurationsByCaipChainId } from '../../selectors/networkController';
55
import { useNetworkEnablement } from './useNetworkEnablement/useNetworkEnablement';
6-
import { selectMultichainAccountsState2Enabled } from '../../selectors/featureFlagController/multichainAccounts';
76
import { KnownCaipNamespace } from '@metamask/utils';
87

98
export interface NetworkInfo {
@@ -29,34 +28,20 @@ export const useCurrentNetworkInfo = (): CurrentNetworkInfo => {
2928
const networksByCaipChainId = useSelector(
3029
selectNetworkConfigurationsByCaipChainId,
3130
);
32-
const isMultichainAccountsState2Enabled = useSelector(
33-
selectMultichainAccountsState2Enabled,
34-
);
3531

3632
// Get all enabled networks for the namespace
3733
const enabledNetworks = useMemo(() => {
38-
if (isMultichainAccountsState2Enabled) {
39-
const networksForNamespace = {
40-
...Object.values(enabledNetworksByNamespace).reduce(
41-
(acc, obj) => ({ ...acc, ...obj }),
42-
{},
43-
),
44-
};
45-
46-
return Object.entries(networksForNamespace)
47-
.filter(([_key, value]) => value)
48-
.map(([chainId, enabled]) => ({ chainId, enabled: Boolean(enabled) }));
49-
}
50-
51-
const networksForNamespace = enabledNetworksByNamespace[namespace] || {};
34+
const networksForNamespace = {
35+
...Object.values(enabledNetworksByNamespace).reduce(
36+
(acc, obj) => ({ ...acc, ...obj }),
37+
{},
38+
),
39+
};
40+
5241
return Object.entries(networksForNamespace)
5342
.filter(([_key, value]) => value)
5443
.map(([chainId, enabled]) => ({ chainId, enabled: Boolean(enabled) }));
55-
}, [
56-
enabledNetworksByNamespace,
57-
isMultichainAccountsState2Enabled,
58-
namespace,
59-
]);
44+
}, [enabledNetworksByNamespace]);
6045

6146
// Generic function to get network info by index
6247
const getNetworkInfo = useCallback(

app/components/hooks/useNetworkEnablement/useNetworkEnablement.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import Engine from '../../../core/Engine';
1414
import { selectEnabledNetworksByNamespace } from '../../../selectors/networkEnablementController';
1515
import { selectIsEvmNetworkSelected } from '../../../selectors/multichainNetworkController';
1616
import { selectChainId } from '../../../selectors/networkController';
17-
import { selectMultichainAccountsState2Enabled } from '../../../selectors/featureFlagController/multichainAccounts';
1817

1918
/**
2019
* Manages network enablement state across namespaces (EVM, Bitcoin, etc).
@@ -62,10 +61,6 @@ export const useNetworkEnablement = () => {
6261
[],
6362
);
6463

65-
const isMultichainAccountsState2Enabled = useSelector(
66-
selectMultichainAccountsState2Enabled,
67-
);
68-
6964
const popularEvmNetworksList =
7065
networkEnablementController?.listPopularEvmNetworks?.() ?? [];
7166
const popularMultichainNetworksList =
@@ -91,13 +86,9 @@ export const useNetworkEnablement = () => {
9186

9287
const enableNetwork = useMemo(
9388
() => (chainId: CaipChainId) => {
94-
if (isMultichainAccountsState2Enabled) {
95-
networkEnablementController.enableNetwork(chainId);
96-
return;
97-
}
98-
networkEnablementController.enableNetworkInNamespace(chainId, namespace);
89+
networkEnablementController.enableNetwork(chainId);
9990
},
100-
[networkEnablementController, isMultichainAccountsState2Enabled, namespace],
91+
[networkEnablementController],
10192
);
10293

10394
const enableAllPopularNetworks = useMemo(

app/components/hooks/useNetworkSelection/useNetworkSelection.test.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { formatChainIdToCaip } from '@metamask/bridge-controller';
1212
import { useNetworkEnablement } from '../useNetworkEnablement/useNetworkEnablement';
1313
import { ProcessedNetwork } from '../useNetworksByNamespace/useNetworksByNamespace';
1414
import { useNetworkSelection } from './useNetworkSelection';
15-
import { selectMultichainAccountsState2Enabled } from '../../../selectors/featureFlagController/multichainAccounts/enabledMultichainAccounts';
1615
import {
1716
selectPopularNetworkConfigurationsByCaipChainId,
1817
selectNetworkConfigurationsByCaipChainId,
@@ -97,13 +96,6 @@ jest.mock('../useNetworkEnablement/useNetworkEnablement', () => ({
9796
useNetworkEnablement: jest.fn(),
9897
}));
9998

100-
jest.mock(
101-
'../../../selectors/featureFlagController/multichainAccounts/enabledMultichainAccounts',
102-
() => ({
103-
selectMultichainAccountsState2Enabled: jest.fn(),
104-
}),
105-
);
106-
10799
jest.mock('../../../core/Engine', () => ({
108100
context: {
109101
MultichainNetworkController: {
@@ -319,9 +311,6 @@ describe('useNetworkSelection', () => {
319311
if (selector === selectNetworkConfigurationsByCaipChainId) {
320312
return mockNetworkConfigurations;
321313
}
322-
if (selector === selectMultichainAccountsState2Enabled) {
323-
return false;
324-
}
325314
if (selector === selectInternalAccounts) {
326315
return [];
327316
}
@@ -673,11 +662,9 @@ describe('useNetworkSelection', () => {
673662
});
674663
});
675664

676-
it('selectCustomNetwork with multichain enabled calls MultichainNetworkController', async () => {
677-
// Mock multichain enabled
665+
it('selectCustomNetwork calls MultichainNetworkController', async () => {
678666
mockUseSelector
679667
.mockReturnValueOnce(mockPopularNetworkConfigurations)
680-
.mockReturnValueOnce(true) // isMultichainAccountsState2Enabled = true
681668
.mockReturnValueOnce([]); // selectInternalAccounts
682669

683670
const customChainId = 'eip155:999' as CaipChainId;
@@ -976,9 +963,6 @@ describe('useNetworkSelection', () => {
976963
if (selector === selectPopularNetworkConfigurationsByCaipChainId) {
977964
return initialPopularNetworks;
978965
}
979-
if (selector === selectMultichainAccountsState2Enabled) {
980-
return false;
981-
}
982966
if (selector === selectInternalAccounts) {
983967
return [];
984968
}
@@ -1208,9 +1192,6 @@ describe('useNetworkSelection', () => {
12081192
if (selector === selectNetworkConfigurationsByCaipChainId) {
12091193
return mockNetworkConfigurations;
12101194
}
1211-
if (selector === selectMultichainAccountsState2Enabled) {
1212-
return false;
1213-
}
12141195
if (selector === selectInternalAccounts) {
12151196
return [mockBitcoinAccount];
12161197
}
@@ -1243,9 +1224,6 @@ describe('useNetworkSelection', () => {
12431224
if (selector === selectNetworkConfigurationsByCaipChainId) {
12441225
return mockNetworkConfigurations;
12451226
}
1246-
if (selector === selectMultichainAccountsState2Enabled) {
1247-
return false;
1248-
}
12491227
if (selector === selectInternalAccounts) {
12501228
return [];
12511229
}
@@ -1825,9 +1803,6 @@ describe('useNetworkSelection', () => {
18251803
if (selector === selectPopularNetworkConfigurationsByCaipChainId) {
18261804
return newPopularConfigs;
18271805
}
1828-
if (selector === selectMultichainAccountsState2Enabled) {
1829-
return false;
1830-
}
18311806
if (selector === selectInternalAccounts) {
18321807
return [];
18331808
}
@@ -1857,9 +1832,6 @@ describe('useNetworkSelection', () => {
18571832
},
18581833
];
18591834
}
1860-
if (selector === selectMultichainAccountsState2Enabled) {
1861-
return false;
1862-
}
18631835
if (selector === selectInternalAccounts) {
18641836
return []; // No Bitcoin accounts
18651837
}

0 commit comments

Comments
 (0)