Skip to content

chore: add remote feature flag for multichain accounts #33112

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

Merged
merged 18 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions ui/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './accounts';
export * from './remote-feature-flags';
export * from './origin-throttling';
export * from './multichain/networks';
export * from './multichain-accounts';
42 changes: 42 additions & 0 deletions ui/selectors/multichain-accounts/feature-flags.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { type RemoteFeatureFlagsState } from '../remote-feature-flags';
import {
type MultichainAccountsFeatureFlag,
getIsMultichainAccountsState1Enabled,
getIsMultichainAccountsState2Enabled,
} from './feature-flags';

type TestState = RemoteFeatureFlagsState & {
metamask: {
remoteFeatureFlags: {
enableMultichainAccounts: MultichainAccountsFeatureFlag;
};
};
};

const disabledStateMock: MultichainAccountsFeatureFlag = {
enabled: false,
featureVersion: null,
minimumVersion: null,
};

const mockState: TestState = {
metamask: {
remoteFeatureFlags: {
enableMultichainAccounts: disabledStateMock,
},
},
};

describe('Multichain Accounts Feature Flags', () => {
describe('getIsMultichainAccountsState1Enabled', () => {
it('returns false for disabled state', () => {
expect(getIsMultichainAccountsState1Enabled(mockState)).toBe(false);
});
});

describe('getIsMultichainAccountsState2Enabled', () => {
it('returns false for disabled state', () => {
expect(getIsMultichainAccountsState2Enabled(mockState)).toBe(false);
});
});
});
93 changes: 93 additions & 0 deletions ui/selectors/multichain-accounts/feature-flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {
getRemoteFeatureFlags,
type RemoteFeatureFlagsState,
} from '../remote-feature-flags';

/**
*
*/
export type MultichainAccountsFeatureFlag = {
enabled: boolean;
featureVersion: string | null;
minimumVersion: string | null;
};

// TODO: Update the value to the decided version multichain accounts will be released
const MINIMUM_SUPPORTED_VERSION = null;
const FEATURE_VERSION_1 = '1';
const FEATURE_VERSION_2 = '2';

/**
* Compare is the version1 is greater than or equal to version2
*
* @param version1 - The first version string to compare.
* @param version2 - The second version string to compare.
* @returns boolean - True if version1 is greater than or equal to version2, false otherwise.
*/
const compareVersions = (version1: string, version2: string) => {
const regex = /^\d+\.\d+\.\d+$/u;
if (!regex.test(version1) || !regex.test(version2)) {
return false; // Invalid version format
}

const v1 = version1.split('.').map(Number);
const v2 = version2.split('.').map(Number);

for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
const num1 = v1[i] || 0;
const num2 = v2[i] || 0;

if (num1 > num2) {
return true;
}
if (num1 < num2) {
return false;
}
}

return true; // Versions are equal
};

/**
* Checks if the multichain accounts feature is enabled for state 1.
*
* @param state - The MetaMask state object
* @returns boolean - True if the feature is enabled for state 1, false otherwise.
*/
export const getIsMultichainAccountsState1Enabled = (
state: RemoteFeatureFlagsState,
) => {
const { enableMultichainAccounts } = getRemoteFeatureFlags(state);
const { enabled, featureVersion, minimumVersion } =
enableMultichainAccounts as MultichainAccountsFeatureFlag;
return (
enabled &&
featureVersion &&
minimumVersion &&
featureVersion === FEATURE_VERSION_1 &&
// @ts-expect-error - we can ignore the error for passing MINIMUM_SUPPORTED_VERSION as null
compareVersions(minimumVersion, MINIMUM_SUPPORTED_VERSION)
);
};

/**
* Checks if the multichain accounts feature is enabled for state 1.
*
* @param state - The MetaMask state object
* @returns boolean - True if the feature is enabled for state 1, false otherwise.
*/
export const getIsMultichainAccountsState2Enabled = (
state: RemoteFeatureFlagsState,
) => {
const { enableMultichainAccounts } = getRemoteFeatureFlags(state);
const { enabled, featureVersion, minimumVersion } =
enableMultichainAccounts as MultichainAccountsFeatureFlag;
return (
enabled &&
featureVersion &&
minimumVersion &&
featureVersion === FEATURE_VERSION_2 &&
// @ts-expect-error - we can ignore the error for passing MINIMUM_SUPPORTED_VERSION as null
compareVersions(minimumVersion, MINIMUM_SUPPORTED_VERSION)
);
};
1 change: 1 addition & 0 deletions ui/selectors/multichain-accounts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './feature-flags';
Loading