Skip to content
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

feat: enable STX by default with migration and notification #12857

Open
wants to merge 121 commits into
base: main
Choose a base branch
from

Conversation

httpJunkie
Copy link

@httpJunkie httpJunkie commented Jan 8, 2025

Description

This PR enables Smart Transactions (STX) in MetaMask Mobile by default through migration number #67 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:

  • Upon Migration STX is enabled in Settings:
  • A banner alert will displays on the following transaction confirmations
    • Send Confirmation flow
    • Swaps confirmation flow
    • Contract deployment & interactions (deploy, minting, etc.)

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:

  1. If smartTransactionsOptInStatus is null (new/never interacted)
  • Sets status to true
  • Enables notification flag
  1. If status is false (previously opted out):
  • With no Ethereum Mainnet STX activity: Sets to true with notification
  • With existing Mainnet STX activity: Preserves user preference
  1. If status is true: No changes needed

UI Components:

Implements SmartTransactionsMigrationBanner component 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/067.test.ts" --no-cache

SmartTransactions Migration Banner component test:

yarn jest "./app/components/Views/confirmations/components/SmartTransactionsMigrationBanner/SmartTransactionsMigrationBanner.test.ts" --no-cache

QuotesView component test:

yarn jest "./app/components/UI/Swaps/QuotesView.test.ts" --no-cache

SendFlow component test:

yarn jest "./app/components/Views/confirmations/SendFlow/Confirm/index.test.tsx" --no-cache

TransactionReview component test:

yarn jest "./app/components/Views/confirmations/components/TransactionReview/index.test.tsx" --no-cach

Manual testing steps

Test Migration (using a wallet/account with no STX Transactions)
Start with an older repo version:

Terminal #1

git checkout tags/v7.32.0
yarn setup && yarn watch

Terminal #2

yarn start:ios
  1. 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 Transactions

  2. Switch to feature branch and run app:

Terminal #1

git checkout feat/enable-stx-migration
yarn setup && yarn watch

Terminal #2

yarn start:ios
  1. Test that Alert only shows during confirmation screens for transactions and contract interactions, but not for signing
  2. Create a Send transaction to your own wallet for 0.0001 ETH
  3. Ensure that Smart Transactions Banner Alert IS showing
  4. Start a Swaps transaction on Ethereum Mainnet
    7 Ensure that Smart Transactions Banner Alert IS showing
  5. Try several Signs (ETH Sign, Personal Sign, Sign Typed Data, etc..) and ensure the STX Banner Alert does not show on those confirmations screens.
  6. Ensure that the Smart Transactions Banner Alert is only showing on STX supported chains:
  • Ethereum
  • Sepolia
  1. Ensure that link in alert "Higher success rates" link (inspect) goes to: What is 'Smart Transactions'?
  2. Dismiss the Smart Transactions Banner Alert
  3. Create a Send transaction to your own wallet for 0.0001 ETH
  4. Ensure that Smart Transactions Banner Alert IS NOT showing
  • Note: The Smart Transactions Banner Alert should not show up on chains like Linea which are not supported

Screenshots/Recordings

The following before and after screenshots show the state of varying Mobile views like Swaps, Send, Contract Deployment, Signing, etc.. that show the SmartTransactionsMigrationBanner component 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

01-stx_before 02-send_before 02-sendLegacy_before 04-signTypedDataV4_before 06-contractInteraction_before 05-contractDeployment_before

After

01-stx_after 02-send_after 02-sendLegacy_after 04-signTypedDataV4_after 06-contractInteraction_after 05-contractDeployment_after 09-swap_after 09-swap_after

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

- 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
@httpJunkie httpJunkie added team-confirmations Push issues to confirmations team team-transactions Transactions team labels Jan 8, 2025
@httpJunkie httpJunkie self-assigned this Jan 8, 2025
@httpJunkie httpJunkie requested a review from a team as a code owner January 8, 2025 06:09
@httpJunkie httpJunkie marked this pull request as draft January 8, 2025 06:09
Copy link
Contributor

github-actions bot commented Jan 8, 2025

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.

@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Jan 8, 2025
- 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
@httpJunkie httpJunkie added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Feb 13, 2025
@MetaMask MetaMask deleted a comment from github-actions bot Feb 13, 2025
@httpJunkie httpJunkie added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Feb 13, 2025
@httpJunkie
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@httpJunkie httpJunkie added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Feb 13, 2025
@httpJunkie httpJunkie added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Feb 13, 2025
Copy link
Contributor

github-actions bot commented Feb 13, 2025

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 2bfce5e
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/644eb0f2-7f92-48d9-975c-66ee9354178f

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@MetaMask MetaMask deleted a comment from github-actions bot Feb 13, 2025
@@ -117,6 +117,9 @@ const createStyles = (colors) =>
marginHorizontal: 16,
marginBottom: -8,
},
SmartTransactionsMigrationBanner: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant for this name to be camelCased like the rest of the styles?

Copy link
Author

@httpJunkie httpJunkie Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, ty... this was due to a find and replace. I appreciate it.

@httpJunkie httpJunkie dismissed stale reviews from dan437 and OGPoyraz via 2c90d21 February 13, 2025 15:08
@httpJunkie httpJunkie added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Feb 13, 2025
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Feb 13, 2025
@httpJunkie httpJunkie added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Feb 13, 2025
Copy link
Contributor

github-actions bot commented Feb 13, 2025

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 9d0fb79
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/18ccdcc2-d38b-4d72-8665-b093021538e2

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@MetaMask MetaMask deleted a comment from github-actions bot Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
INVALID-PR-TEMPLATE PR's body doesn't match template release-7.41.0 Issue or pull request that will be included in release 7.41.0 Run Smoke E2E Triggers smoke e2e on Bitrise team-confirmations Push issues to confirmations team team-transactions Transactions team
Projects
Status: Needs more work from the author
Development

Successfully merging this pull request may close these issues.

7 participants