Skip to content

fix(withdraw): update amount when isMaxAmount and show dropdown icon#44

Merged
CharlVS merged 3 commits intodevfrom
bugfix/withdraw-widget-state
Apr 2, 2025
Merged

fix(withdraw): update amount when isMaxAmount and show dropdown icon#44
CharlVS merged 3 commits intodevfrom
bugfix/withdraw-widget-state

Conversation

@takenagain
Copy link
Copy Markdown
Contributor

@takenagain takenagain commented Mar 30, 2025

  • Introduces the market data manager fixes provided by @CharlVS
  • Changes WithdrawAmountField to a StatefulWidget to update the amount field when isMaxAmount is true

Summary by CodeRabbit

  • New Features

    • Enhanced the address selection component for a more intuitive copy-to-clipboard and verification experience.
    • Upgraded the withdrawal amount input to offer dynamic interactivity, real-time error messaging, and balance insights.
  • Refactor

    • Streamlined asset identifier management to ensure more consistent and reliable price lookups.

@takenagain takenagain added the bug Something isn't working label Mar 30, 2025
@takenagain takenagain self-assigned this Mar 30, 2025
Copilot AI review requested due to automatic review settings March 30, 2025 19:20
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.

Copilot wasn't able to review any files in this pull request.

Files not reviewed (4)
  • packages/komodo_defi_sdk/lib/src/market_data/market_data_manager.dart: Language not supported
  • packages/komodo_ui/lib/src/core/inputs/address_select_input.dart: Language not supported
  • packages/komodo_ui/lib/src/defi/withdraw/source_address_field.dart: Language not supported
  • packages/komodo_ui/lib/src/defi/withdraw/withdraw_amount_field.dart: Language not supported

convert to stateful widget and use a text editing controller to set the update the amount value regardless of the enabled/disabled status of the widget
@takenagain takenagain force-pushed the bugfix/withdraw-widget-state branch from 02ad091 to 7a3219f Compare March 31, 2025 13:23
@CharlVS
Copy link
Copy Markdown
Collaborator

CharlVS commented Mar 31, 2025

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2025

Walkthrough

The changes update asset identifier handling in the market data manager by switching from id to symbol.configSymbol across ticker initialization, caching, and price lookup functions. A new _getTradingSymbol method encapsulates the symbol retrieval logic. In the UI components, the address selection process is streamlined by replacing the _buildAddressSelector method with a direct instantiation of AddressSelectInput and moving the address verification logic to the _isAddressVerified method. The withdraw amount field was refactored from a StatelessWidget to a StatefulWidget, introducing state management via a TextEditingController and additional properties.

Changes

File Change Summary
pkg/komodo_defi_sdk/.../market_data_manager.dart Updated CexMarketDataManager: switched from using assetId.id to assetId.symbol.configSymbol in ticker initialization, caching keys, and price lookups; introduced _getTradingSymbol for retrieving the trading symbol.
pkg/komodo_ui/.../withdraw/source_address_field.dart Replaced _buildAddressSelector with a direct instantiation of AddressSelectInput with enhanced parameters; introduced _isAddressVerified method for address verification; updated color opacity handling via the withValues method.
pkg/komodo_ui/.../withdraw/withdraw_amount_field.dart Refactored WithdrawAmountField from a StatelessWidget to a StatefulWidget using a private state class; added a TextEditingController with appropriate lifecycle methods; introduced new properties (e.g., isMaxAmount, onChanged, amountError) for better state handling.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant MDM as MarketDataManager
  participant TS as _getTradingSymbol
  participant Price as PriceService
  
  Client->>MDM: Request fiat price for asset
  MDM->>TS: Retrieve trading symbol for asset
  TS-->>MDM: Return configSymbol
  MDM->>Price: Query price using trading symbol
  Price-->>MDM: Return fiat price data
  MDM-->>Client: Provide fiat price result
Loading
sequenceDiagram
  participant User
  participant WAF as WithdrawAmountField
  participant Controller as TextEditingController
  
  User->>WAF: Open withdrawal form
  WAF->>Controller: initState initializes TextEditingController with current amount
  User->>WAF: Update withdrawal amount input
  WAF->>WAF: didUpdateWidget updates controller text preserving cursor
  Controller-->>WAF: Trigger onChanged callback
  WAF-->>User: Refresh UI with updated amount and error/balance status
Loading

Poem

I hopped through lines of clever code,
Updating symbols on a swift new road.
Addresses selected with care and ease,
Withdrawals now flow like a gentle breeze.
In CodeRabbit’s realm, each change is a delight,
Leaping forward with every byte!


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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/komodo_defi_sdk/lib/src/market_data/market_data_manager.dart (1)

125-128: Method encapsulation for trading symbol retrieval

Added a new _getTradingSymbol method that encapsulates the logic for retrieving the trading symbol. However, there's a discrepancy between the method comment and implementation.

The comment mentions preferring the binanceId if available, but the implementation simply returns configSymbol. Consider either:

  1. Updating the comment to match the current implementation
  2. Implementing the binanceId preference as mentioned in the comment
/// Gets the trading symbol to use for price lookups.
-/// Prefers the binanceId if available, falls back to configSymbol
+/// Uses the configSymbol for price lookups
String _getTradingSymbol(AssetId assetId) {
  return assetId.symbol.configSymbol;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d9d9db4 and 7a3219f.

📒 Files selected for processing (3)
  • packages/komodo_defi_sdk/lib/src/market_data/market_data_manager.dart (6 hunks)
  • packages/komodo_ui/lib/src/defi/withdraw/source_address_field.dart (11 hunks)
  • packages/komodo_ui/lib/src/defi/withdraw/withdraw_amount_field.dart (6 hunks)
🔇 Additional comments (13)
packages/komodo_ui/lib/src/defi/withdraw/source_address_field.dart (6)

61-63: Color handling improvement with withValues()

This change improves color handling by using withValues(alpha: 0.7) instead of the likely previous withOpacity(0.7). This approach provides more control over color properties and maintains consistency with similar changes throughout the file.


76-99: Improved address selection implementation

The code now directly instantiates AddressSelectInput instead of using a separate helper method, which simplifies the code structure. The widget includes proper handling for address selection, copying to clipboard, and verification.

The addition of the copy-to-clipboard functionality with user feedback via a SnackBar improves the user experience significantly.


112-114: Good encapsulation of address verification logic

Moving the address verification logic to a dedicated method _isAddressVerified enhances code readability and follows the single responsibility principle. This approach makes the code easier to maintain and test.


145-146: Consistent color opacity handling

The change to use withValues(alpha: 0.2) maintains consistency with the new approach for handling color opacity throughout the file.


167-168: Consistent color opacity approach across multiple components

The consistent application of withValues(alpha: x) across various UI components (LoadingState text, ErrorState text, BalanceIndicator) ensures a uniform approach to managing color opacity throughout the application.

Also applies to: 221-223, 350-351, 357-358


189-190: Consistent color handling in background elements

The color opacity changes have been consistently applied to background elements like Cards and Containers, ensuring visual consistency throughout the UI.

Also applies to: 285-286, 314-315, 370-371

packages/komodo_defi_sdk/lib/src/market_data/market_data_manager.dart (4)

84-85: Improved asset identification using symbol instead of id

Changed from using id to symbol when initializing known tickers, which aligns with the overall approach of using configurable symbols for asset identification throughout the system.


116-117: Consistent cache key generation using configSymbol

Updated cache key generation to use assetId.symbol.configSymbol instead of what was likely assetId.id previously. This ensures consistency in how assets are identified when caching prices and changes.

Also applies to: 121-122


174-175: Consistent use of trading symbol method

The code now uses the new _getTradingSymbol method when fetching prices and checking if a ticker is known. This improves consistency and makes future changes to symbol handling easier to implement.

Also applies to: 211-213


253-254: Consistent asset identification in price queries

Changed to use assetId.symbol.configSymbol instead of what was likely assetId.id when looking up price data and historical prices. This ensures consistent asset identification across all price-related operations.

Also applies to: 286-287

packages/komodo_ui/lib/src/defi/withdraw/withdraw_amount_field.dart (3)

4-45: Enhanced widget architecture with state management

The widget has been refactored from a StatelessWidget to a StatefulWidget with improved properties and documentation:

  1. Added state management capabilities
  2. Added essential properties (isMaxAmount, onChanged, onMaxToggled)
  3. Added optional properties (amountError, hasInsufficientBalance, availableBalance)
  4. Provided comprehensive documentation for all properties

This change significantly improves the component's flexibility and usability, addressing the PR objective to "ensure that the amount field updates correctly when the isMaxAmount condition is true."


47-80: Well-implemented state management for text input

The _WithdrawAmountFieldState class properly handles the text input state with these key features:

  1. Proper initialization of the TextEditingController
  2. Well-implemented didUpdateWidget method that preserves cursor position during updates
  3. Proper resource cleanup in the dispose method

This implementation solves the issue mentioned in the PR objectives by ensuring the amount field updates correctly when isMaxAmount is true, while maintaining a good user experience by preserving cursor position.


97-103: Proper widget property references and controller integration

The build method correctly references properties through widget and uses the controller for the TextFormField. The field is properly disabled when maximum amount is selected, and the UI correctly reflects the current state (errors, balance information).

The checkbox and MAX button functionality for toggling maximum amount selection is well integrated with the new callback properties.

Also applies to: 108-148, 157-166

@CharlVS CharlVS merged commit b1d58f3 into dev Apr 2, 2025
1 check failed
@takenagain takenagain deleted the bugfix/withdraw-widget-state branch August 13, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants