Skip to content

Commit e48abe6

Browse files
authored
chore: Use network-specific smart transaction feature flags (#30094)
## **Description** If there are network-specific feature flags for smart transactions, they will take priority over shared smart transaction feature flags. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/30094?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Turn off some feature flag which is network-specific for smart transactions (e.g. `bsc.smartTransactions.extensionActive = false`) 2. See that it's being used over a shared one (`smartTransactions.extensionActive`) ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] 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). - [ ] 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-extension/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.
1 parent a381650 commit e48abe6

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

shared/modules/selectors/index.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,33 @@ describe('Selectors', () => {
237237
},
238238
);
239239

240+
jestIt(
241+
'returns false if feature flag is disabled for BSC, not a HW and is BSC network with a default RPC URL',
242+
() => {
243+
const state = createSwapsMockStore();
244+
state.metamask.swapsState.swapsFeatureFlags = {
245+
...state.metamask.swapsState.swapsFeatureFlags,
246+
bsc: {
247+
...state.metamask.swapsState.swapsFeatureFlags.bsc,
248+
smartTransactions: {
249+
extensionActive: false,
250+
},
251+
},
252+
};
253+
const newState = {
254+
...state,
255+
metamask: {
256+
...state.metamask,
257+
...mockNetworkState({
258+
chainId: CHAIN_IDS.BSC,
259+
rpcUrl: 'https://bsc-dataseed.binance.org/',
260+
}),
261+
},
262+
};
263+
expect(getSmartTransactionsEnabled(newState)).toBe(false);
264+
},
265+
);
266+
240267
jestIt(
241268
'returns false if feature flag is enabled, not a HW and is BSC network with a non-default RPC URL',
242269
() => {

shared/modules/selectors/smart-transactions.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
// eslint-disable-next-line import/no-restricted-paths
1212
} from '../../../ui/selectors/selectors'; // TODO: Migrate shared selectors to this file.
1313
import { isProduction } from '../environment';
14+
import { getFeatureFlagsByChainId } from './feature-flags';
1415
import { getCurrentChainId, NetworkState } from './networks';
1516

1617
export type SmartTransactionsMetaMaskState = {
@@ -156,10 +157,11 @@ export const getSmartTransactionsEnabled = (
156157
state: SmartTransactionsMetaMaskState & NetworkState,
157158
): boolean => {
158159
const supportedAccount = accountSupportsSmartTx(state);
160+
// @ts-expect-error Smart transaction selector types does not match controller state
161+
const featureFlagsByChainId = getFeatureFlagsByChainId(state);
159162
// TODO: Create a new proxy service only for MM feature flags.
160163
const smartTransactionsFeatureFlagEnabled =
161-
state.metamask.swapsState?.swapsFeatureFlags?.smartTransactions
162-
?.extensionActive;
164+
featureFlagsByChainId?.smartTransactions?.extensionActive;
163165
const smartTransactionsLiveness =
164166
state.metamask.smartTransactionsState?.liveness;
165167
return Boolean(

test/jest/mock-store.js

+5
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ export const createSwapsMockStore = () => {
398398
extensionReturnTxHashAsap: false,
399399
},
400400
},
401+
bsc: {
402+
extensionActive: true,
403+
mobileActive: false,
404+
smartTransactions: {},
405+
},
401406
smartTransactions: {
402407
mobileActive: true,
403408
extensionActive: true,

0 commit comments

Comments
 (0)