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 missing conversion rates in swaps token drop down #12420

Merged
merged 3 commits into from
Oct 25, 2021

Conversation

adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Oct 20, 2021

Explanation: Conversion rates were missing in the swaps "from token" searchable dropdown because contractExchangeRates are keyed with addresses in checksum format. This is yet another case where address format normalization needs to take place globally

additionally the defaultToken (ETH) appeared to only render conversionRates when swapsTokens were unavailable so this PR alters logic for deriving the tokensToSearchBuckets such that we guarantee the defaultToken/native asset has data required to show fiat conversion available.

@github-actions
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.

@adonesky1 adonesky1 force-pushed the fix/missing-conversion-rates-swaps-dropdown branch from 068ee11 to 6b22e5a Compare October 20, 2021 22:32
@adonesky1 adonesky1 marked this pull request as ready for review October 21, 2021 15:15
@adonesky1 adonesky1 requested a review from a team as a code owner October 21, 2021 15:15
@metamaskbot
Copy link
Collaborator

Builds ready [c674179]
Page Load Metrics (421 ± 55 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint28068342011455
domContentLoaded27068541111756
load28068542111555
domInteractive27068541111756

@@ -172,6 +172,10 @@ export function useTokensToSearch({
return new BigNumber(rawFiat || 0).gt(secondRawFiat || 0) ? -1 : 1;
},
);

// the defaultToken/asset should always be at the top of the owned section
tokensToSearchBuckets.owned.unshift(memoizedDefaultToken);
Copy link
Contributor

@darkwing darkwing Oct 21, 2021

Choose a reason for hiding this comment

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

Nice! My only concern was if owned was ever not an array, and ui/hooks/useTokensToSearch.js shows it initialized as empty, so we're good!

darkwing
darkwing previously approved these changes Oct 21, 2021
…own with full renderable data regardless of whether swaps tokens are available
@adonesky1 adonesky1 force-pushed the fix/missing-conversion-rates-swaps-dropdown branch from 6d1876b to a5171c4 Compare October 21, 2021 16:06
@@ -139,7 +142,7 @@ export function useTokensToSearch({
};

const memoizedSwapsAndUserTokensWithoutDuplicities = uniqBy(
[...memoizedTokensToSearch, ...memoizedUsersToken],
[memoizedDefaultToken, ...memoizedTokensToSearch, ...memoizedUsersToken],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found that this change was required to get the native asset to consistently show conversionRate as well. Otherwise we would use the swapsTokens instance of ETH (when swapsTokens are available, which appears to be intermittent?) which has no balance information resulting in not showing conversions. cc @dan437 @danjm

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 this change is fine

@metamaskbot
Copy link
Collaborator

Builds ready [a5171c4]
Page Load Metrics (497 ± 59 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint12163046112660
domContentLoaded29579348612459
load30580649712459
domInteractive29579348612459

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 the changes locally and I can see fiat prices now + tokens are sorted by their fiat value. Great job!

@metamaskbot
Copy link
Collaborator

Builds ready [8272efd]
Page Load Metrics (453 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint29570145213565
domContentLoaded28570944414067
load29570945313665
domInteractive28570944414067

Copy link
Contributor

@darkwing darkwing left a comment

Choose a reason for hiding this comment

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

My only nit is that we run toChecksumHexAddress(address) twice, maybe we could store that value in a const instead of doing the work twice, but not a huge deal.

@adonesky1
Copy link
Contributor Author

@danjm this okay to merge and pull into 10.3.0? Does it resolve all concerns?

@adonesky1 adonesky1 merged commit 385e0f2 into develop Oct 25, 2021
@adonesky1 adonesky1 deleted the fix/missing-conversion-rates-swaps-dropdown branch October 25, 2021 15:03
@github-actions github-actions bot locked and limited conversation to collaborators Oct 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants