Skip to content

refactor: enable DI for market data#174

Merged
takenagain merged 2 commits intobugfix/balance-watcherfrom
codex/get-changed-files-and-plan-tests
Aug 5, 2025
Merged

refactor: enable DI for market data#174
takenagain merged 2 commits intobugfix/balance-watcherfrom
codex/get-changed-files-and-plan-tests

Conversation

@takenagain
Copy link
Copy Markdown
Contributor

Summary

  • add provider/repository interfaces for market data
  • inject selection strategy and timer into market data manager
  • add unit tests for selection strategy, Komodo price repository and market data manager
  • fix test asset definitions and fiat currency to allow tests to run under flutter environment

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 5, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/get-changed-files-and-plan-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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 5, 2025

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

@takenagain takenagain marked this pull request as ready for review August 5, 2025 17:22
Copilot AI review requested due to automatic review settings August 5, 2025 17:22
@takenagain takenagain merged commit 5e267e5 into bugfix/balance-watcher Aug 5, 2025
1 check passed
@takenagain takenagain deleted the codex/get-changed-files-and-plan-tests branch August 5, 2025 17:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timer factory is being called but _timerFactory field is not defined in the class. This will cause a compilation error.

Copilot uses AI. Check for mistakes.
}

/// A repository for fetching the prices of coins from the Komodo Defi API.
class KomodoPriceRepository extends CexRepository {
Copy link

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class should implement IKomodoPriceRepository interface in addition to extending CexRepository to maintain the contract defined by the interface.

Suggested change
class KomodoPriceRepository extends CexRepository {
class KomodoPriceRepository extends CexRepository implements IKomodoPriceRepository {

Copilot uses AI. Check for mistakes.
CharlVS pushed a commit that referenced this pull request Aug 13, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants