Skip to content

Commit eea4d3d

Browse files
authored
fix: dapp-swap comparison fiat rate fetching for native tokens (#38108)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** fix: dapp-swap comparison fiat rate fetching for native tokens ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: ## **Related issues** Fixes: MetaMask/MetaMask-planning#6327 ## **Manual testing steps** 1. Trigger swap including native tokens 2. Check that fait conversion in metrics is correct ## **Screenshots/Recordings** TODO ## **Pre-merge author checklist** - [X] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [X] I've completed the PR template to the best of my ability - [X] I’ve included tests if applicable - [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [X] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/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] > Fetch fiat rates only for non-native tokens in the dapp-swap comparison hook to correctly handle native assets. > > - **Hooks**: > - Update `ui/pages/confirmations/hooks/transactions/dapp-swap-comparison/useDappSwapUSDValues.ts` to filter out native addresses from `tokenAddresses` before calling `fetchTokenExchangeRates('usd', ...)`, avoiding fiat rate requests for native tokens. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 7ff0f9b. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent e377454 commit eea4d3d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ui/pages/confirmations/hooks/transactions/dapp-swap-comparison/useDappSwapUSDValues.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ export function useDappSwapUSDValues({
3030

3131
const { value: fiatRates, pending: fiatRatesPending } = useAsyncResult<
3232
Record<Hex, number | undefined>
33-
>(
34-
() => fetchTokenExchangeRates('usd', tokenAddresses as Hex[], chainId),
35-
[chainId, tokenAddresses?.length],
36-
);
33+
>(() => {
34+
const addresses = tokenAddresses.filter(
35+
(tokenAddress) => !isNativeAddress(tokenAddress),
36+
);
37+
return fetchTokenExchangeRates('usd', addresses as Hex[], chainId);
38+
}, [chainId, tokenAddresses?.length]);
3739

3840
const { value: tokenDetails, pending: tokenDetailsPending } = useAsyncResult<
3941
Record<Hex, TokenStandAndDetails>

0 commit comments

Comments
 (0)