Skip to content

Swaps UI update#19169

Merged
dan437 merged 35 commits intoMetaMask:developfrom
dan437:swaps-ui-update
Jun 15, 2023
Merged

Swaps UI update#19169
dan437 merged 35 commits intoMetaMask:developfrom
dan437:swaps-ui-update

Conversation

@dan437
Copy link
Copy Markdown
Contributor

@dan437 dan437 commented May 16, 2023

Explanation

We've redesigned our Swaps feature to be easier and faster to use.

There are still a few todos (see below), but we can start getting feedback on code and functionality now to move faster. Most of existing business logic was reused from current Swaps. We keep the old design as a fallback solution, which is controlled via a feature flag. Once we verify that the new redesign is performing well, we will remove the old design from the codebase to make it cleaner.

TODOs:

  • Do more QA testing

Screenshots

image

Manual Testing Steps

  • Click on the "Swap" button on the main page of MetaMask
  • Do our regular Swaps testing, but with the new redesign (different tokens, networks, transaction settings, etc.)

@dan437 dan437 added DO-NOT-MERGE Pull requests that should not be merged area-swaps labels May 16, 2023
@dan437 dan437 requested a review from a team as a code owner May 16, 2023 12:36
@dan437 dan437 requested a review from chloeYue May 16, 2023 12:36
@github-actions
Copy link
Copy Markdown
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.

@dan437 dan437 requested review from adonesky1 and darkwing and removed request for chloeYue May 16, 2023 12:38
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@darkwing
Copy link
Copy Markdown
Contributor

Awesome work @dan437 ! I have a few comments:

1. Adding tokens simply because we requested a swap quote

I think this is current behavior but adding a token to the user's token list simply because they requested a quote seems like unnecessary clutter
SCR-20230519-jnmf

2. Swap details spacing

These controls and text all look really scrunched together -- could use more standardized spacing, maybe from design system?
SCR-20230519-jmlc

3. Settings spacing

These controls and text all look really scrunched together -- could use more standardized spacing, maybe from design system?
SCR-20230519-jmdk

4. Error off the map

I'm seeing this in other places, especially onboarding, so no idea why this is stretching:
SCR-20230519-jizq

5. Max

I feel like we should disable the "MAX" button if the value is 0
SCR-20230519-jgst

6. Accessibility

I don't think I could get to these dropdowns via keyboard
SCR-20230519-jetr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can this be added as a color property to Box?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can color and padding-left be added as box props?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@dan437 does this TODO need to be resolved before we merge? Or can it be addressed in a future release?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After merge is fine, because we only redirect to this page if there is QUOTES_EXPIRED_ERROR: https://github.com/MetaMask/metamask-extension/pull/19169/files#diff-8b6b5a47eeec0494313f7bfc546bce1f3e0fbb16bb56d1092884e376ce394095R691

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why was the swapsFeatureFlags property explicitly added here? This would always initialize the feature flag state to what it was during the last user session. Is that intended?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Glad you asked! The reason for this is the following: if we would turn off the feature flag for this new UI redesign (in case there is a blocking issue), we would anyway show the new redesign by default before redirecting to the previous design once we get a response from the /featureFlags endpoint, which is not user-friendly. This way we will remember which feature flags were used last time and use those by default, before we get fresh ones from the /featureFlags endpoint.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you check the edge case we mentioned on slack, where the user selects a token to swap that they have not yet added to their token list? The possible failure, given that this PR removes the destinationTokenAddedForSwap and associated logic, is that token balances are not calculated correctly on this page for destination tokens that are not in the users list.

Copy link
Copy Markdown
Contributor Author

@dan437 dan437 Jun 13, 2023

Choose a reason for hiding this comment

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

Yes. It seems that tokensWithBalances is only used for token from in this component and destinationTokenAddedForSwap was for token to. We still call the addToken function from Swaps for token from if that token has a balance, so it should work: https://github.com/MetaMask/metamask-extension/pull/19169/files#diff-2493772b1f68622e8d2eae0660b50d2765884331c60418c86e5315389fb2fd8eR693

@nikoferro
Copy link
Copy Markdown
Contributor

Hey @dan437, can you debounce fetching the code when the user is typing? Right now it seems it makes the requests to get the quotes just as soon as the user starts typing which feels sluggish and with some lag if the user keeps typing after a couple of characters.

Also in the case the user keeps adding numbers, are you cancelling previous requests or how is this handled? Just wondering about an scenario where the user inputs 1 and then 0 (trying to swap 10), and for some reason the request to get a quote for 1, is slower than the request for quotes for 10. So you get a quote to swap 1 instead of 10

@nikoferro
Copy link
Copy Markdown
Contributor

nikoferro commented Jun 13, 2023

Hey @dan437 , does the new redesign consider this scenario? Right now swaps on full screen looks a bit weird since the layout goes to the bigger size but swaps remains the same.

Screenshot 2023-06-13 at 15 39 35

This also looks like a bug right now:

Screenshot 2023-06-13 at 15 41 51

@dan437
Copy link
Copy Markdown
Contributor Author

dan437 commented Jun 14, 2023

Hi @nikoferro, thanks a lot for this valuable feedback. We briefly discussed it internally and here are my responses:

  • Debouncing: we have it in the prepare-swap-page.js component: https://github.com/MetaMask/metamask-extension/pull/19169/files#diff-8b6b5a47eeec0494313f7bfc546bce1f3e0fbb16bb56d1092884e376ce394095R628 It's the same debouncing that's already in production. I also noticed that the extension is a bit slow when doing yarn start, but if I use a build created via yarn dist, the experience is very smooth, including the Amount field in Swaps.
  • Expanded view: the long nav bar was added recently. The expanded view's width for Swaps is similar to the Send feature, but I will discuss with our designers how we can make it better with the new nav bar.
  • ETH -> ETH swap: I wasn't able to reproduce ETH -> ETH, since the Token To field should not show a token that's in the Token From field. If you are able to reproduce it, please, let me know.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be defaulted to '' since it's not required @georgewrmarshall ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here @georgewrmarshall .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe Boolean(payload) instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Elegant!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this eslint line necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It only silences a warning, but code works without it as well, so I've removed it.

When I pass the handleSearch dependency to remove the warning, it triggers this effect many times. That's why I didn't add it into the dependency list. Maybe there is a better way where the handleSearch fn doesn't trigger this effect.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can these first values be assigned at the time of let, and then replaced with if ! priceSlippageUnknownFiatValue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want use Text instead of span here @georgewrmarshall

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This PR only adds data-testid attributes in this existing file. We have a user story to refactor a few remaining components in Swaps to use the new DS components (we use them in most of the redesigned Swaps already), so I would prefer do it in another PR.

@darkwing
Copy link
Copy Markdown
Contributor

Seeing this weird state where I can submit a swap that I don't have a balance for, for roughly 1 second before I'm told I don't have enough ETH to pay gas fee:

MaybeCommit.mov

@darkwing
Copy link
Copy Markdown
Contributor

Can we keep the token list within the bounds of the popup viewport?

SCR-20230614-jrgs

@dan437
Copy link
Copy Markdown
Contributor Author

dan437 commented Jun 15, 2023

Can we keep the token list within the bounds of the popup viewport?

SCR-20230614-jrgs

Yes, I discussed it with our designers a few weeks ago and there is a ticket for adding a new design system component called ModalBody, which should allow scrolling only for content, instead of having scrolling for the whole page as we have it now. Before the new ModalBody component is available, I will do that via custom CSS.

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 15, 2023

Codecov Report

Merging #19169 (60cf5cc) into develop (55a1514) will decrease coverage by 0.05%.
The diff coverage is 67.67%.

@@             Coverage Diff             @@
##           develop   #19169      +/-   ##
===========================================
- Coverage    70.49%   70.44%   -0.05%     
===========================================
  Files          972      984      +12     
  Lines        37277    38270     +993     
  Branches      9636    10004     +368     
===========================================
+ Hits         26276    26957     +681     
- Misses       11001    11313     +312     
Impacted Files Coverage Δ
shared/notifications/index.js 26.67% <0.00%> (-2.96%) ⬇️
...ction-breakdown/transaction-breakdown.component.js 76.74% <ø> (ø)
...details/transaction-list-item-details.component.js 62.82% <ø> (ø)
ui/components/app/wallet-overview/eth-overview.js 67.09% <ø> (ø)
.../components/app/whats-new-popup/whats-new-popup.js 22.22% <0.00%> (-0.58%) ⬇️
...nents/component-library/banner-base/banner-base.js 100.00% <ø> (ø)
...ponents/component-library/text-field/text-field.js 97.37% <ø> (ø)
ui/components/ui/info-tooltip/info-tooltip.js 71.43% <ø> (ø)
ui/components/ui/typography/typography.js 100.00% <ø> (ø)
ui/pages/swaps/awaiting-swap/awaiting-swap.js 96.94% <ø> (ø)
... and 30 more

... and 2 files with indirect coverage changes

Copy link
Copy Markdown
Contributor

@davibroc davibroc left a comment

Choose a reason for hiding this comment

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

I have completed the tests for this and found no issues

@dan437 dan437 merged commit 8b3e3c8 into MetaMask:develop Jun 15, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jun 15, 2023
@dan437 dan437 deleted the swaps-ui-update branch July 24, 2023 11:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants