Skip to content

Commit a7cc1a0

Browse files
authored
fix: use v3 for historical prices for EVM (#24315)
## **Description** use v3 for EVM historical prices instead of V1 price api. Api platform team has made improvements on the v3 api; they added geckoterminal as provider for historical prices, hence it should have more coverage for prices. ## **Changelog** CHANGELOG entry: using v3 api to get historical prices for asset details page instead of v1 ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin Feature: my feature name Scenario: user [verb for user action] Given [describe expected initial app state] When user [verb for user action] Then [describe expected outcome] ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> https://github.com/user-attachments/assets/69625f29-0394-4bcc-bec3-a553b8f2704f ### **After** <!-- [screenshots/recordings] --> https://github.com/user-attachments/assets/ea15d185-c35e-4495-b124-2b9baf1c0aef ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.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-mobile/blob/main/.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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Switch EVM historical price fetch to v3** > > - In `useTokenHistoricalPrices`, replace v1 `price.api` endpoint with v3 and change path to use CAIP-2/CAIP-19 (`eip155:{chainId}` and `erc20:{address}`) for EVM assets > - Preserve existing query params (`timePeriod`, `vsCurrency`, optional `from`/`to`) and 204 handling; non-EVM flow unchanged > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8e2fd83. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 0cd0427 commit a7cc1a0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

app/components/hooks/useTokenHistoricalPrices.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,13 @@ const useTokenHistoricalPrices = ({
119119

120120
setPrices(transformedResult);
121121
} else {
122-
const baseUri = 'https://price.api.cx.metamask.io/v1';
122+
const baseUri = 'https://price.api.cx.metamask.io/v3';
123+
const decimalChainId = getDecimalChainId(chainId);
124+
const caipChainId = `eip155:${decimalChainId}`;
125+
// CAIP-19 format: eip155:{chainId}/erc20:{address}
126+
const assetIdentifier = `erc20:${address}`;
123127
const uri = new URL(
124-
`${baseUri}/chains/${getDecimalChainId(
125-
chainId,
126-
)}/historical-prices/${address}`,
128+
`${baseUri}/historical-prices/${caipChainId}/${assetIdentifier}`,
127129
);
128130
uri.searchParams.set(
129131
'timePeriod',

0 commit comments

Comments
 (0)