Skip to content

Commit 271d096

Browse files
authored
chore: Remove MM_PER_DAPP_SELECTED_NETWORK feature flag (#21963)
## **Description** This is a collective effort to clean up our codebase by removing old feature flags such as `MM_PER_DAPP_SELECTED_NETWORK` ## **Changelog** CHANGELOG entry:null ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/MUL-1132 ## **Manual testing steps** ```gherkin Feature: my feature name Scenario: user [verb for user action] Given [describe expected initial app state] When user [verb for user action] Then [describe expected outcome] ``` ## **Screenshots/Recordings** `~` ### **Before** `~` ### **After** `~` ## **Pre-merge author checklist** - [x] 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). - [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-mobile/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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Removes MM_PER_DAPP_SELECTED_NETWORK flag and simplifies code to always use per-dapp network selection across UI, RPC, WalletConnect, selectors, hooks, tests, and CI. > > - **Network selection (core/infra)**: > - Remove `MM_PER_DAPP_SELECTED_NETWORK` flag and all conditionals; per-dapp network selection is now always on. > - `selectedNetworkController` selectors default to domain-based values; `selectPerOriginChainId` used broadly. > - `ethereum-chain-utils.switchToNetwork` and RPC middleware always set `SelectedNetworkController.setNetworkClientIdForDomain`. > - `useSwitchNetworks`/NetworkSelector: when dapp connected, always set per-domain network; otherwise switch global. > - **UI**: > - Account/Tx components (`AccountFromToInfoCard`, `AddressFrom`, `TransactionDetails`, `TransactionNotification`) use tx/chain-specific data directly (no flag checks). > - Permissions UIs (`PermissionsSummary`, `AccountPermissions`, multichain variants) always show per-dapp network picker and set domain network on changes. > - BrowserTab: remove legacy permission checks tied to global selection. > - **WalletConnect**: > - Use per-origin chain ID (`selectPerOriginChainId`) and domain network switching; simplify switch handling and tests accordingly. > - **Hooks/Utils**: > - `useAddressBalance` and smart tx publish hook rely on provided `chainId`/`networkClientId` without gating. > - **Tests/CI/Config**: > - Update unit/e2e tests and mocks removing flag; rename E2E titles to “Dapp Network Switching”. > - Remove flag from `.js.env.example` and Bitrise envs. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8de63d1. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent fbc08a6 commit 271d096

File tree

26 files changed

+69
-332
lines changed

26 files changed

+69
-332
lines changed

.js.env.example

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ export MM_SAMPLE_FEATURE_COUNTER_ENABLED="true"
9292
# The endpoint used to submit errors and tracing data to Sentry for dev environment.
9393
# export MM_SENTRY_DSN_DEV=
9494

95-
# Per dapp selected network feature flag
96-
export MM_PER_DAPP_SELECTED_NETWORK=""
97-
9895
# Remove global network selector flag
9996
export MM_REMOVE_GLOBAL_NETWORK_SELECTOR=""
10097

app/components/UI/AccountFromToInfoCard/AccountFromToInfoCard.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { AccountFromToInfoCardProps } from './AccountFromToInfoCard.types';
2121
import { selectInternalAccounts } from '../../../selectors/accountsController';
2222
import { RootState } from '../../../reducers';
2323
import AddressFrom from './AddressFrom';
24-
import { isPerDappSelectedNetworkEnabled } from '../../../util/networks';
2524

2625
const AccountFromToInfoCard = (props: AccountFromToInfoCardProps) => {
2726
const { internalAccounts, chainId, ticker, transactionState, origin } = props;
@@ -170,11 +169,7 @@ const AccountFromToInfoCard = (props: AccountFromToInfoCardProps) => {
170169
<View style={styles.container}>
171170
{fromAddress && (
172171
<AddressFrom
173-
chainId={
174-
isPerDappSelectedNetworkEnabled()
175-
? transactionState?.chainId
176-
: undefined
177-
}
172+
chainId={transactionState?.chainId}
178173
asset={selectedAsset}
179174
from={fromAddress}
180175
origin={origin}

app/components/UI/AccountFromToInfoCard/AddressFrom.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import { BadgeVariant } from '../../../component-library/components/Badges/Badge
88
import Text from '../../../component-library/components/Texts/Text';
99
import { useStyles } from '../../../component-library/hooks';
1010
import { selectAccountsByChainId } from '../../../selectors/accountTrackerController';
11-
import {
12-
selectEvmNetworkImageSource,
13-
selectEvmNetworkName,
14-
} from '../../../selectors/networkInfos';
1511
import {
1612
getLabelTextByAddress,
1713
renderAccountName,
@@ -21,7 +17,6 @@ import useAddressBalance from '../../hooks/useAddressBalance/useAddressBalance';
2117
import stylesheet from './AddressFrom.styles';
2218
import { selectInternalEvmAccounts } from '../../../selectors/accountsController';
2319
import useNetworkInfo from '../../Views/confirmations/hooks/useNetworkInfo';
24-
import { isPerDappSelectedNetworkEnabled } from '../../../util/networks';
2520
import { selectAvatarAccountType } from '../../../selectors/settings';
2621

2722
interface Asset {
@@ -57,16 +52,14 @@ const AddressFrom = ({
5752
asset,
5853
from,
5954
dontWatchAsset,
60-
isPerDappSelectedNetworkEnabled() ? chainId : undefined,
55+
chainId,
6156
);
6257

6358
const accountsByChainId = useSelector(selectAccountsByChainId);
6459

6560
const internalAccounts = useSelector(selectInternalEvmAccounts);
6661
const activeAddress = toChecksumAddress(from);
6762

68-
const networkName = useSelector(selectEvmNetworkName);
69-
const networkImage = useSelector(selectEvmNetworkImageSource);
7063
const perDappNetworkInfo = useNetworkInfo(chainId);
7164

7265
const avatarAccountType = useSelector(selectAvatarAccountType);
@@ -82,13 +75,9 @@ const AddressFrom = ({
8275
}
8376
}, [accountsByChainId, internalAccounts, activeAddress, origin]);
8477

85-
const displayNetworkName = isPerDappSelectedNetworkEnabled()
86-
? perDappNetworkInfo.networkName
87-
: networkName;
78+
const displayNetworkName = perDappNetworkInfo.networkName;
8879

89-
const displayNetworkImage = isPerDappSelectedNetworkEnabled()
90-
? perDappNetworkInfo.networkImage
91-
: networkImage;
80+
const displayNetworkImage = perDappNetworkInfo.networkImage;
9281

9382
const accountTypeLabel = getLabelTextByAddress(activeAddress);
9483

app/components/UI/Notification/TransactionNotification/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { collectibleContractsSelector } from '../../../../reducers/collectibles'
2525
import { useTheme } from '../../../../util/theme';
2626
import {
2727
selectChainId,
28-
selectEvmTicker,
2928
selectTickerByChainId,
3029
} from '../../../../selectors/networkController';
3130
import {
@@ -37,7 +36,6 @@ import { selectContractExchangeRates } from '../../../../selectors/tokenRatesCon
3736
import { selectAccounts } from '../../../../selectors/accountTrackerController';
3837
import { speedUpTransaction } from '../../../../util/transaction-controller';
3938
import { selectSelectedInternalAccountFormattedAddress } from '../../../../selectors/accountsController';
40-
import { isPerDappSelectedNetworkEnabled } from '../../../../util/networks';
4139

4240
const WINDOW_WIDTH = Dimensions.get('window').width;
4341
const ACTION_CANCEL = 'cancel';
@@ -454,9 +452,7 @@ const mapStateToProps = (state, ownProps) => {
454452
({ id }) => id === ownProps?.currentNotification.transaction.id,
455453
);
456454

457-
const ticker = isPerDappSelectedNetworkEnabled()
458-
? selectTickerByChainId(state, tx?.chainId)
459-
: selectEvmTicker(state);
455+
const ticker = selectTickerByChainId(state, tx?.chainId);
460456
return {
461457
accounts: selectAccounts(state),
462458
selectedAddress: selectSelectedInternalAccountFormattedAddress(state),

app/components/UI/PermissionsSummary/PermissionsSummary.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ import ButtonIcon, {
4141
ButtonIconSizes,
4242
} from '../../../component-library/components/Buttons/ButtonIcon';
4343
import TabBar from '../../../component-library/components-temp/TabBar';
44-
import {
45-
getNetworkImageSource,
46-
isPerDappSelectedNetworkEnabled,
47-
} from '../../../util/networks';
44+
import { getNetworkImageSource } from '../../../util/networks';
4845
import Engine from '../../../core/Engine';
4946
import { SDKSelectorsIDs } from '../../../../e2e/selectors/Settings/SDK.selectors';
5047
import { useSelector } from 'react-redux';
@@ -169,9 +166,7 @@ const PermissionsSummary = ({
169166
const url = currentPageInformation.url;
170167
const iconTitle = getHost(currentEnsName || url);
171168

172-
return isPerDappSelectedNetworkEnabled() &&
173-
isAlreadyConnected &&
174-
!showPermissionsOnly ? (
169+
return isAlreadyConnected && !showPermissionsOnly ? (
175170
<View style={[styles.domainLogoContainer, styles.assetLogoContainer]}>
176171
<TouchableOpacity
177172
onPress={switchNetwork}

app/components/UI/TransactionElement/TransactionDetails/index.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
getBlockExplorerTxUrl,
1414
findBlockExplorerForNonEvmChainId,
1515
isLineaMainnetChainId,
16-
isPerDappSelectedNetworkEnabled,
1716
} from '../../../../util/networks';
1817
import Logger from '../../../../util/Logger';
1918
import EthereumAddress from '../../EthereumAddress';
@@ -33,7 +32,6 @@ import decodeTransaction from '../../TransactionElement/utils';
3332
import {
3433
selectChainId,
3534
selectNetworkConfigurations,
36-
selectEvmTicker,
3735
selectProviderConfig,
3836
selectTickerByChainId,
3937
} from '../../../../selectors/networkController';
@@ -240,9 +238,7 @@ class TransactionDetails extends PureComponent {
240238
transactions,
241239
} = this.props;
242240

243-
const chainId = isPerDappSelectedNetworkEnabled()
244-
? transactionObject.chainId
245-
: this.props.chainId;
241+
const chainId = transactionObject.chainId;
246242
const multiLayerFeeNetwork = isMultiLayerFeeNetwork(chainId);
247243
const transactionHash = transactionDetails?.hash;
248244
if (
@@ -382,9 +378,7 @@ class TransactionDetails extends PureComponent {
382378
transactionObject: { status, time, txParams, chainId: txChainId },
383379
shouldUseSmartTransaction,
384380
} = this.props;
385-
const chainId = isPerDappSelectedNetworkEnabled()
386-
? txChainId
387-
: this.props.chainId;
381+
const chainId = txChainId;
388382
const hasNestedTransactions = Boolean(
389383
transactionObject?.nestedTransactions?.length,
390384
);
@@ -552,15 +546,11 @@ class TransactionDetails extends PureComponent {
552546

553547
const mapStateToProps = (state, ownProps) => ({
554548
chainId: selectChainId(state),
555-
providerConfig: isPerDappSelectedNetworkEnabled()
556-
? selectProviderConfig(state)
557-
: undefined,
549+
providerConfig: selectProviderConfig(state),
558550
networkConfigurations: selectNetworkConfigurations(state),
559551
selectedAddress: selectSelectedInternalAccountFormattedAddress(state),
560552
transactions: selectTransactions(state),
561-
ticker: isPerDappSelectedNetworkEnabled()
562-
? selectTickerByChainId(state, ownProps.transactionObject.chainId)
563-
: selectEvmTicker(state),
553+
ticker: selectTickerByChainId(state, ownProps.transactionObject.chainId),
564554
tokens: selectTokensByChainIdAndAddress(
565555
state,
566556
ownProps.transactionObject.chainId,

app/components/Views/AccountPermissions/AccountPermissions.tsx

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ import URLParse from 'url-parse';
6161
import { useMetrics } from '../../../components/hooks/useMetrics';
6262
import { selectPermissionControllerState } from '../../../selectors/snaps/permissionController';
6363
import { RootState } from '../../../reducers';
64-
import {
65-
getNetworkImageSource,
66-
isPerDappSelectedNetworkEnabled,
67-
} from '../../../util/networks';
64+
import { getNetworkImageSource } from '../../../util/networks';
6865
import PermissionsSummary from '../../../components/UI/PermissionsSummary';
6966
import { PermissionsSummaryProps } from '../../../components/UI/PermissionsSummary/PermissionsSummary.types';
7067
import {
@@ -359,10 +356,7 @@ const AccountPermissions = (props: AccountPermissionsProps) => {
359356
toggleRevokeAllPermissionsModal();
360357
return;
361358
}
362-
const currentEvmCaipChainId: CaipChainId =
363-
isPerDappSelectedNetworkEnabled()
364-
? `eip155:${parseInt(networkInfo.chainId, 16)}`
365-
: `eip155:${parseInt(currentEvmChainId, 16)}`;
359+
const currentEvmCaipChainId: CaipChainId = `eip155:${parseInt(networkInfo.chainId, 16)}`;
366360

367361
const newSelectedEvmChainId = chainIds.find((chainId) => {
368362
const { namespace } = parseChainId(chainId);
@@ -398,18 +392,11 @@ const AccountPermissions = (props: AccountPermissionsProps) => {
398392
config as NetworkConfiguration;
399393
const { networkClientId } = rpcEndpoints[defaultRpcEndpointIndex];
400394

401-
if (isPerDappSelectedNetworkEnabled()) {
402-
// For per-dapp network selection, directly set the network for this domain
403-
Engine.context.SelectedNetworkController.setNetworkClientIdForDomain(
404-
hostname,
405-
networkClientId,
406-
);
407-
} else {
408-
// For global network selection, switch the active network
409-
await Engine.context.MultichainNetworkController.setActiveNetwork(
410-
networkClientId,
411-
);
412-
}
395+
// For per-dapp network selection, directly set the network for this domain
396+
Engine.context.SelectedNetworkController.setNetworkClientIdForDomain(
397+
hostname,
398+
networkClientId,
399+
);
413400
}
414401
}
415402

@@ -418,7 +405,6 @@ const AccountPermissions = (props: AccountPermissionsProps) => {
418405
setNetworkSelectorUserIntent(USER_INTENT.Confirm);
419406
},
420407
[
421-
currentEvmChainId,
422408
hostname,
423409
networkConfigurations,
424410
permittedCaipChainIds,

app/components/Views/BrowserTab/BrowserTab.tsx

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import downloadFile from '../../../util/browser/downloadFile';
4848
import { MAX_MESSAGE_LENGTH } from '../../../constants/dapp';
4949
import sanitizeUrlInput from '../../../util/url/sanitizeUrlInput';
5050
import {
51-
getCaip25Caveat,
5251
getPermittedCaipAccountIdsByHostname,
5352
getPermittedEvmAddressesByHostname,
5453
sortMultichainAccountsByLastSelected,
@@ -78,8 +77,7 @@ import trackErrorAsAnalytics from '../../../util/metrics/TrackError/trackErrorAs
7877
import { selectPermissionControllerState } from '../../../selectors/snaps/permissionController';
7978
import { isTest } from '../../../util/test/utils.js';
8079
import { EXTERNAL_LINK_TYPE } from '../../../constants/browser';
81-
import { AccountPermissionsScreens } from '../AccountPermissions/AccountPermissions.types';
82-
import { useIsFocused, useNavigation } from '@react-navigation/native';
80+
import { useNavigation } from '@react-navigation/native';
8381
import { useStyles } from '../../hooks/useStyles';
8482
import styleSheet from './styles';
8583
import { type RootState } from '../../../reducers';
@@ -113,14 +111,11 @@ import UrlAutocomplete, {
113111
UrlAutocompleteRef,
114112
} from '../../UI/UrlAutocomplete';
115113
import { selectSearchEngine } from '../../../reducers/browser/selectors';
116-
import { getPermittedEthChainIds } from '@metamask/chain-agnostic-permission';
117114
import {
118115
getPhishingTestResult,
119116
getPhishingTestResultAsync,
120117
isProductSafetyDappScanningEnabled,
121118
} from '../../../util/phishingDetection';
122-
import { isPerDappSelectedNetworkEnabled } from '../../../util/networks';
123-
import { toHex } from '@metamask/controller-utils';
124119
import { parseCaipAccountId } from '@metamask/utils';
125120
import { selectBrowserFullscreen } from '../../../selectors/browser';
126121
import { selectAssetsTrendingTokensEnabled } from '../../../selectors/featureFlagController/assetsTrendingTokens';
@@ -145,7 +140,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = React.memo(
145140
toggleFullscreen,
146141
showTabs,
147142
linkType,
148-
isInTabsView,
149143
updateTabInfo,
150144
addToBrowserHistory,
151145
bookmarks,
@@ -258,8 +252,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = React.memo(
258252
(state: RootState) => state.browser.whitelist,
259253
);
260254

261-
const isFocused = useIsFocused();
262-
263255
/**
264256
* Checks if a given url or the current url is the homepage
265257
*/
@@ -685,60 +677,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = React.memo(
685677
],
686678
);
687679

688-
const checkTabPermissions = useCallback(() => {
689-
if (isPerDappSelectedNetworkEnabled()) {
690-
return;
691-
}
692-
693-
if (!(isFocused && !isInTabsView && isTabActive)) {
694-
return;
695-
}
696-
if (!resolvedUrlRef.current) return;
697-
const hostname = new URLParse(resolvedUrlRef.current).origin;
698-
const permissionsControllerState =
699-
Engine.context.PermissionController.state;
700-
const permittedAccounts = getPermittedCaipAccountIdsByHostname(
701-
permissionsControllerState,
702-
hostname,
703-
);
704-
705-
const isConnected = permittedAccounts.length > 0;
706-
707-
if (isConnected) {
708-
let permittedChains = [];
709-
try {
710-
const caveat = getCaip25Caveat(hostname);
711-
permittedChains = caveat ? getPermittedEthChainIds(caveat.value) : [];
712-
713-
const currentChainId = toHex(activeChainId);
714-
const isCurrentChainIdAlreadyPermitted =
715-
permittedChains.includes(currentChainId);
716-
717-
if (!isCurrentChainIdAlreadyPermitted) {
718-
navigation.navigate(Routes.MODAL.ROOT_MODAL_FLOW, {
719-
screen: Routes.SHEET.ACCOUNT_PERMISSIONS,
720-
params: {
721-
isNonDappNetworkSwitch: true,
722-
hostInfo: {
723-
metadata: {
724-
origin: hostname,
725-
},
726-
},
727-
isRenderedAsBottomSheet: true,
728-
initialScreen: AccountPermissionsScreens.Connected,
729-
},
730-
});
731-
}
732-
} catch (e) {
733-
const checkTabPermissionsError = e as Error;
734-
Logger.error(
735-
checkTabPermissionsError,
736-
'Error in checkTabPermissions',
737-
);
738-
}
739-
}
740-
}, [activeChainId, navigation, isFocused, isInTabsView, isTabActive]);
741-
742680
/**
743681
* Handles state changes for when the url changes
744682
*/
@@ -781,10 +719,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = React.memo(
781719
name: siteInfo.title,
782720
url: getMaskedUrl(siteInfo.url, sessionENSNamesRef.current),
783721
});
784-
785-
if (!isPerDappSelectedNetworkEnabled()) {
786-
checkTabPermissions();
787-
}
788722
},
789723
[
790724
isUrlBarFocused,
@@ -794,7 +728,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = React.memo(
794728
updateTabInfo,
795729
addToBrowserHistory,
796730
navigation,
797-
checkTabPermissions,
798731
],
799732
);
800733

@@ -1206,12 +1139,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = React.memo(
12061139
[linkType],
12071140
);
12081141

1209-
useEffect(() => {
1210-
if (!isPerDappSelectedNetworkEnabled()) {
1211-
checkTabPermissions();
1212-
}
1213-
}, [checkTabPermissions, isFocused, isInTabsView, isTabActive]);
1214-
12151142
const handleEnsUrl = useCallback(
12161143
async (ens: string) => {
12171144
try {

app/components/Views/MultichainAccounts/MultichainAccountPermissions/MultichainAccountPermissions.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ jest.mock(
227227
);
228228

229229
jest.mock('../../../../util/networks', () => ({
230-
isPerDappSelectedNetworkEnabled: jest.fn(() => true),
231230
getNetworkImageSource: jest.fn(() => 'mock-image-source'),
232231
}));
233232

0 commit comments

Comments
 (0)