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: display conversion rate #21185

Merged

Conversation

sahar-fehri
Copy link
Contributor

Description

This PR solves one bug shown in this github issue: #20106

When you try to send a token, on Polygon, it does not show the conversion of the amount, it just shows "ETH".

If you chose "FIAT" in the settings=>general, this issue does not occur. This only happens when you choose crypto.

PS: I have also noticed this issue on BNB chain. On Ethereum network, all works fine. If you try to send a token on other chains, you won't be able to see the conversion correctly and it will always just show "ETH".

Manual testing steps

_1. Chose polygon network
_2. Go to settings => General and choose "MATIC" as the primary currency.
_3. Go back to the home screen and choose a token to send (exp USDC)
_4. Click on the "send" button and choose an account
_5. Notice that if you type "5" in the amount input, you will see "ETH" as the conversion of that amount.

(The same steps are applicable on BNB chain)

Screenshots/Recordings

If applicable, add screenshots and/or recordings to visualize the before and after of your change.

Before

On Polygon

image

On BNB

image

After

On Polygon:

image

On BNB:

image

Related issues

(_Fixes #MMASSETS-26)[https://consensyssoftware.atlassian.net/browse/MMASSETS-26]

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained:
    • What problem this PR is solving.
    • How this problem was solved.
    • How reviewers can test my changes.
  • I’ve indicated what issue this PR is linked to: Fixes #???
  • I’ve included tests if applicable.
  • I’ve documented any added code.
  • I’ve applied the right labels on the PR (see labeling guidelines).
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

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.

@sahar-fehri sahar-fehri requested a review from a team as a code owner October 4, 2023 08:49
@sahar-fehri sahar-fehri self-assigned this Oct 4, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2023

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.

@sahar-fehri sahar-fehri added team-extension-ux DEPRECATED: please use "team-wallet-ux" label instead needs-ux-ds-review labels Oct 4, 2023
// Display ETH
currency = EtherDenomination.ETH;
// Display Native currency
currency = nativeCurrency;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we notice this piece of code if(showFiat){....} else{ fallback to ETH} . When you set Fiat in the settings=>General, the problem does not occur.
When you choose crypto, it falls back automatically to 'display ETH' and currency is currency = EtherDenomination.ETH;
regardless of the network you are on.

On the core repo; inside TokenRatesController.ts there is this fct fetchAndMapExchangeRates responsible for fetching the conversion rates. That function first checks if the nativeCurrencySupported by coingecko which in the case of BNB returns true and in the case of "MATIC" returns false.

If it is supported it will return the prices from coingecko, if it is not; it will
1- fetch from coingecko the exchange rate of that token exp (USDC) against the fallback currency (eth)
2- fetch from cryptocompare the conversion of native currency exp (ETH) vs(MATIC)

And then eventually it will multiply them tokenToVsCurrencyConversionRate * vsCurrencyToNativeCurrencyConversionRate returning the conversion of USDC in the native currency (MATIC).

@sahar-fehri sahar-fehri force-pushed the fix/MMASSETS-26-fix-currency-display-in-send-modal branch from 6c95976 to 888715c Compare October 4, 2023 09:14
@metamaskbot
Copy link
Collaborator

Builds ready [888715c]
Page Load Metrics (535 ± 321 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint84145100178
domContentLoaded69140912110
load821795535669321
domInteractive69139912110
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 199 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@sahar-fehri sahar-fehri force-pushed the fix/MMASSETS-26-fix-currency-display-in-send-modal branch from 888715c to fbf94bb Compare October 4, 2023 11:38
@metamaskbot
Copy link
Collaborator

Builds ready [fbf94bb]
Page Load Metrics (359 ± 259 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint8311793115
domContentLoaded6710685126
load781471359540259
domInteractive6710685126
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 199 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@codecov
Copy link

codecov bot commented Oct 4, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (a4e2610) 68.64% compared to head (52c4561) 68.64%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #21185   +/-   ##
========================================
  Coverage    68.64%   68.64%           
========================================
  Files         1017     1017           
  Lines        40797    40797           
  Branches     10893    10893           
========================================
  Hits         28004    28004           
  Misses       12793    12793           
Files Coverage Δ
...components/ui/token-input/token-input.component.js 91.07% <100.00%> (ø)
...components/ui/token-input/token-input.container.js 100.00% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sahar-fehri sahar-fehri force-pushed the fix/MMASSETS-26-fix-currency-display-in-send-modal branch from fbf94bb to 52c4561 Compare October 9, 2023 12:54
@metamaskbot
Copy link
Collaborator

Builds ready [52c4561]
Page Load Metrics (784 ± 374 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint8113797147
domContentLoaded6913588188
load772007784779374
domInteractive6913588188
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 199 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@sahar-fehri sahar-fehri merged commit 001c94b into develop Oct 13, 2023
64 checks passed
@sahar-fehri sahar-fehri deleted the fix/MMASSETS-26-fix-currency-display-in-send-modal branch October 13, 2023 15:10
@github-actions github-actions bot locked and limited conversation to collaborators Oct 13, 2023
@metamaskbot metamaskbot added the release-11.5.0 Issue or pull request that will be included in release 11.5.0 label Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-11.5.0 Issue or pull request that will be included in release 11.5.0 team-extension-ux DEPRECATED: please use "team-wallet-ux" label instead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants