feat: enable STX by default with migration and notification#12857
Conversation
- Enable STX for new users or those that have not enabled in settings - Preserves settings for users who explicitly opted out and have existing STX transactions - Adds a migration flag to track this change
…ror messages using team's established pattern.
- Mock Sentry error handling ensuring we can track when errors are captured - Setup `beforeEach()` restore/reset for all mocks - Define test cases for error handling - Each case has: invalid input state, expected error message, and description - Invalid States Test: how migration handles malformed data - Runs each invalid state test case - Verifies: Invalid state returns unchanged, Error is captured by Sentry, Error message matches expected format Also, Setup first test to ensure STX is enabled and migration flag is set when undefined opt-in status
- Null status test, similar to undefined opt-in status test - Tests migration with null status - Verifies that STX is enabled and migration flag is set
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
- create opt-out test - tests that users explicit opt-out is respected when STX transactions exist - verifies migration flag is set but preference is unchanged
- create opt-out test - tests that users explicit opt-out is respected when STX transactions exist - verifies migration flag is set but preference is unchanged
- tests that opt-out is overridden when user has no transaction history - verifies migration flag is set and preference is changed
- added test for initializing preferences - added test for when STX is already enabled - use `merge` with `initialRootState` consistently across all tests
- uses redux selectors to access the state - checks flags we need (opt-in status and migration applied) - Returns (isEnabled, isMigrationApplied) for our banner to use - Provides proper TypeScript types
- check default states - ensure proper state reading - handle partial states
- test conditional rendering - check text content - ensure close button functionality works - ensure link functionality works
- useSmartTransactionsEnabled enhanced to include dismiss functionality - add a dispatch action to update the smartTransactionsOptInStatus - remove external onClose prop from SmartTransactionsEnabledBanner in favor of using the hook's dismiss functionality - update component and hook tests to account for new functionality These changes require more changes in the next commit to add the smartTransactionsBannerDismissed field to our PreferencesController state as well to add a reducer case for SET_SMART_TRANSACTIONS_BANNER_DISMISSED and update any types/interfaces in our codebase that reference PreferencesController.
…nitialize it. Update the migration and test to account for the new change
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12857 +/- ##
==========================================
+ Coverage 61.58% 61.87% +0.29%
==========================================
Files 1953 1977 +24
Lines 43442 43884 +442
Branches 5835 5929 +94
==========================================
+ Hits 26753 27153 +400
- Misses 14905 14929 +24
- Partials 1784 1802 +18 ☔ View full report in Codecov by Sentry. |
|
I have read the CLA Document and I hereby sign the CLA |
|
…sk/metamask-mobile into feat/enable-stx-migration
|
|
|
|
I have read the CLA Document and I hereby sign the CLA |
|



Description
This PR enables Smart Transactions (STX) in MetaMask Mobile by default through migration number 68 for users who have either opted out with notification if the Smart Transactions toggle has been enabled for them.
Docs: SmartTransactionsMigrationBanner
How it works (if user does not have STX enabled or prior STX Transaction history:
In the case a user migrates from a previous version of the Mobile app and the migration runs and sets STX toggle "ON" in
Settings > Advanced > Smart Transactions, they will receive an Alert on transaction confirmation screens until dismissed, or by clicking on the "Higher success rates" link within the alert. If they click on the link in the banner alert they will get sent to: What is 'Smart Transactions'? for more information. When returning to the confirmation they just navigated from the banner alert should not show and should never show again.Edge Cases:
If a user is new and setting up a wallet for the first time, they will not receive the Banner Alert. If a user imports a new wallet during a fresh install of the extension on a new browser or recovers a wallet, it's possible they may not see the alert if STX was on in a previous install. The STX Banner Alert is dismissed and will not show again if a user is in the state to get shown the banner and toggles STX off independently even if they do not physically dismiss the STX Banner Alert.
Migration Logic:
smartTransactionsOptInStatusisnull(new/never interacted)UI Components:
Implements
SmartTransactionsMigrationBannercomponent for user notification.The notification system bridges the migration changes with the UI, ensuring users are informed of the STX enablement while maintaining their ability to opt out through settings.
Target release: release-7.39.0
Affected user base: ~5.7M users who previously opted out of STX but have no STX activity.
Running Unit Tests
Migration 067 test:
yarn jest "./app/store/migrations/068.test.ts" --no-cacheSmartTransactions Migration Banner component test:
yarn jest "./app/components/Views/confirmations/components/SmartTransactionsMigrationBanner/SmartTransactionsMigrationBanner.test.ts" --no-cacheQuotesView component test:
yarn jest "./app/components/UI/Swaps/QuotesView.test.ts" --no-cacheSendFlow component test:
yarn jest "./app/components/Views/confirmations/SendFlow/Confirm/index.test.tsx" --no-cacheTransactionReview component test:
yarn jest "./app/components/Views/confirmations/components/TransactionReview/index.test.tsx" --no-cachManual testing steps
Test Migration (using a wallet/account with no STX Transactions)
Start with an older repo version:
Terminal #1
yarn setup && yarn watchTerminal #2
Import or setup a wallet without STX transactions, launch the wallet (do not enable STX if prompted), check that toggle is OFF in:
Settings > Advanced > Smart TransactionsSwitch to feature branch and run app:
Terminal #1
yarn setup && yarn watchTerminal #2
0.0001ETH7 Ensure that Smart Transactions Banner Alert IS showing
0.0001ETHScreenshots/Recordings
The following before and after screenshots show the state of varying Mobile views like Swaps, Send, Contract Deployment, Signing, etc.. that show the
SmartTransactionsMigrationBannercomponent and how it's displayed on each view. The before shows the view without the component being rendered and the after (after migration and before dismissal) show the component as it will appear for the user on each view.Before
After
Pre-merge author checklist
Pre-merge reviewer checklist