Skip to content
Open
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
feat(STX-331): migrate STX flags to smart-transactions-controller
  • Loading branch information
rarquevaux committed Dec 12, 2025
commit 27e2f33ce45137694cd03c3c0363a4e298c13063
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- **BREAKING**: The controller now reads feature flags directly from `RemoteFeatureFlagController` via the messenger instead of using the `getFeatureFlags` callback
- Clients must configure the following as allowed actions in the controller messenger:
- `RemoteFeatureFlagController:getState`
- `ErrorReportingService:captureException` (for reporting validation errors to Sentry)
- Clients must configure `RemoteFeatureFlagController:stateChange` as an allowed event
- The `getFeatureFlags` constructor option is now deprecated and ignored

## [21.0.0]

### Changed
Expand Down
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,53 @@ Run `yarn test` to run the tests once. To run tests on file changes, run `yarn t

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

### Feature Flags

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.

The flag in LaunchDarkly is named `smartTransactionsNetworks`.

#### Adding a New Flag

1. **Add the field to the schema** in `src/utils/validators.ts`:

```typescript
export const SmartTransactionsNetworkConfigSchema = type({
// ... existing fields
myNewFlag: optional(boolean()),
});
```

The `SmartTransactionsNetworkConfig` type is automatically inferred from this schema.

2. **Add default value** in `src/constants.ts` under `DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS`:

These values should be defensive. They are applied when the remote config is invalid or does not exist for a network.
It disables smart transaction.

```typescript
export const DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS = {
default: {
// ... existing defaults
myNewFlag: false,
},
};
```

3. **Use in clients** via the exported selectors:

```typescript
import { selectSmartTransactionsFeatureFlagsForChain } from '@metamask/smart-transactions-controller';

const chainConfig = selectSmartTransactionsFeatureFlagsForChain(
state,
'0x1',
);
if (chainConfig.myNewFlag) {
// Feature is enabled
}
```

### Release & Publishing

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.
Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,27 @@
"@metamask/eth-query": "^4.0.0",
"@metamask/messenger": "^0.3.0",
"@metamask/polling-controller": "^15.0.0",
"@metamask/superstruct": "^3.1.0",
"@metamask/utils": "^11.0.0",
"bignumber.js": "^9.0.1",
"fast-json-patch": "^3.1.0",
"lodash": "^4.17.21"
"lodash": "^4.17.21",
"reselect": "^5.1.1"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.18.2",
"@lavamoat/allow-scripts": "^3.2.1",
"@lavamoat/preinstall-always-fail": "^2.1.0",
"@metamask/auto-changelog": "^3.1.0",
"@metamask/error-reporting-service": "^3.0.0",
"@metamask/eslint-config": "^12.2.0",
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^12.1.0",
"@metamask/gas-fee-controller": "^22.0.0",
"@metamask/json-rpc-engine": "^10.0.1",
"@metamask/network-controller": "^25.0.0",
"@metamask/remote-feature-flag-controller": "^2.0.0",
"@metamask/transaction-controller": "^61.0.0",
"@ts-bridge/cli": "^0.6.3",
"@types/jest": "^26.0.24",
Expand All @@ -93,7 +98,9 @@
"typescript": "~4.8.4"
},
"peerDependencies": {
"@metamask/error-reporting-service": "^3.0.0",
"@metamask/network-controller": "^25.0.0",
"@metamask/remote-feature-flag-controller": "^2.0.0",
"@metamask/transaction-controller": "^61.0.0"
},
"peerDependenciesMeta": {
Expand All @@ -108,9 +115,6 @@
},
"@metamask/gas-fee-controller": {
"optional": true
},
"@metamask/remote-feature-flag-controller": {
"optional": true
}
},
"packageManager": "[email protected]",
Expand Down
Loading
Loading