-
-
Notifications
You must be signed in to change notification settings - Fork 266
feat: improve currency rate fallback logic #7606
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
Draft
Prithpal-Sooriya
wants to merge
8
commits into
main
Choose a base branch
from
cursor/currency-rate-fallback-logic-c1f2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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 Agent can help with this pull request. Just |
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
cdd82a4 to
b7809cd
Compare
…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
- 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 <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation
This PR refactors the
CurrencyRateControllerto improve the readability, maintainability, and testability of its exchange rate fetching logic, especially concerning fallback mechanisms.#fetchExchangeRatesWithFallbackmethod was a single, lengthy function responsible for both primary API calls and fallback logic, making it difficult to understand, maintain, and test thoroughly.#fetchExchangeRatesWithFallbackmethod has been refactored into smaller, focused private helper methods:#fetchRatesFromPriceApi: Handles the initial attempt to fetch rates from the primary Price API, identifying successful rates and currencies that failed.#fetchRatesFromTokenPricesService: Manages the fallback mechanism, attempting to fetch rates for previously failed currencies using the Token Prices Service.#createNullRatesForCurrencies: A utility to generate null rate entries for any currencies that failed both primary and fallback attempts.The main
#fetchExchangeRatesWithFallbacknow orchestrates these smaller, well-defined steps.mutex,includeUsdRate,useExternalServices) have been renamed to use the hash syntax (#mutex, etc.) to align with TypeScript's private class fields and fix linting errors.References
Checklist