Skip to content
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

chore: Use network-specific smart transaction feature flags #30094

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions shared/modules/selectors/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,33 @@ describe('Selectors', () => {
},
);

jestIt(
'returns false if feature flag is disabled for BSC, not a HW and is BSC network with a default RPC URL',
() => {
const state = createSwapsMockStore();
state.metamask.swapsState.swapsFeatureFlags = {
...state.metamask.swapsState.swapsFeatureFlags,
bsc: {
...state.metamask.swapsState.swapsFeatureFlags.bsc,
smartTransactions: {
extensionActive: false,
},
},
};
const newState = {
...state,
metamask: {
...state.metamask,
...mockNetworkState({
chainId: CHAIN_IDS.BSC,
rpcUrl: 'https://bsc-dataseed.binance.org/',
}),
},
};
expect(getSmartTransactionsEnabled(newState)).toBe(false);
},
);

jestIt(
'returns false if feature flag is enabled, not a HW and is BSC network with a non-default RPC URL',
() => {
Expand Down
6 changes: 4 additions & 2 deletions shared/modules/selectors/smart-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
// eslint-disable-next-line import/no-restricted-paths
} from '../../../ui/selectors/selectors'; // TODO: Migrate shared selectors to this file.
import { isProduction } from '../environment';
import { getFeatureFlagsByChainId } from './feature-flags';
import { getCurrentChainId, NetworkState } from './networks';

export type SmartTransactionsMetaMaskState = {
Expand Down Expand Up @@ -156,10 +157,11 @@ export const getSmartTransactionsEnabled = (
state: SmartTransactionsMetaMaskState & NetworkState,
): boolean => {
const supportedAccount = accountSupportsSmartTx(state);
// @ts-expect-error Smart transaction selector types does not match controller state
const featureFlagsByChainId = getFeatureFlagsByChainId(state);
// TODO: Create a new proxy service only for MM feature flags.
const smartTransactionsFeatureFlagEnabled =
state.metamask.swapsState?.swapsFeatureFlags?.smartTransactions
?.extensionActive;
featureFlagsByChainId?.smartTransactions?.extensionActive;
const smartTransactionsLiveness =
state.metamask.smartTransactionsState?.liveness;
return Boolean(
Expand Down
5 changes: 5 additions & 0 deletions test/jest/mock-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ export const createSwapsMockStore = () => {
extensionReturnTxHashAsap: false,
},
},
bsc: {
extensionActive: true,
mobileActive: false,
smartTransactions: {},
dan437 marked this conversation as resolved.
Show resolved Hide resolved
},
smartTransactions: {
mobileActive: true,
extensionActive: true,
Expand Down
Loading