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: market data for native tokens with non zero addresses #28584

Merged
merged 8 commits into from
Nov 22, 2024

Conversation

bergeron
Copy link
Contributor

@bergeron bergeron commented Nov 20, 2024

Description

Draft

When querying the price API, the native token is usually represented by the zero address. But this is not the case on some chains like polygon, whose native token has a contract 0x0000000000000000000000000000000000001010.

Depends on: MetaMask/core#4952

Open in GitHub Codespaces

Related issues

Fixes:

Manual testing steps

(pre-req - you may need to enable the PORTFOLIO_VIEW=true flag)

  1. Onboard with an SRP that have POL tokens.
  2. Connect and switch to Polygon
  3. View the POL token on the tokens section on the home page.
    • Does it contain percentages and market data.
  4. View the POL asset page.
    • Does it contain the market details view; and percentage sections?

Screenshots/Recordings

Before After
Screenshot 2024-11-22 at 16 42 25 Screenshot 2024-11-22 at 16 29 38
Screenshot 2024-11-22 at 16 42 41 Screenshot 2024-11-22 at 16 29 46

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.

package.json Outdated Show resolved Hide resolved
@gambinish gambinish mentioned this pull request Nov 21, 2024
7 tasks
github-merge-queue bot pushed a commit that referenced this pull request Nov 21, 2024
## **Description**

This consolidates the changes from a series of 3 Multichain Asset List
PRs that built on each other:

1. Product code (feature branch):
#28386
2. Unit tests: #28451
3. e2e tests: #28524

We created separate branches for rapid iteration and isolated testing.
The code is now cleaner and stable enough for review and merge into
develop, gated by the `PORTFOLIO_VIEW` feature flag.

We will introduce another PR to remove this feature flag when we are
ready to ship it.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28593?quickstart=1)

## **Related issues**

Fixes:
https://github.com/orgs/MetaMask/projects/85/views/35?pane=issue&itemId=82217837

## **Manual testing steps**

`PORTFOLIO_VIEW=1 yarn webpack --watch`

1. View tokens across all networks in one unified list.
2. Filter tokens by selected network
3. Crosschain navigation:
- Token detail pages update to display data from the appropriate
network.
- Send/Swap actions automatically adjust the selected network for user
convenience.
- Ensure that network switch is functional, and sends/swaps happen on
correct chain.
    
Known caveats:
1. POL native token market data not populating. Will be addressed here:
#28584 and
MetaMask/core#4952
2. Native token swapping on different network than selected network
swaps incorrect token:
#28587
3. Multichain token detection experimental draft:
#28380
    

## **Screenshots/Recordings**


https://github.com/user-attachments/assets/79e7fd2d-9908-4c7a-8134-089cbe6593cc


https://github.com/user-attachments/assets/dfb4a54f-a8ae-48a4-a9e7-50327f56054a

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.

---------

Co-authored-by: Jonathan Bursztyn <[email protected]>
Co-authored-by: chloeYue <[email protected]>
Co-authored-by: seaona <[email protected]>
Co-authored-by: Monte Lai <[email protected]>
Co-authored-by: Charly Chevalier <[email protected]>
Co-authored-by: Pedro Figueiredo <[email protected]>
Co-authored-by: MetaMask Bot <[email protected]>
Co-authored-by: NidhiKJha <[email protected]>
Co-authored-by: sahar-fehri <[email protected]>
Prithpal-Sooriya added a commit to MetaMask/core that referenced this pull request Nov 22, 2024
## Explanation

When querying the price API, the native token is usually represented by
the zero address. But this is not the case on some chains like polygon,
whose native token has a contract
`0x0000000000000000000000000000000000001010`.

Note: Extension/mobile would also need to use the exported
`getNativeTokenAddress`, so they know where to lookup the native prices
in state.

Draft extension PR:
MetaMask/metamask-extension#28584

## References

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/assets-controllers`

- **ADDED**: `chainIdToNativeTokenAddress` to record chains with unique
(non-zero) addresses
- **ADDED**: `getNativeTokenAddress()` exported function to return the
correct native token address for native assets (either zero addresses,
or the unique addresses recorded in `chainIdToNativeTokenAddress`)
- **CHANGED**: Updated price API calls to use the native token by chain
instead of relying on the zero address.
- **CHANGED**: Updated `TokenRatesController` market data mapping to use
`getNativeTokenAddress` instead of the zero address for native tokens.

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes

---------

Co-authored-by: Prithpal Sooriya <[email protected]>
@metamaskbot
Copy link
Collaborator

Builds ready [b17514b]
Page Load Metrics (1882 ± 74 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint16472300188614871
domContentLoaded15892214185814369
load15982317188215574
domInteractive15181453918
backgroundConnect11100302411
firstReactRender793021234522
getState55816178
initialActions0482105
loadScripts11091645135512058
setupStore65512147
uiStartup181027472121213102
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 728 Bytes (0.01%)
  • common: 346 Bytes (0.00%)

Comment on lines +37 to +43
const mockGetIntlLocale = jest.mocked(getIntlLocale);
const mockGetCurrentCurrency = jest.mocked(getCurrentCurrency);
const mockGetPreferences = jest.mocked(getPreferences);
const mockGetSelectedAccount = jest.mocked(getSelectedAccount);
const mockGetShouldHideZeroBalanceTokens = jest.mocked(
getShouldHideZeroBalanceTokens,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL jest.mocked way better than casting to jest.Mock like I'm used to 👍

gambinish
gambinish previously approved these changes Nov 22, 2024
Copy link
Contributor

@gambinish gambinish left a comment

Choose a reason for hiding this comment

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

LGTM. Pulled down and ran. Populates both the percent change as well as the graph over time in asset details 👍

If you need another pass after removing the patch, lmk.

@metamaskbot
Copy link
Collaborator

Builds ready [ff6daec]
Page Load Metrics (1986 ± 74 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint25624541901407195
domContentLoaded17562410194415172
load17702461198615574
domInteractive278442178
backgroundConnect12112402713
firstReactRender513111347737
getState75217136
initialActions00000
loadScripts12791804142912761
setupStore778202010
uiStartup20092724227520196
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 711 Bytes (0.01%)
  • common: 346 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [b8caf56]
Page Load Metrics (1917 ± 126 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint40926081810388186
domContentLoaded165226231888253122
load165726281917263126
domInteractive22147443014
backgroundConnect997322512
firstReactRender483001456330
getState46315168
initialActions01000
loadScripts119020391401226109
setupStore65617199
uiStartup186433352224354170
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 711 Bytes (0.01%)
  • common: 470 Bytes (0.01%)

@Prithpal-Sooriya Prithpal-Sooriya marked this pull request as ready for review November 22, 2024 20:00
@darkwing darkwing added this pull request to the merge queue Nov 22, 2024
Merged via the queue into develop with commit 9bdfd03 Nov 22, 2024
75 checks passed
@darkwing darkwing deleted the brian/polygonzeroaddress branch November 22, 2024 21:47
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2024
@metamaskbot metamaskbot added the release-12.9.0 Issue or pull request that will be included in release 12.9.0 label Nov 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.9.0 Issue or pull request that will be included in release 12.9.0 team-assets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants