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

Fix issue with awaiting swaps page #16344

Merged
merged 8 commits into from
Nov 4, 2022
Merged

Conversation

adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Nov 1, 2022

Explanation

Currently when the service worker is terminated immediately after a swap is initiated the SwapsController controlled swapsState is reset and so the quotes empty out along with other fetchParams causing a redirect:
https://github.com/MetaMask/metamask-extension/blob/develop/ui/pages/swaps/index.js#L505

. So if you don't quickly hit the swap button on the view quotes page after terminating the SW you will be redirected back to the build-quote page:

Screen.Recording.2022-11-01.at.4.25.08.PM.mov

But if you hit swap button before the redirect we hit this call to prepareToLeaveSwaps, which clears the swaps state

And before the state clearing process is complete the signAndSendTransactions call - that is initiated when you hit the swap button - goes through with the swaps state intact

https://github.com/MetaMask/metamask-extension/blob/develop/ui/pages/swaps/index.js#L257

once you arrive on the awaiting-swaps page, though the swap has been submitted correctly, the token information that we use to tell the user which token they will be receiving is no longer accessible since it is accessed through the now cleared swapsState (from the SwapsController in the background)

This PR fixes the issue by having the await-swap page fetch the swap transaction data from the transactions controller (where the state is persisted if the transaction is successfully initiated) rather than the swaps controller where the required state is cleared.

More Information

Manual Testing Steps

  1. Begin a Swap
  2. Introduce amount
  3. Introduce token
  4. Click Review Swap
  5. Terminate service worker -- you can proceed normally
  6. Click Confirm Swap
  7. Terminate service worker
  8. Click Swap --
  9. See that you do not land on an error page, you see the message: Your <symbol of currency you are swapping for> will be added to your account once this transaction has processed.
  10. And see that the swap succeeds

Pre-Merge Checklist

  • PR template is filled out
  • IF this PR fixes a bug, a test that would have caught the bug has been added
  • PR is linked to the appropriate GitHub issue
  • PR has been added to the appropriate release Milestone

+ If there are functional changes:

  • Manual testing complete & passed
  • "Extension QA Board" label has been applied

@github-actions
Copy link
Contributor

github-actions bot commented Nov 1, 2022

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.

@adonesky1 adonesky1 marked this pull request as ready for review November 1, 2022 22:55
@adonesky1 adonesky1 requested a review from a team as a code owner November 1, 2022 22:55
@adonesky1 adonesky1 requested a review from danjm November 1, 2022 22:55
@adonesky1 adonesky1 force-pushed the fix-awaiting-swap-page branch 2 times, most recently from cbc6fb0 to e241359 Compare November 2, 2022 17:24
@jpuri
Copy link
Contributor

jpuri commented Nov 2, 2022

Though changes look good, I would suggest a review by someone from swaps team also.

@darkwing darkwing requested a review from dan437 November 2, 2022 19:12
@metamaskbot
Copy link
Collaborator

Builds ready [e66391d]
Page Load Metrics (2296 ± 119 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint94146118167
domContentLoaded180726852282247119
load180726852296248119
domInteractive180726852282247119

highlights:

storybook

@dan437
Copy link
Contributor

dan437 commented Nov 3, 2022

Thanks for the code. I believe it should be also changed on the smart transaction status page, which is displayed when a smart transaction is submitted: https://github.com/MetaMask/metamask-extension/blob/develop/ui/pages/swaps/smart-transaction-status/smart-transaction-status.js#L76

@hilvmason hilvmason added the PR - P1 identifies PRs deemed priority for Extension team label Nov 3, 2022
@adonesky1 adonesky1 force-pushed the fix-awaiting-swap-page branch from 7f43485 to 44f110c Compare November 3, 2022 16:20
@metamaskbot
Copy link
Collaborator

Builds ready [97f6157]
Page Load Metrics (2017 ± 94 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint8716099157
domContentLoaded16862317200319493
load16862319201719694
domInteractive16862317200319493

highlights:

storybook

@adonesky1 adonesky1 force-pushed the fix-awaiting-swap-page branch from 3bac654 to 5c3c319 Compare November 4, 2022 14:40
Copy link
Contributor

@dan437 dan437 left a comment

Choose a reason for hiding this comment

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

I've tested it with and without smart transactions + terminating a service worker and it worked well. Great job!

@adonesky1 adonesky1 requested a review from seaona November 4, 2022 15:34
@metamaskbot
Copy link
Collaborator

Builds ready [35f8d44]
Page Load Metrics (2380 ± 128 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint983121334622
domContentLoaded188128192362279134
load194128192380267128
domInteractive188128192362279134

highlights:

storybook

@adonesky1 adonesky1 merged commit 4245f24 into develop Nov 4, 2022
@adonesky1 adonesky1 deleted the fix-awaiting-swap-page branch November 4, 2022 16:14
@github-actions github-actions bot locked and limited conversation to collaborators Nov 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
PR - P1 identifies PRs deemed priority for Extension team
Projects
None yet
6 participants