Skip to content

Conversation

@Prithpal-Sooriya
Copy link
Contributor

@Prithpal-Sooriya Prithpal-Sooriya commented Jan 12, 2026

Explanation

Modifies CurrencyRateController to better handle fallback currency rates

  • improved success/error handling (will now try both exchange-rates endpoint then spot prices endpoint for failed networks).

Also decoupled the complex currency fetching logic into separate methods for the main exchange rates fetch vs spot prices fetch.

Oh and also resolve ESLint issues (agent led this)

https://consensys.zoom.us/clips/share/GCgPlIVRRtejh3f0Wgyhmg

References

https://consensyssoftware.atlassian.net/browse/ASSETS-2269
MetaMask/metamask-extension#39194

Checklist

  • I've updated the test suite for new or updated code as appropriate (Added 5 new tests for partial success/fallback scenarios and updated 2 existing tests to reflect new behavior).
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate (JSDoc added for new private helper methods).
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Open in Cursor Open in Web


Note

Improves exchange rate fetching in CurrencyRateController.ts with clearer structure and smarter fallback behavior.

  • Extracts #fetchRatesFromPriceApi, #fetchRatesFromTokenPricesService, and #createNullRatesForCurrencies to modularize logic
  • Fallback now retries only currencies missing or invalid from the Price API, preserving successful results and returning nulls when both attempts fail
  • Migrates internals to TypeScript private fields (e.g., #mutex, #includeUsdRate, #useExternalServices) and adds explicit return types
  • Expands and updates tests to cover partial success, fallback failures, and undefined/zero-rate cases
  • Updates CHANGELOG.md entry describing the refactor and behavior changes

Written by Cursor Bugbot for commit f9ff877. This will update automatically on new commits. Configure here.

Prithpal-Sooriya and others added 2 commits January 12, 2026 21:49
- Refactor #fetchExchangeRatesWithFallback into smaller helper methods:
  - #fetchRatesFromPriceApi: handles primary Price API call
  - #fetchRatesFromTokenPricesService: handles fallback fetching
  - #createNullRatesForCurrencies: creates null entries for failed currencies
- Rename private members to use hash syntax (fixing lint errors)
- Add partial success handling: when some currencies succeed and others fail,
  only failed currencies trigger fallback
- Add comprehensive tests for partial success scenarios
- Update existing tests to match new expected behavior
@cursor
Copy link

cursor bot commented Jan 12, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

Removed unused suppressions after refactoring:
- no-negated-condition: no longer needed
- no-restricted-syntax: no longer needed
- @typescript-eslint/explicit-function-return-type: reduced count from 3 to 1
@cursor cursor bot force-pushed the cursor/currency-rate-fallback-logic-c1f2 branch from cdd82a4 to b7809cd Compare January 12, 2026 22:29
…nd failedCurrencies

- Updated #fetchRatesFromTokenPricesService to return { rates, failedCurrencies }
  similar to #fetchRatesFromPriceApi for consistency
- Removed null currency creation from fallback method - failures now add to
  failedCurrencies instead of creating null rates inline
- Step 4 now takes the final list of failed currencies from step 3 to build
  null rates, simplifying the logic
- Simplified #createNullRatesForCurrencies to only take currencies array
- Renamed PriceApiResult type to FetchRatesResult for broader applicability
Prithpal-Sooriya and others added 3 commits January 12, 2026 22:44
- Wrapped the entire method body in try-catch so it never throws
- On any unexpected error, returns all currencies as failed
- Updated JSDoc to document that the method is designed to never throw
- This allows #fetchExchangeRatesWithFallback to use const instead of let
  and removes the external try-catch, simplifying the orchestration logic
@Prithpal-Sooriya Prithpal-Sooriya changed the title Currency rate fallback logic feat: improve currency rate fallback logic Jan 12, 2026
@Prithpal-Sooriya Prithpal-Sooriya marked this pull request as ready for review January 13, 2026 09:45
@Prithpal-Sooriya Prithpal-Sooriya requested review from a team as code owners January 13, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants