Skip to content

fix(dex): crash on buy coin dropdown selection#2624

Merged
CharlVS merged 3 commits intodevfrom
bugfix/dex-dropdown-crash
May 15, 2025
Merged

fix(dex): crash on buy coin dropdown selection#2624
CharlVS merged 3 commits intodevfrom
bugfix/dex-dropdown-crash

Conversation

@takenagain
Copy link
Copy Markdown
Contributor

@takenagain takenagain commented May 12, 2025

Changes

  • Filter out excluded assets from best_orders response, coins list, and fiat onramp to prevent downstream errors from unsupported coins. ARRR is returned in the best_orders response, despite not being supported (not yet implemented - activation failes), which caused the buy coin dropdown to crash.
  • Remove the NFT_* coins from the enabled-by-default coins list to fix the failed activation log spam in console. The NFT page handles required coin activations, so inclusion in this list is unnecessary. The auto-activation does not provide the required parameters for activation, resulting in failed activation and subsequent periodic reactivation attempts.

Testing

Local debug build is required to access the Swap page to confirm that the buy coin selection dropdown does not cause the page/application to crash as reported by @DeckerSU

Summary by CodeRabbit

  • Bug Fixes
    • Unsupported coins, such as ARRR and certain NFT v2 coins, are now excluded from default enabled coins and filtered out from best order lists to prevent errors.
  • Refactor
    • Improved type safety and code clarity in the order grouping list view.
  • Style
    • Minor adjustments to parameter order and use of constants in UI components.
  • Chores
    • Enhanced exception handling and variable immutability in wallet management.

KDF returns ARRR in the best orders response, which is currently excluded from the state which caused the exception to be thrown in grouped list view
@takenagain takenagain self-assigned this May 12, 2025
@takenagain takenagain added the bug Something isn't working label May 12, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 12, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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.

Walkthrough

The changes update coin filtering logic across several modules to exclude unsupported coins such as ARRR and NFT v2 assets. Filtering is applied when fetching best orders in bridge and taker forms. Type specificity is improved in a grouped list view widget, and minor variable declaration improvements are made in the wallets repository.

Changes

File(s) Change Summary
lib/app_config/app_config.dart Added comment about ARRR exclusion; removed NFT v2 coins from default enabled list; updated excludedAssetList and enabledByDefaultCoins contents.
lib/bloc/bridge_form/bridge_bloc.dart
lib/bloc/taker_form/taker_bloc.dart
Imported app_config.dart; added filtering of unsupported coins (using excludedAssetList) from best orders to prevent downstream errors.
lib/blocs/wallets_repository.dart Changed a variable in _getLegacyWallets from var to final; updated exception handling in downloadEncryptedWallet to interpolate the exception object directly.
lib/views/dex/simple/form/tables/orders_table/grouped_list_view.dart Reordered super.key in constructor; changed onSelect type from Function(T) to void Function(T); replaced const EdgeInsets.all(0) with EdgeInsets.zero; made local map variable final.

Sequence Diagram(s)

sequenceDiagram
    participant UI
    participant BridgeBloc
    participant AppConfig
    participant Repository

    UI->>BridgeBloc: Request best orders
    BridgeBloc->>Repository: Fetch best orders
    Repository-->>BridgeBloc: Return best orders
    BridgeBloc->>AppConfig: Access excludedAssetList
    BridgeBloc->>BridgeBloc: Filter out excluded coins from best orders
    BridgeBloc-->>UI: Emit filtered best orders
Loading
sequenceDiagram
    participant UI
    participant TakerBloc
    participant AppConfig
    participant Repository

    UI->>TakerBloc: Request best orders
    TakerBloc->>Repository: Fetch best orders
    Repository-->>TakerBloc: Return best orders
    TakerBloc->>AppConfig: Access excludedAssetList
    TakerBloc->>TakerBloc: Filter out excluded coins from best orders
    TakerBloc-->>UI: Emit filtered best orders
Loading

Suggested labels

QA

Suggested reviewers

  • CharlVS

Poem

In the meadow of code where the coins leap and play,
The ARRR and NFT v2 have hopped away.
With filters in place and types set just right,
The rabbit ensures all coins are in sight.
🐇✨
No pirates allowed, just clean code delight!


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.
    • @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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

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 generate sequence diagram to generate a sequence diagram of the changes in 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

github-actions bot commented May 12, 2025

Visit the preview URL for this PR (updated for commit 3cb8de2):

https://walletrc--pull-2624-merge-4h2sveol.web.app

(expires Wed, 21 May 2025 14:53:42 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: f66a4ff03faa546f12f0ae5a841bd9eff2714dcc

@takenagain
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 13, 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.

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: 2

🔭 Outside diff range comments (2)
lib/bloc/bridge_form/bridge_bloc.dart (1)

99-99: 💡 Verification agent

🧩 Analysis chain

Address linting warning for deprecated method.

The pipeline reports that 'getCoin' is deprecated. Consider updating to the recommended alternatives: KomodoDefiSdk assets or getCoinFromId.

Also applies to: 589-589


🏁 Script executed:

#!/bin/bash
# Check for usage of the recommended alternatives in the codebase
echo "Checking for usage of the recommended alternatives..."
rg "getCoinFromId|KomodoDefiSdk.*assets" --type=dart

Length of output: 623


Replace deprecated getCoin with getCoinFromId
The getCoin call at these locations is deprecated. Please switch to the existing getCoinFromId method in your repository, which already returns a nullable Coin?. For example:

// Before
final Coin? defaultTickerCoin = _coinsRepository.getCoin(event.ticker);

// After
final Coin? defaultTickerCoin = _coinsRepository.getCoinFromId(event.ticker);

This change applies to:

  • lib/bloc/bridge_form/bridge_bloc.dart (line 99)
  • lib/bloc/bridge_form/bridge_bloc.dart (line 589)
🧰 Tools
🪛 GitHub Actions: takenagain is validating code guidelines 🚀

[info] 99-99: 'getCoin' is deprecated and shouldn't be used. Use KomodoDefiSdk assets or getCoinFromId instead

lib/bloc/taker_form/taker_bloc.dart (1)

242-242: 💡 Verification agent

🧩 Analysis chain

Address linting warning for deprecated method.

Similar to BridgeBloc, the pipeline reports that 'getCoin' is deprecated here. Consider updating to the recommended alternatives: KomodoDefiSdk assets or getCoinFromId.


🏁 Script executed:

#!/bin/bash
# Check for examples of the recommended alternatives in this file
echo "Checking for examples of the recommended methods in this file..."
rg "getCoinFromId|KomodoDefiSdk.*assets" lib/bloc/taker_form/taker_bloc.dart

Length of output: 217


Let’s locate the getCoin definition, its deprecation, and available alternatives across the repo:


🏁 Script executed:

#!/bin/bash
set -e

echo "1) Usages of getCoin:"
rg --context 2 "getCoin\(" -n .

echo
echo "2) Definitions or mentions of getCoinFromId:"
rg --context 2 "getCoinFromId" -n .

echo
echo "3) References to KomodoDefiSdk (assets API):"
rg --context 2 "KomodoDefiSdk" -n .

echo
echo "4) Any @Deprecated annotations:"
rg --context 2 "@Deprecated" -n .

echo
echo "5) Locate CoinsRepo class to inspect getCoin:"
rg --context 2 "class .*CoinsRepo" -n .

Length of output: 65903


Running additional verification to inspect TakerBloc and defaultDexCoin types:


🏁 Script executed:

#!/bin/bash
set -e

echo "1) TakerBloc class and constructor:"
rg -C10 "class TakerBloc" -n lib/bloc/taker_form/taker_bloc.dart

echo
echo "2) Declaration and usage of defaultDexCoin:"
rg -C5 "defaultDexCoin" -n lib/bloc/taker_form/taker_bloc.dart

Length of output: 1597


Replace deprecated getCoin with getCoinFromId in TakerBloc

Line 242 of lib/bloc/taker_form/taker_bloc.dart uses the deprecated

final Coin? defaultCoin = _coinsRepo.getCoin(defaultDexCoin);

Replace it with the new ID-based lookup:

- final Coin? defaultCoin = _coinsRepo.getCoin(defaultDexCoin);
+ final Coin? defaultCoin = _coinsRepo.getCoinFromId(defaultDexCoin);

• If defaultDexCoin is a String, wrap it in an AssetId:

final Coin? defaultCoin = _coinsRepo.getCoinFromId(AssetId(defaultDexCoin));

• Alternatively, pull directly from the SDK’s assets bag via _kdfSdk.assets.available.
This silences the lint warning and drops the deprecated API.

🧹 Nitpick comments (1)
lib/blocs/wallets_repository.dart (1)

46-47: Best practice: Using immutable variable declaration.

Changed from var to final to ensure immutability, which is a good Dart practice. This prevents unintended reassignment.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5a6ad28 and 5b10406.

📒 Files selected for processing (5)
  • lib/app_config/app_config.dart (1 hunks)
  • lib/bloc/bridge_form/bridge_bloc.dart (2 hunks)
  • lib/bloc/taker_form/taker_bloc.dart (1 hunks)
  • lib/blocs/wallets_repository.dart (2 hunks)
  • lib/views/dex/simple/form/tables/orders_table/grouped_list_view.dart (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
lib/bloc/bridge_form/bridge_bloc.dart (1)
Learnt from: takenagain
PR: KomodoPlatform/komodo-wallet#2566
File: lib/bloc/coins_bloc/coins_bloc.dart:10-10
Timestamp: 2025-04-01T15:51:37.060Z
Learning: In the Komodo Wallet project, part files share imports with their parent files. The import for `app_config.dart` in `coins_bloc.dart` is necessary because the part file `coins_state.dart` uses `excludedAssetList` from that package.
🪛 GitHub Actions: takenagain is validating code guidelines 🚀
lib/bloc/bridge_form/bridge_bloc.dart

[info] 99-99: 'getCoin' is deprecated and shouldn't be used. Use KomodoDefiSdk assets or getCoinFromId instead


[info] 589-589: 'getCoin' is deprecated and shouldn't be used. Use KomodoDefiSdk assets or getCoinFromId instead

🔇 Additional comments (9)
lib/app_config/app_config.dart (1)

76-77: Documentation improvement for ARRR exclusion.

The added comment clearly explains why ARRR is excluded from the list of supported coins, helping other developers understand the reason behind this decision.

lib/blocs/wallets_repository.dart (1)

118-118: Improved exception message formatting.

The change simplifies exception handling by directly using string interpolation ($e) instead of explicitly calling toString(). This preserves the original exception information better.

lib/bloc/bridge_form/bridge_bloc.dart (1)

7-7: Added necessary import for excludedAssetList.

Added import for app_config.dart to access the excludedAssetList constant used in the fix.

lib/views/dex/simple/form/tables/orders_table/grouped_list_view.dart (6)

18-18: Improved constructor parameter order.

Repositioning super.key after required parameters aligns with Dart best practices and improves code readability.


22-22: Enhanced type safety with specific callback signature.

Changing from generic Function(T) to explicit void Function(T) improves type safety and makes the intention clearer that this callback doesn't return a value.


38-38: Better use of predefined constants.

Using EdgeInsets.zero instead of creating a new instance with const EdgeInsets.all(0) is more idiomatic and slightly more efficient.


86-87: Consistent parameter typing and default value.

The method signature now correctly specifies the return type for the callback and uses the standard EdgeInsets.zero for default padding, improving consistency across the codebase.


109-109: Improved immutability with final variable.

Making the grouped map final prevents accidental reassignment of the variable reference while still allowing the map's contents to be modified - a good practice for maintaining code clarity.


13-128: Overall these changes help prevent the dropdown selection crash.

These type safety improvements and better constant usage, while subtle, contribute to the stability of the component that displays filtered coin data. This works in conjunction with the backend filtering changes mentioned in the summary that exclude unsupported coins like ARRR and NFT v2 assets.

Comment on lines +261 to +266

/// Unsupported coins like ARRR cause downstream errors, so we need to
/// remove them from the list here
bestOrders.result
?.removeWhere((coinId, _) => excludedAssetList.contains(coinId));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical bugfix: Filter out unsupported coins to prevent crashes.

This change prevents downstream errors by filtering out coins like 'ARRR' that lack proper activation parameters, addressing the crash mentioned in the PR title.

The implementation correctly uses removeWhere to filter out all coins listed in the excludedAssetList before updating the state with the best orders.

Comment on lines +296 to +300
/// Unsupported coins like ARRR cause downstream errors, so we need to
/// remove them from the list here
bestOrders.result
?.removeWhere((coinId, _) => excludedAssetList.contains(coinId));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical bugfix: Filter out unsupported coins to prevent crashes.

This change applies the same fix as in BridgeBloc to filter out unsupported coins from the best orders list, ensuring consistency between the two implementations and preventing crashes during coin selection.

The implementation correctly uses removeWhere to filter out all coins listed in the excludedAssetList before updating the state with the best orders.

@takenagain takenagain marked this pull request as ready for review May 13, 2025 18:26
@takenagain takenagain requested a review from Copilot May 13, 2025 18:26
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 fixes a crash on the buy coin dropdown by filtering out unsupported coins (like ARRR) and removing NFT_* coins from the default enabled list. Key changes include adjustments to type safety in callbacks, proper exclusion of unsupported coins in the best orders logic in both taker and bridge blocs, and minor refactoring in the wallets repository to improve code clarity.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/views/dex/simple/form/tables/orders_table/grouped_list_view.dart Adjusted parameter ordering and improved type safety using void callbacks, and replaced EdgeInsets.all(0) with EdgeInsets.zero.
lib/blocs/wallets_repository.dart Replaced mutable variable with a final variable for clearer intent and simplified exception string interpolation.
lib/bloc/taker_form/taker_bloc.dart Added filtering of unsupported coins from best orders to prevent downstream errors.
lib/bloc/bridge_form/bridge_bloc.dart Introduced app_config import and similar filtering of unsupported coins to prevent errors.
lib/app_config/app_config.dart Removed NFT_* coins from the enabled-by-default coins list and added explanatory comments.

@takenagain takenagain marked this pull request as draft May 13, 2025 18:31
@takenagain takenagain marked this pull request as ready for review May 14, 2025 19:28
@takenagain takenagain added the QA Ready for QA Testing label May 14, 2025
Copy link
Copy Markdown
Collaborator

@smk762 smk762 left a comment

Choose a reason for hiding this comment

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

  • No crash on buy coin selection ✔️
  • No NFT related activation error in log stream ✔️
    LGTM, thanks!

Copy link
Copy Markdown
Collaborator

@CharlVS CharlVS left a comment

Choose a reason for hiding this comment

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

SBTYSM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working QA Ready for QA Testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants