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 #28854

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

Conversation

httpJunkie
Copy link

@httpJunkie httpJunkie commented Dec 2, 2024

Description

This PR enables Smart Transactions (STX) by default through migration number 135 for users who have either opted out or haven't interacted with the STX toggle, provided they have no recorded STX activity.

How it works:

  • Upon Migration 135, alert displays on transaction confirmations:
  • Legacy transaction flow
  • New transaction flow (experimental)
  • Swaps confirmation flow
  • Contract deployment
  • Contract interactions (minting, etc.)

In the case a user migrates from a previous version of the extension and the migration runs and sets STX toggle "ON" in Settings > Advanced > Smart Transactions, they will receive an STX Banner Alert on transaction confirmation screens until dismissed through a close button, or by clicking on the "Higher success rates" link within the alert that goes to: What is 'Smart Transactions'? for more information.

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 SmartTransactionsBannerAlert 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: TBD
Affected user base: ~5.7M users who previously opted out of STX but have no STX activity.


Related issues

Fixes: N/A


Running Unit Tests

Migration Test:

yarn jest app/scripts/migrations/135.test.ts --verbose

Smart Transaction Banner Component Test:

yarn jest ui/pages/confirmations/components/smart-transactions-banner-alert/smart-transactions-banner-alert.test.ts --coverage=false

Confirm Transaction base Test:

yarn jest ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.test.js --coverage=false

Preferences Controller Test:

yarn jest app/scripts/controllers/preferences-controller.test.ts --coverage=false

Transaction Alerts Component Test:

yarn jest ui/pages/confirmations/components/transaction-alerts/transaction-alerts.test.js --coverage=false

Manual testing steps

Test Migration (using a wallet/account with no STX Transactions)

  1. Switch branch: git checkout tags/v12.5.0 and run:
yarn
yarn webpack
  • Generate a dist/chrome directory
  1. In Chrome Extension Manager, "Load Unpacked" from this directory
  2. Import or setup a wallet without STX transactions, launch the wallet and choose "No Thanks" on the "Enhanced Transaction Protection" popup.
  3. Check that toggle is OFF in: Settings > Advanced > Smart Transactions
  4. Close MetaMask Extension and toggle the Extension "OFF" in the Extension Manager
  5. Switch to branch from this PR git checkout feat/enable-stx-migration
yarn
yarn webpack
  1. Open MetaMask Extension and Check that toggle is ON in: Settings > Advanced > Smart Transactions

Test STX Banner Alert that it shows on Transaction Confirmations and not Sign Confirmations)
(using new confirmations flow)

  1. Check that Improved transaction requests is ON in Settings > Experimental
  2. Open the E2E TestDapp, try several Signs (ETH Sign, Personal Sign, Sign Typed Data, etc..) and ensure the STX Banner Alert does not show on those confirmations screens.
  3. Create a Send transaction to your own wallet for 0.0001 ETH
  4. Ensure that Smart Transactions Banner Alert IS showing
  5. Start a Swaps transaction on Ethereum Mainnet
  6. Ensure that Smart Transactions Banner Alert IS showing

Test STX Banner Alert that it shows on Transaction Confirmations and not Sign Confirmations)
(using old confirmations flow)

  1. Check that Improved transaction requests is OFF in Settings > Experimental
  2. Open the E2E TestDapp, try several Signs (ETH Sign, Personal Sign, Sign Typed Data, etc..) and ensure the STX Banner Alert does not show on those confirmations screens.
  3. Create a Send transaction to your own wallet for 0.0001 ETH
  4. Ensure that Smart Transactions Banner Alert IS showing
  5. Start a Swaps transaction on Ethereum Mainnet
  6. Ensure that Smart Transactions Banner Alert IS showing
  7. Without clicking on Check that "Higher success rates" link (inspect) goes to: What is 'Smart Transactions'?
  8. Dismiss the Smart Transactions Banner Alert and set Improved transaction requests back to ON in Settings > Experimental
  9. Create a Send transaction to your own wallet for 0.0001 ETH
  10. Ensure that Smart Transactions Banner Alert IS NOT showing

Congrats, you have manually tested the happy path, now we just need to test the edge cases:

  1. Remove the extensions from Extension Manager and Repeat steps 1 to 10 above to run migration again
  2. Create a Send transaction to your own wallet for 0.0001 ETH
  3. Ensure that Smart Transactions Banner Alert IS showing
  • DO NOT DISMISS THE ALERT. Instead
  1. Open MetaMask Extension and Check that toggle is ON in: Settings > Advanced > Smart Transactions
  2. Turn it off
  3. Create a Send transaction to your own wallet for 0.0001 ETH
  4. Ensure that Smart Transactions Banner Alert IS NOT showing
  5. Perform any other Signing and/or Transaction Confirmations and ensure there are no modals that show errors and that the Banner Alert does not show anymore.

Test edge case that after STX migration runs and Banner is being shown that clicking on "Higher success rates" link:

  1. Remove the extensions from Extension Manager and Repeat steps 1 to 10 above to run migration again
  2. Create a Send transaction to your own wallet for 0.0001 ETH
  3. Ensure that Smart Transactions Banner Alert IS showing
  • DO NOT DISMISS THE ALERT WITH CLOSE BUTTON... INSTEAD
  1. Click on "Higher success rates" link and ensure that it goes to: What is 'Smart Transactions'?
  2. Open MetaMask Extension and Check that toggle is ON in: Settings > Advanced > Smart Transactions
  3. Turn it off
  4. Create a Send transaction to your own wallet for 0.0001 ETH
  5. Ensure that Smart Transactions Banner Alert IS NOT showing
  6. Perform any other Signing and/or Transaction Confirmations and ensure there are no modals that show errors and that the Banner Alert does not show anymore.

Because the NEW confirmation flow does not support alerts using hooks that are dismissible, we have used the old style Banner Alert, and it is normal for their to be some variation on where the alert shows up and it's surroundings. But overall they should look similar.


Screenshots/Recordings

Before

01-stx_before 02-legacySend_before 03-legacySwap_before 04-signTypedDataV4_before 05-contractDeployment_before 06-contractInteraction_before 07-wideSwap_before

After

01-stx_after 02-legacySend_after 03-legacySwap_after 04-signTypedDataV4_after 05-contractDeployment_after 06-contractInteraction_after 07-wideSwap_after

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs and MetaMask Extension Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests for the new behavior, covering:
    • Version update handling
    • All logic branches:
      • null opt-in status
      • false opt-in status with no STX activity
      • false opt-in status with existing STX activity
      • true opt-in status
    • Notification flag setting
    • Error handling
  • I’ve documented my code using JSDoc format where applicable.
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pulled and built the branch, ran the app, and tested the changes described above).
  • I confirm that this PR addresses all acceptance criteria described in the ticket and includes the necessary testing evidence (e.g., recordings, screenshots, or detailed descriptions).

@httpJunkie httpJunkie requested a review from a team as a code owner December 2, 2024 22:39
Copy link
Contributor

github-actions bot commented Dec 2, 2024

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.

@httpJunkie httpJunkie requested a review from a team as a code owner December 3, 2024 15:46
…transaction flows that occur when experimental/Improved transaction requests is not toggled on.
@httpJunkie httpJunkie requested a review from a team as a code owner December 4, 2024 06:17
@httpJunkie httpJunkie self-assigned this Dec 4, 2024
@httpJunkie
Copy link
Author

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

app/_locales/en/messages.json Outdated Show resolved Hide resolved
app/_locales/en/messages.json Outdated Show resolved Hide resolved
app/scripts/controllers/preferences-controller.ts Outdated Show resolved Hide resolved
app/scripts/migrations/135.test.ts Outdated Show resolved Hide resolved
app/scripts/migrations/135.test.ts Outdated Show resolved Hide resolved
app/scripts/migrations/135.ts Outdated Show resolved Hide resolved
shared/constants/alerts.ts Outdated Show resolved Hide resolved
ui/ducks/alerts/stx-migration.js Outdated Show resolved Hide resolved
@httpJunkie

This comment was marked as outdated.

…ing message. When a user dismisses the alert (via close or "Learn more"), their preference is stored and persists across transaction sessions. The dismissal is handled through the alerts state system and uses the existing setAlertEnabledness functionality. Remove comments.
…sts for the STXBannerAlert and TransactionAlerts tests.
…ion flow. Does not let me close alert or show link.
@dan437 dan437 force-pushed the feat/enable-stx-migration branch from 733d66f to 202e7d6 Compare December 19, 2024 10:19
data: {
PreferencesController?: {
preferences?: {
smartTransactionsOptInStatus?: boolean | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a reminder that smartTransactionsOptInStatus is still here twice.

describe('Swap Eth for another Token @no-mmi', function () {
// TODO: (MM-PENDING) These tests are planned for deprecation as part of swaps testing revamp
// eslint-disable-next-line mocha/no-skipped-tests
describe.skip('Swap Eth for another Token @no-mmi', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this skipped? It tests happy path for Swaps, which is the most important thing to test for Swaps. It should be only removed when a testing revamp happens and there is a replacement E2E test for this.

const notOptedInState = {
metamask: {
alertEnabledness: {
[AlertTypes.smartTransactionsMigration]: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this set to true when migration happens and STX opt in status is false? Shouldn't we set alertEnabledness to false in that case?

] !== false,
);

const smartTransactionsOptIn = useSelector(
Copy link
Contributor

Choose a reason for hiding this comment

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

There is an existing selector for this: getSmartTransactionsOptInStatusInternal

state.metamask.preferences?.smartTransactionsOptInStatus === true,
);

const smartTransactionsMigrationApplied = useSelector(
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't be having selectors in React components, this could be for example in: shared/modules/selectors/smart-transactions.ts

React.useEffect(() => {
if (alertEnabled && !smartTransactionsOptIn) {
dispatch({
type: 'alert/dismiss',
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there some constant for this?


const handleDismiss = useCallback(() => {
dispatch({
type: 'alert/dismiss',
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about a constant. Also, I see that this code is duplicated. Can you have the dispatch and setAlertEnabledness calls in one function which you can reuse?

networkConfigurationsByChainId: {
[CHAIN_ID_MOCK]: {
chainId: CHAIN_ID_MOCK,
// other required network properties
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this comment.

Copy link
Author

Choose a reason for hiding this comment

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

will do, I will check for others too.

@metamaskbot
Copy link
Collaborator

Builds ready [fd00aa9]
Page Load Metrics (1776 ± 108 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint33022461597452217
domContentLoaded147721881743218105
load150422401776224108
domInteractive23106492412
backgroundConnect106934199
firstReactRender1678362110
getState56217178
initialActions00000
loadScripts10661685130617685
setupStore75413136
uiStartup175325282009244117
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.98 KiB (0.04%)
  • ui: 5.97 KiB (0.08%)
  • common: 309 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [20cca27]
Page Load Metrics (1787 ± 100 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint33022181707370178
domContentLoaded147221451758211101
load152321791787209100
domInteractive24122523115
backgroundConnect106227168
firstReactRender17107482914
getState777292612
initialActions01000
loadScripts10951655133217082
setupStore76116178
uiStartup174725892095268129
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.84 KiB (0.03%)
  • ui: 5.97 KiB (0.08%)
  • common: 309 Bytes (0.00%)

…ore or without migration) as conditions are already tested individually.
- Replace inline Redux selector with `getSmartTransactionsOptInStatusInternal`
- Add `getSmartTransactionsMigrationAppliedInternal` for consistent state handling
- Centralize banner visibility logic in `alertConditions` for clarity
- Consolidate alert dismissal logic in `dismissAlert` and remove redundant `dispatch`
- Simplify state typing and remove unused types
- Merge duplicate dismissal tests for shared functionality

Alert state is now managed via AlertController's `setAlertEnabledness`. Selectors are reusable, logic is more maintainable, and tests better reflect component behavior.
@metamaskbot
Copy link
Collaborator

Builds ready [dcf814c]
Page Load Metrics (1664 ± 86 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint13822106166817282
domContentLoaded13732094164416981
load13822158166417986
domInteractive23169544019
backgroundConnect86523168
firstReactRender1678442713
getState55717178
initialActions01000
loadScripts9731436119412862
setupStore65513147
uiStartup15762383189118890
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.9 KiB (0.03%)
  • ui: 5.76 KiB (0.07%)
  • common: 504 Bytes (0.01%)

matthewwalsh0
matthewwalsh0 previously approved these changes Dec 20, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [8385fce]
Page Load Metrics (1655 ± 77 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint14722107165115575
domContentLoaded14652062162515374
load14722117165516177
domInteractive20169433316
backgroundConnect7134293115
firstReactRender15104503215
getState474202211
initialActions01000
loadScripts1039138411859445
setupStore65510105
uiStartup16702350194420096
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.9 KiB (0.03%)
  • ui: 5.76 KiB (0.07%)
  • common: 504 Bytes (0.01%)

@metamaskbot
Copy link
Collaborator

Builds ready [f4b14dc]
Page Load Metrics (1906 ± 78 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint23422611617663318
domContentLoaded16532247187515976
load16602260190616378
domInteractive25179533617
backgroundConnect1196382713
firstReactRender22111502411
getState682292010
initialActions01000
loadScripts12561734142213263
setupStore74914115
uiStartup186329182247297142

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-12.11.0 Issue or pull request that will be included in release 12.11.0 team-confirmations Push issues to confirmations team team-transactions Transactions team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants