refactor: enable DI for market data#174
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Visit the preview URL for this PR (updated for commit 0d5ce3c): https://komodo-defi-sdk--pr174-codex-get-changed-fi-eghsab5q.web.app (expires Tue, 12 Aug 2025 12:53:30 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 7f9f5ac39928f333b6e8fcefb7138575e24ed347 |
There was a problem hiding this comment.
Pull Request Overview
This PR implements dependency injection for market data components to improve testability and modularity. The changes replace concrete class dependencies with abstract interfaces and add comprehensive unit tests.
- Introduces interface abstractions for price repositories and providers to enable dependency injection
- Adds a configurable timer factory and repository selection strategy to the market data manager
- Creates comprehensive unit tests for the selection strategy, Komodo price repository, and market data manager
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/komodo_defi_sdk/lib/src/market_data/market_data_manager.dart | Updates constructor to accept interface types and configurable timer factory |
| packages/komodo_defi_sdk/lib/src/bootstrap.dart | Registers new interfaces and dependencies in the DI container |
| packages/komodo_cex_market_data/lib/src/repository_selection_strategy.dart | Extracts abstract interface and implements default strategy |
| packages/komodo_cex_market_data/lib/src/komodo/prices/komodo_price_repository.dart | Implements interface and adds missing CexRepository methods |
| packages/komodo_cex_market_data/lib/src/komodo/prices/komodo_price_provider.dart | Adds interface abstraction for the provider |
| packages/komodo_cex_market_data/lib/src/coingecko/data/coingecko_cex_provider.dart | Extracts interface for CoinGecko provider |
| packages/komodo_cex_market_data/lib/src/coingecko/data/coingecko_repository.dart | Updates to use interface type |
| packages/komodo_cex_market_data/lib/src/binance/data/binance_repository.dart | Minor formatting improvements |
| Test files | Adds comprehensive unit tests for new components |
| _logger.fine('Initialized known tickers: ${_knownTickers?.length ?? 0}'); | ||
| // Start cache clearing timer | ||
| _cacheTimer = Timer.periodic(_cacheClearInterval, (_) => _clearCaches()); | ||
| _cacheTimer = _timerFactory(_cacheClearInterval, _clearCaches); |
There was a problem hiding this comment.
The timer factory is being called but _timerFactory field is not defined in the class. This will cause a compilation error.
| } | ||
|
|
||
| /// A repository for fetching the prices of coins from the Komodo Defi API. | ||
| class KomodoPriceRepository extends CexRepository { |
There was a problem hiding this comment.
The class should implement IKomodoPriceRepository interface in addition to extending CexRepository to maintain the contract defined by the interface.
| class KomodoPriceRepository extends CexRepository { | |
| class KomodoPriceRepository extends CexRepository implements IKomodoPriceRepository { |
* fix(market-data-manager): default to KomodoPriceRepository Binance CexRepository supports a limited number of symbols and no longer lists KMD price history after the delisting * refactor(market-data): move ticker resolution to the repository layer allows for API-specific tickers to be used on a per-repository basis * feat(example): show market data in example asset list * feat(market-data): add coin supported check to selection strategy * Implement getCoinFiatPrices with batch processing and error handling Co-authored-by: francoisvw <francoisvw@protonmail.com> * refactor(market-data): standardise retry mechanism * feat(example): add sparkline chart to asset row item * refactor(example): change market info cubit to bloc to manage streaming automatically via emit.forEach rather than manually disposing background streams. fixes the emit after close bug * fix(asset-market-info): move bloc provider into the asset row item * refactor(id-resolution): improve typing of previously nullable functions * feat(sparkline): add multi-provider support and logging * test: fix market data unit tests (#174) * feat(cex-market-data): align and update interfaces use Decimal, use standard interface, add missing 24hr price change functionality * refactor(market-data): add quote currency union type * fix(komodo-prices): change json key and add in-memory caching * feat(market-data): add repository fallback logic and tests * feat(market-data): add stablecoin to fiat mapping and fix tests * refactor(review): update comments and fix potential issues * refactor: remove string ticker-based coin pair model in favour of quote * fix(sparkline): prevent requests to unsupported coins and add fallback * test(cex-market-data): improve coverage and refactor out utilities * refactor(review): improve sparkline and repository error visibilty * feat(asset-id): add asset cache key to standardize asset-based caching * test: extract helper functions and remove unnecessary tests --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Summary
Testing
flutter test test/komodo_price_repository_test.dart test/repository_selection_strategy_test.dart(packages/komodo_cex_market_data)flutter test test/market_data_manager_test.dart(packages/komodo_defi_sdk)https://chatgpt.com/codex/tasks/task_e_6891d3bdf3388331a0948dce086396cc