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(TXL-435): turn smart transactions on by default for new users #27885

Merged
merged 8 commits into from
Oct 17, 2024

Conversation

dbrans
Copy link
Contributor

@dbrans dbrans commented Oct 16, 2024

Description

This PR:

  • enables smart transactions by default for new users
  • prevents the smart transaction opt-in modal from appearing

To enable stx by default, we needed to replace the getSmartTransactionsOptInStatus selector with two distinct selectors:

  • getSmartTransactionsOptInStatusForMetrics
  • getSmartTransactionsPreferenceEnabled

Previously, the getSmartTransactionsOptInStatus selector was doing double duty for the user's opt-in status and deciding whether the preference was enabled. Since the feature was disabled by default, and a user that has not opted-in or out of smart transactions has an opt-in status of null, this did not pose a problem.

However, since we decided to enable smart transactions by default, we needed a separate selector for checking the preference for deciding to enable stx.

Why not keep the getSmartTransactionsOptInStatus selector as-is and just add a new one?

We considered keeping the getSmartTransactionsOptInStatus selector and adding a new one. However, by renaming it to getSmartTransactionsOptInStatusForMetrics, we avoid any confusion and make it clear that it is used for metrics collection and not for user preference handling.

Open in GitHub Codespaces

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TXL-435

Manual testing steps

  1. add an account with funds on mainnet
  2. opt-in modal does not display
  3. transfer 0ETH to yourself uses smart transaction
  4. preferences toggle starts enabled
  5. set preferences toggle off
  6. transfer 0ETH to yourself uses regular transaction

Screenshots/Recordings

Before

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.

Copy link
Contributor

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.

@github-actions github-actions bot added the team-transactions Transactions team label Oct 16, 2024
@dbrans dbrans added the DO-NOT-MERGE Pull requests that should not be merged label Oct 16, 2024
@dbrans dbrans marked this pull request as ready for review October 16, 2024 01:54
@dbrans dbrans requested review from a team as code owners October 16, 2024 01:54
@legobeat legobeat marked this pull request as draft October 16, 2024 05:09
@dbrans dbrans marked this pull request as ready for review October 16, 2024 10:33
@dbrans dbrans requested a review from a team as a code owner October 16, 2024 10:33
@dbrans dbrans removed the DO-NOT-MERGE Pull requests that should not be merged label Oct 16, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [8624a66]
Page Load Metrics (2132 ± 134 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint171528592138287138
domContentLoaded170327852091282136
load171427942132279134
domInteractive15207715124
backgroundConnect1283382311
firstReactRender483131236431
getState581322713
initialActions01000
loadScripts128621841595250120
setupStore11100392813
uiStartup189231582425350168
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 6 Bytes (0.00%)
  • ui: -45 Bytes (-0.00%)
  • common: 1.42 KiB (0.02%)

shared/modules/selectors/index.test.ts Outdated Show resolved Hide resolved
ui/pages/home/home.container.js Show resolved Hide resolved
matthewwalsh0
matthewwalsh0 previously approved these changes Oct 16, 2024
darkwing
darkwing previously approved these changes Oct 16, 2024
shared/modules/selectors/smart-transactions.ts Outdated Show resolved Hide resolved
Comment on lines 283 to +285
const isSmartTransaction =
currentSmartTransactionsEnabled && smartTransactionsOptInStatus;
useSelector(getSmartTransactionsPreferenceEnabled) &&
currentSmartTransactionsEnabled;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for not using getIsSmartTransaction from the selectors here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even though the variable is called isSmartTransaction, the logic behind it (useSelector(getSmartTransactionsPreferenceEnabled) && useSelector(getCurrentSmartTransactionsEnabled)) isn’t obviously equivalent to useSelector(getIsSmartTransaction) at first glance.

This PR was mainly intended as a simple rename, but if you have any suggestions, I’d be happy to include them!

@dbrans dbrans enabled auto-merge October 16, 2024 16:13
/**
* Returns the user's explicit opt-in status for the smart transactions feature.
*
* Do not export this selector. It should only be used internally within this file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind please adding to this comment a bit to help readers understand why it shouldn't be exported?

ui/ducks/swaps/swaps.js Show resolved Hide resolved
ui/ducks/swaps/swaps.js Show resolved Hide resolved
@@ -280,7 +281,8 @@ export default function ReviewQuote({ setReceiveToAmount }) {
const unsignedTransaction = usedQuote.trade;
const { isGasIncludedTrade } = usedQuote;
const isSmartTransaction =
currentSmartTransactionsEnabled && smartTransactionsOptInStatus;
useSelector(getSmartTransactionsPreferenceEnabled) &&
currentSmartTransactionsEnabled;
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 there are a few references on this page where we should now replace usage of smartTransactionsOptInStatus with isSmartTransaction because they have to do with whether or not a smart transaction will occur rather than the opt-in status for metrics purposes:

  • In call to quotesToRenderableData (here)
  • In definition of isSwapButtonDisabled (here)
  • In hideEstimatedGasFee property of SelectQuotePopover (here)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @martahj – good catch(es). I've replaced all of these with smartTransactionsPreferenceEnabled.

@dbrans dbrans dismissed stale reviews from darkwing and matthewwalsh0 via 27d1c07 October 16, 2024 16:55
Copy link

Copy link
Contributor

@martahj martahj left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Collaborator

Builds ready [6d371dc]
Page Load Metrics (1817 ± 122 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint40624901735389187
domContentLoaded15612368176920699
load156925361817253122
domInteractive26245594823
backgroundConnect8315536732
firstReactRender47202954220
getState4187204019
initialActions00000
loadScripts11631821132816177
setupStore10143493617
uiStartup171836762098448215
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 6 Bytes (0.00%)
  • ui: 17 Bytes (0.00%)
  • common: 1.5 KiB (0.02%)

@dbrans dbrans added this pull request to the merge queue Oct 17, 2024
Merged via the queue into develop with commit 93fbaaf Oct 17, 2024
78 checks passed
@dbrans dbrans deleted the djb/stx-default-on branch October 17, 2024 13:41
@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2024
@metamaskbot metamaskbot added the release-12.7.0 Issue or pull request that will be included in release 12.7.0 label Oct 17, 2024
@gauthierpetetin gauthierpetetin added release-12.6.0 Issue or pull request that will be included in release 12.6.0 and removed release-12.7.0 Issue or pull request that will be included in release 12.7.0 labels Oct 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.6.0 Issue or pull request that will be included in release 12.6.0 team-transactions Transactions team
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants