-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d944f8e
chore: add remote feature flag for multichain accounts
gantunesr 6244d16
fix: lint
gantunesr b1e466e
test: update unit tests
gantunesr ee8a2c1
fix: use u flag in regex
gantunesr 7701868
Merge branch 'main' into gar/chore/multichain-accounts-ff
gantunesr 8021ab9
chore: update feature flag
gantunesr ed6c928
chore: refactor
gantunesr 6a14232
chore: add break
gantunesr 1beaf8c
chore: ignore unused vars warning
gantunesr df0fc64
chore: lint
gantunesr a97efef
refactor: use semver
gantunesr 9401614
chore: validate enableMultichainAccounts ff
gantunesr be6d599
chore: get version from packagejson
gantunesr 5eb39a3
refactor: use createDeepEqualSelector
gantunesr 44e143c
chore: apply feedback
gantunesr 7a0be39
chore: remove createDeepEqualSelector
gantunesr 926a951
chore: remove logs
gantunesr 2adc168
chore: remove log
gantunesr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { type RemoteFeatureFlagsState } from '../remote-feature-flags'; | ||
import { | ||
type MultichainAccountsFeatureFlag, | ||
getIsMultichainAccountsState1Enabled, | ||
getIsMultichainAccountsState2Enabled, | ||
} from './feature-flags'; | ||
|
||
jest.mock('../../../package.json', () => ({ | ||
packageJson: { | ||
version: '12.0.0', | ||
}, | ||
})); | ||
|
||
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); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
// We can ignore the unused vars warning while the flag is not active | ||
|
||
import { | ||
Infer, | ||
object, | ||
boolean, | ||
nullable, | ||
string, | ||
assert, | ||
} from '@metamask/superstruct'; | ||
import semver from 'semver'; | ||
import packageJson from '../../../package.json'; | ||
import { | ||
getRemoteFeatureFlags, | ||
type RemoteFeatureFlagsState, | ||
} from '../remote-feature-flags'; | ||
import { createDeepEqualSelector } from '../../../shared/modules/selectors/util'; | ||
|
||
/** | ||
* Feature flag structure for multichain accounts features | ||
*/ | ||
const MultichainAccountsFeatureFlag = object({ | ||
enabled: boolean(), | ||
featureVersion: nullable(string()), | ||
minimumVersion: nullable(string()), | ||
}); | ||
|
||
/** | ||
* Feature flag type for multichain accounts features | ||
*/ | ||
export type MultichainAccountsFeatureFlag = Infer< | ||
typeof MultichainAccountsFeatureFlag | ||
>; | ||
|
||
// TODO: Update the value to the decided version multichain accounts will be released | ||
const APP_VERSION = packageJson.version; | ||
const FEATURE_VERSION_1 = '1'; | ||
const FEATURE_VERSION_2 = '2'; | ||
|
||
/** | ||
* Checks if the multichain accounts feature is enabled for a given state and feature version. | ||
* | ||
* @param state - The MetaMask state object | ||
* @param featureVersion - The specific feature version to check | ||
* @returns boolean - True if the feature is enabled for the given state and version, false otherwise. | ||
*/ | ||
export const isMultichainAccountsFeatureEnabled = ( | ||
state: RemoteFeatureFlagsState, | ||
featureVersion: string, | ||
) => { | ||
const { enableMultichainAccounts } = getRemoteFeatureFlags(state); | ||
ccharly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try { | ||
assert(enableMultichainAccounts, MultichainAccountsFeatureFlag); | ||
} catch (error) { | ||
console.error(error); | ||
return false; | ||
} | ||
|
||
const { | ||
enabled, | ||
featureVersion: currentFeatureVersion, | ||
minimumVersion, | ||
} = enableMultichainAccounts; | ||
return ( | ||
enabled && | ||
currentFeatureVersion && | ||
minimumVersion && | ||
currentFeatureVersion === featureVersion && | ||
semver.gt(minimumVersion, APP_VERSION) | ||
gantunesr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
}; | ||
|
||
/** | ||
* Selector to check if the multichain accounts feature is enabled for state 1. | ||
*/ | ||
export const getIsMultichainAccountsState1Enabled = createDeepEqualSelector( | ||
(state: RemoteFeatureFlagsState) => state, | ||
gantunesr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(state) => { | ||
return false; | ||
// TODO: Uncomment this when the feature is ready for release | ||
// return isMultichainAccountsFeatureEnabled(state, FEATURE_VERSION_1); | ||
}, | ||
); | ||
|
||
/** | ||
* Selector to check if the multichain accounts feature is enabled for state 2. | ||
*/ | ||
export const getIsMultichainAccountsState2Enabled = createDeepEqualSelector( | ||
(state: RemoteFeatureFlagsState) => state, | ||
gantunesr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(state) => { | ||
return false; | ||
// TODO: Uncomment this when the feature is ready for release | ||
// return isMultichainAccountsFeatureEnabled(state, FEATURE_VERSION_2); | ||
}, | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './feature-flags'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.