Skip to content

Commit fa29d03

Browse files
committed
feat(STX-331): migrate smart transaction feature flags in the controller
1 parent bfe8e9c commit fa29d03

18 files changed

Lines changed: 2040 additions & 67 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
- **BREAKING**: The controller now reads feature flags directly from `RemoteFeatureFlagController` via the messenger instead of using the `getFeatureFlags` callback
12+
- Clients must configure `RemoteFeatureFlagController:getState` as an allowed action in the controller messenger
13+
- The `getFeatureFlags` constructor option is now deprecated and ignored
14+
1015
## [20.1.0]
1116

1217
### Added

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,45 @@ or
2424
Run `yarn test` to run the tests once. To run tests on file changes, run `yarn test:watch`.
2525

2626
Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues.
27+
### Feature Flags
28+
29+
Smart transactions feature flags are managed via `RemoteFeatureFlagController` (LaunchDarkly). The configuration uses a `default` object for global settings and chain-specific overrides keyed by hex chain ID.
30+
31+
#### Adding a New Flag
32+
33+
1. **Add the field to the schema** in `src/utils/validators.ts`:
34+
35+
```typescript
36+
export const SmartTransactionsNetworkConfigSchema = type({
37+
// ... existing fields
38+
myNewFlag: optional(boolean()),
39+
});
40+
```
41+
42+
The `SmartTransactionsNetworkConfig` type is automatically inferred from this schema.
43+
44+
2. **Add default value** in `src/constants.ts` under `DEFAULT_SMART_TRANSACTIONS_FEATURE_FLAGS`:
45+
46+
```typescript
47+
export const DEFAULT_SMART_TRANSACTIONS_FEATURE_FLAGS = {
48+
default: {
49+
// ... existing defaults
50+
myNewFlag: false,
51+
},
52+
};
53+
```
54+
55+
3. **Use in clients** via the exported selectors:
56+
57+
```typescript
58+
import { selectSmartTransactionsFeatureFlagsForChain } from '@metamask/smart-transactions-controller';
59+
60+
const chainConfig = selectSmartTransactionsFeatureFlagsForChain(state, '0x1');
61+
if (chainConfig.myNewFlag) {
62+
// Feature is enabled
63+
}
64+
```
65+
2766

2867
### Release & Publishing
2968

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,27 @@
5151
"@metamask/eth-query": "^4.0.0",
5252
"@metamask/messenger": "^0.3.0",
5353
"@metamask/polling-controller": "^15.0.0",
54+
"@metamask/superstruct": "^3.1.0",
55+
"@metamask/utils": "^11.0.0",
5456
"bignumber.js": "^9.0.1",
5557
"fast-json-patch": "^3.1.0",
56-
"lodash": "^4.17.21"
58+
"lodash": "^4.17.21",
59+
"reselect": "^5.1.1"
5760
},
5861
"devDependencies": {
5962
"@arethetypeswrong/cli": "^0.18.2",
6063
"@lavamoat/allow-scripts": "^3.2.1",
6164
"@lavamoat/preinstall-always-fail": "^2.1.0",
6265
"@metamask/auto-changelog": "^3.1.0",
66+
"@metamask/error-reporting-service": "^3.0.0",
6367
"@metamask/eslint-config": "^12.2.0",
6468
"@metamask/eslint-config-jest": "^12.1.0",
6569
"@metamask/eslint-config-nodejs": "^12.1.0",
6670
"@metamask/eslint-config-typescript": "^12.1.0",
6771
"@metamask/gas-fee-controller": "^22.0.0",
6872
"@metamask/json-rpc-engine": "^10.0.1",
6973
"@metamask/network-controller": "^25.0.0",
74+
"@metamask/remote-feature-flag-controller": "^2.0.0",
7075
"@metamask/transaction-controller": "^61.0.0",
7176
"@ts-bridge/cli": "^0.6.3",
7277
"@types/jest": "^26.0.24",
@@ -93,7 +98,9 @@
9398
"typescript": "~4.8.4"
9499
},
95100
"peerDependencies": {
101+
"@metamask/error-reporting-service": "^3.0.0",
96102
"@metamask/network-controller": "^25.0.0",
103+
"@metamask/remote-feature-flag-controller": "^2.0.0",
97104
"@metamask/transaction-controller": "^61.0.0"
98105
},
99106
"peerDependenciesMeta": {
@@ -108,9 +115,6 @@
108115
},
109116
"@metamask/gas-fee-controller": {
110117
"optional": true
111-
},
112-
"@metamask/remote-feature-flag-controller": {
113-
"optional": true
114118
}
115119
},
116120
"packageManager": "yarn@3.2.1",

0 commit comments

Comments
 (0)