Skip to content

fix(coins-bloc): coins re-activating after being disabled by the user#2584

Merged
CharlVS merged 1 commit intodevfrom
bugfix/coin-deactivation
Apr 3, 2025
Merged

fix(coins-bloc): coins re-activating after being disabled by the user#2584
CharlVS merged 1 commit intodevfrom
bugfix/coin-deactivation

Conversation

@takenagain
Copy link
Copy Markdown
Contributor

@takenagain takenagain commented Mar 31, 2025

Fixes coins re-appearing in the coins list after being disabled (after a delay), as seen in #2526

Summary by CodeRabbit

  • Refactor
    • Streamlined coin management to fetch current wallet data in real time, ensuring up-to-date coin status.
    • Enhanced responsiveness in coin activation, deactivation, and refresh operations through asynchronous updates.

@takenagain takenagain added the bug Something isn't working label Mar 31, 2025
@takenagain takenagain self-assigned this Mar 31, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 31, 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 the CoinsBloc class by removing the _currentUserCache mechanism and replacing it with direct wallet retrieval from the _kdfSdk. Several methods now obtain the current wallet in real time for processes such as coin activation, deactivation, and refreshing, ensuring that wallet configuration is always current. The method signatures for _prePopulateListWithActivatingCoins and _getUnactivatedWalletCoins have been updated to return futures, reflecting their asynchronous nature. Additionally, error logging in the deactivation method has been corrected to log the proper asset ID.

Changes

File Change Summary
lib/.../coins_bloc.dart Removed _currentUserCache and updated methods (_onCoinsRefreshed, _onCoinsActivated, _onCoinsDeactivated, _activateCoins, _getUnactivatedWalletCoins) to retrieve the current wallet directly from _kdfSdk. Method signatures updated to return asynchronous Future types, and error logging in _onCoinsDeactivated has been corrected.

Sequence Diagram(s)

sequenceDiagram
    participant CB as CoinsBloc
    participant KDF as _kdfSdk
    participant Wallet as CurrentWallet

    CB->>KDF: Fetch current wallet
    KDF-->>CB: Return current wallet data
    CB->>CB: Process coin operations based on wallet configuration
Loading

Suggested reviewers

  • AndrewDelaney
  • smk762
  • ShantanuSharma9873
  • CharlVS

Poem

In the code realm where coins do gleam,
I hop with joy like in a dream.
Cache removed for wallet true,
Now real-time calls guide what we do.
Hopping through lines with rhythmic beats,
I celebrate changes with bunny feats!
🐇💻


🪧 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.

@takenagain
Copy link
Copy Markdown
Contributor Author

@coderabbitai 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.

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 (2)
lib/bloc/coins_bloc/coins_bloc.dart (2)

120-121: Consider short-circuiting when there's no wallet.

The currentWallet may be null, yet the code continues into the switch block under case null:. This can work as intended, but it might be clearer to explicitly short-circuit if currentWallet is absent for maintainability.


267-269: Double-check for coin presence before logging.

Similar to the previous block, you are force-unwrapping currentWalletCoins[assetId]!. While likely safe in practice, a guard check or error message if the coin is missing can improve robustness.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d513ddc and 4855fe5.

📒 Files selected for processing (1)
  • lib/bloc/coins_bloc/coins_bloc.dart (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Build Desktop (linux)
  • GitHub Check: Build Mobile (Android)
  • GitHub Check: Test web-app-macos
  • GitHub Check: Build Desktop (windows)
  • GitHub Check: Build Mobile (iOS)
  • GitHub Check: Test web-app-linux-profile
  • GitHub Check: Build Desktop (macos)
  • GitHub Check: unit_tests
  • GitHub Check: validate_code_guidelines
🔇 Additional comments (12)
lib/bloc/coins_bloc/coins_bloc.dart (12)

233-235: Handle potential null wallet scenario.

Currently, if currentWallet is null, the block to sync coins would be skipped. Consider confirming that you never expect to activate coins without a wallet. Otherwise, you may want to explicitly bail out.


251-257: Good early return approach.

Returning immediately when there are no wallet coins to disable is a clean approach that avoids unnecessary processing.


258-266: Prevent possible runtime error from forced null unwrap.

You’re force-unwrapping currentWalletCoins[assetId]!. If assetId is ever missing (e.g., concurrency or missed edge case), a runtime error would occur. Consider a safety check or null-safe approach.


278-278: Improved logging message.

Using assetId in the error log helps with triaging.


387-387: Asynchronous state emission looks correct.

Emitting the result from _prePopulateListWithActivatingCoins ensures that the state accurately reflects newly activating coins.


416-418: Correct method signature update.

Changing _prePopulateListWithActivatingCoins to return a Future aligns with the asynchronous wallet retrieval.


426-426: Enabling coins explicitly for the current wallet type.

Assigning enabledType: currentWallet?.config.type ensures the coin's enabled type matches the latest wallet context.


447-448: Straightforward login check.

Retrieving the current wallet and checking if it's non-null is a clear way to determine if the user is logged in before activating a coin.


494-494: Fetching current wallet upon login.

Grabbing currentWallet at login time is consistent with the rest of the updated logic to ensure up-to-date wallet data.


516-516: Nicely combined suspended and unactivated coins.

Adding the result of _getUnactivatedWalletCoins() ensures you capture all coins that need activation in one pass.


523-524: Appropriate async retrieval.

Shifting _getUnactivatedWalletCoins to a Future is consistent with the rest of the asynchronous design.


526-526: Useful warning log.

Logging a warning when there's no wallet gives clear feedback in case of unexpected states.

@takenagain takenagain force-pushed the bugfix/coin-deactivation branch from 4855fe5 to c3f522e Compare March 31, 2025 11:18
@github-actions
Copy link
Copy Markdown

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

https://walletrc--pull-2584-merge-j9r0zc0d.web.app

(expires Mon, 07 Apr 2025 11:22:16 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: f66a4ff03faa546f12f0ae5a841bd9eff2714dcc

@takenagain takenagain marked this pull request as ready for review March 31, 2025 11:23
@takenagain takenagain added the QA Ready for QA Testing label Mar 31, 2025
Copy link
Copy Markdown

@AndrewDelaney AndrewDelaney left a comment

Choose a reason for hiding this comment

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

The updates are working well. Coin management is seemless, and I did not run into any issues enabling/disabling assets. Coins were added and removed from the lists as soon as I gave the action.

@CharlVS CharlVS merged commit 82392a7 into dev Apr 3, 2025
7 of 12 checks passed
@CharlVS CharlVS deleted the bugfix/coin-deactivation branch April 3, 2025 09:15
@ShantanuSharma9873
Copy link
Copy Markdown

The Enable/Disable feature for coins is working as expected. I did not encounter any issues during testing. After disabling specific coins and logging back into the wallet, I observed that the disabled coins no longer appear on the Wallet page or under the graph, which is the expected behavior.

However, please note that this also applies to the KMD coin. Once KMD is disabled and the user logs in again, it does not reappear on the Wallet page unless re-enabled.

Additionally, although it falls outside the current testing scope, I noticed that the test coins (Doc & Marty) were not visible even when the 'Enable Test Coin' toggle was turned on in the settings.

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