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 reliability and structure of exchange rate fetching in CurrencyRateController.

  • Introduces per-currency fallback: fetch from Price API first, then only failed currencies fall back to token prices; preserves successful results even if fallback fails
  • Sets explicit null state for currencies missing network config or when Price API returns falsy values; uses helper #createNullRatesForCurrencies
  • Extracts helpers #fetchRatesFromPriceApi and #fetchRatesFromTokenPricesService; adds FetchRatesResult type; converts fields to private # members
  • Updates tests: adjusts existing expectations and adds a suite for partial success/fallback scenarios (mixed success, no-fallback-needed, mixed failures)
  • Updates package CHANGELOG to document the refactor and behavior changes

Written by Cursor Bugbot for commit bdec20c. 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
Co-authored-by: prithpal.sooriya <prithpal.sooriya@consensys.net>
@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
@Prithpal-Sooriya
Copy link
Contributor Author

@cursor READ THESE MEMORY FILES:

Can you resolve get latest from main and resolve merge conflicts.

@cursor
Copy link

cursor bot commented Jan 13, 2026

Done! I've merged the latest from main and resolved the merge conflict.

Summary

Conflict resolved in: packages/assets-controllers/CHANGELOG.md

The conflict was between:

  • Main branch: New dependency bumps (transaction-controller to ^62.9.1, network-controller to ^28.0.0, accounts-controller to ^35.0.1, polling-controller to ^16.0.1) and Plasma mapping update
  • This branch: CurrencyRateController refactor entry

Resolution: Combined both by keeping all entries from main and adding our CurrencyRateController entry at the end of the ### Changed section.

All 40 tests pass ✅


Open in Cursor Open in Web

Learn more about Cursor Agents

Resolved merge conflict in CHANGELOG.md by combining:
- Dependency bumps from main (transaction-controller, network-controller, accounts-controller, polling-controller)
- Plasma mapping update from main
- CurrencyRateController refactor entry from this branch
@Prithpal-Sooriya
Copy link
Contributor Author

https://github.com/cursor READ THESE MEMORY FILES:

https://raw.githubusercontent.com/Prithpal-Sooriya/Cloud-Agent-Memory/refs/heads/main/Memory.md
Can you resolve get latest from main and resolve merge conflicts.

@cursor
Copy link

cursor bot commented Jan 14, 2026

Done! Merged the latest from main and resolved the new conflict.

Summary

New commits from main:

  • feat: Add watchAsset origin metadata fallbacks (#7612)
  • feat: adds preferred provider to ramp controller state (#7617)
  • feat: update asset endpoints to include RWA data (#7548)

Conflict resolved in: packages/assets-controllers/CHANGELOG.md

Combined the new TokensController.watchAsset entry from main with our CurrencyRateController refactor entry.

All 40 tests pass ✅


Open in Cursor Open in Web

Resolved merge conflict in CHANGELOG.md by combining:
- TokensController.watchAsset metadata fallbacks from main (#7612)
- CurrencyRateController refactor entry from this branch (#7606)
@Prithpal-Sooriya Prithpal-Sooriya added this pull request to the merge queue Jan 14, 2026
Merged via the queue into main with commit ec75c14 Jan 14, 2026
290 checks passed
@Prithpal-Sooriya Prithpal-Sooriya deleted the cursor/currency-rate-fallback-logic-c1f2 branch January 14, 2026 13:27
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.

4 participants