Skip to content

Commit b4c03a2

Browse files
committed
fix(STX-331): migrate STX flags to smart-transactions-controller
1 parent bfe8e9c commit b4c03a2

18 files changed

Lines changed: 2163 additions & 67 deletions

CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Changed
11+
12+
- **BREAKING**: The controller now reads feature flags directly from `RemoteFeatureFlagController` via the messenger instead of using the `getFeatureFlags` callback
13+
- Clients must configure the following as allowed actions in the controller messenger:
14+
- `RemoteFeatureFlagController:getState`
15+
- `ErrorReportingService:captureException` (for reporting validation errors to Sentry)
16+
- Clients must configure `RemoteFeatureFlagController:stateChange` as an allowed event
17+
- The `getFeatureFlags` constructor option is now deprecated and ignored
18+
1019
## [20.1.0]
1120

1221
### Added

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,53 @@ Run `yarn test` to run the tests once. To run tests on file changes, run `yarn t
2525

2626
Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues.
2727

28+
### Feature Flags
29+
30+
Smart transactions feature flags are managed via `RemoteFeatureFlagController` (LaunchDarkly). The configuration uses a `default` remote object for global settings and chain-specific overrides keyed by hex chain ID.
31+
32+
The flag in LaunchDarkly is named `smartTransactionsNetworks`.
33+
34+
#### Adding a New Flag
35+
36+
1. **Add the field to the schema** in `src/utils/validators.ts`:
37+
38+
```typescript
39+
export const SmartTransactionsNetworkConfigSchema = type({
40+
// ... existing fields
41+
myNewFlag: optional(boolean()),
42+
});
43+
```
44+
45+
The `SmartTransactionsNetworkConfig` type is automatically inferred from this schema.
46+
47+
2. **Add default value** in `src/constants.ts` under `DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS`:
48+
49+
These values should be defensive. They are applied when the remote config is invalid or does not exist for a network.
50+
It disables smart transaction.
51+
52+
```typescript
53+
export const DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS = {
54+
default: {
55+
// ... existing defaults
56+
myNewFlag: false,
57+
},
58+
};
59+
```
60+
61+
3. **Use in clients** via the exported selectors:
62+
63+
```typescript
64+
import { selectSmartTransactionsFeatureFlagsForChain } from '@metamask/smart-transactions-controller';
65+
66+
const chainConfig = selectSmartTransactionsFeatureFlagsForChain(
67+
state,
68+
'0x1',
69+
);
70+
if (chainConfig.myNewFlag) {
71+
// Feature is enabled
72+
}
73+
```
74+
2875
### Release & Publishing
2976

3077
The project follows the same release process as the other libraries in the MetaMask organization. The GitHub Actions [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) are used to automate the release process; see those repositories for more information about how they work.

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)