Skip to content

fix(tokens): refresh takes forever when no identity defined#290

Merged
QuantumExplorer merged 2 commits into
v0.9-devfrom
fix/tokens-refresh-forever-no-identity
May 29, 2025
Merged

fix(tokens): refresh takes forever when no identity defined#290
QuantumExplorer merged 2 commits into
v0.9-devfrom
fix/tokens-refresh-forever-no-identity

Conversation

@lklimek
Copy link
Copy Markdown
Contributor

@lklimek lklimek commented May 23, 2025

Refreshing tokens takes forever when no identity is loaded.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for token balance queries by displaying an explicit error message when no identities are found.
  • Refactor
    • Updated internal message handling to better distinguish between supported and unsupported messages or actions in the tokens screen.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 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

A new crate-private constant for the "No identities found" message was introduced in the backend module. The token balance query logic now returns an error using this constant instead of a successful message. The UI was updated to recognize this constant and improved its handling and logging of unsupported messages and actions.

Changes

File(s) Change Summary
src/backend_task/mod.rs Added crate-private constant NO_IDENTITIES_FOUND with a TODO comment for future refactoring.
src/backend_task/tokens/query_my_token_balances.rs Changed logic to return an error with NO_IDENTITIES_FOUND if no identities are found; updated import.
src/ui/tokens/tokens_screen.rs Updated imports, message handling to recognize NO_IDENTITIES_FOUND, and improved logging for unsupported messages/actions.

Poem

In code where tokens hop and bound,
A message constant now is found.
If no identities appear,
An error whispers, crystal clear.
The UI listens, logs with care—
No tokens? No worries, the rabbits are aware!
🐇✨


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.

@lklimek
Copy link
Copy Markdown
Contributor Author

lklimek commented May 23, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 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

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

Addresses a bug where token refresh would hang indefinitely if no identity is loaded by surfacing a dedicated error constant and updating both the backend query and UI handling.

  • Introduced a NO_IDENTITIES_FOUND constant for a consistent “no identities” error.
  • Modified query_my_token_balances to return an error when no identities exist.
  • Updated the TokensScreen to detect and handle the new constant, plus added logging for unsupported messages and actions.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/ui/tokens/tokens_screen.rs Imported NO_IDENTITIES_FOUND, added a check for it in the refresh logic, and improved logging for messages and actions
src/backend_task/tokens/query_my_token_balances.rs Changed empty‐identity branch to return Err(NO_IDENTITIES_FOUND) instead of a success message
src/backend_task/mod.rs Added NO_IDENTITIES_FOUND constant to centralize the “no identities” error message
Comments suppressed due to low confidence (1)

src/backend_task/tokens/query_my_token_balances.rs:26

  • Add a unit test for query_my_token_balances to cover the case when no identities are found, ensuring it returns the NO_IDENTITIES_FOUND error.
            return Err(NO_IDENTITIES_FOUND.to_string());

Comment thread src/ui/tokens/tokens_screen.rs Outdated
Comment on lines +5522 to +5524
| msg.contains("Failed to fetch token balances")
| msg.contains("Failed to get estimated rewards")
| msg.eq(NO_IDENTITIES_FOUND)
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

Use logical OR (||) instead of bitwise OR (|) when combining boolean conditions to enable short-circuit evaluation and improve readability.

Suggested change
| msg.contains("Failed to fetch token balances")
| msg.contains("Failed to get estimated rewards")
| msg.eq(NO_IDENTITIES_FOUND)
|| msg.contains("Failed to fetch token balances")
|| msg.contains("Failed to get estimated rewards")
|| msg.eq(NO_IDENTITIES_FOUND)

Copilot uses AI. Check for mistakes.
Comment thread src/backend_task/mod.rs
pub mod tokens;
pub mod update_data_contract;

// TODO: Refactor how we handle errors and messages, and remove it from here
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

[nitpick] Add a doc comment explaining the purpose and usage of the NO_IDENTITIES_FOUND constant to help future maintainers understand its role.

Suggested change
// TODO: Refactor how we handle errors and messages, and remove it from here
// TODO: Refactor how we handle errors and messages, and remove it from here
/// A constant string used to indicate that no identities were found during a task.
/// This is typically used in error messages or logs to provide a clear and consistent
/// description of the issue. Future refactoring may relocate or replace this constant.

Copilot uses AI. Check for mistakes.
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)
src/backend_task/mod.rs (1)

40-41: Good addition for consistency, but address the TODO.

The constant helps standardize error messages across the codebase, which improves maintainability. The crate-private visibility is appropriate for this internal constant.

The TODO comment indicates this is a temporary solution. Would you like me to help design a more robust error handling system to replace this string-based approach?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1c3bce6 and f5296c0.

📒 Files selected for processing (3)
  • src/backend_task/mod.rs (1 hunks)
  • src/backend_task/tokens/query_my_token_balances.rs (3 hunks)
  • src/ui/tokens/tokens_screen.rs (3 hunks)
🔇 Additional comments (6)
src/backend_task/tokens/query_my_token_balances.rs (2)

3-3: LGTM!

Clean import of the standardized constant.


25-27:

Details

✅ Verification successful

Excellent fix for the hanging refresh issue!

Converting the no-identities condition from a success message to an error is the right approach. This should prevent the infinite refresh loops described in the PR objectives by allowing calling code to handle this condition explicitly rather than continuing processing.

Please verify that all calling code properly handles this new error condition to ensure graceful user experience:


🏁 Script executed:

#!/bin/bash
# Description: Find all callers of query_my_token_balances to verify error handling
# Expected: All callers should handle the NO_IDENTITIES_FOUND error appropriately

echo "Searching for callers of query_my_token_balances..."
rg -A 10 "query_my_token_balances" --type rust

echo -e "\nSearching for error handling patterns..."
rg -A 5 -B 5 "NO_IDENTITIES_FOUND" --type rust

Length of output: 6620


🏁 Script executed:

#!/bin/bash
# Locate the definition of BackendTaskSuccessResult for context
echo "Searching for BackendTaskSuccessResult definition..."
rg -n "struct BackendTaskSuccessResult" -n --type rust || echo "Definition not found"

Length of output: 222


All callers handle the new error condition correctly

  • In src/backend_task/tokens/mod.rs, the Err(NO_IDENTITIES_FOUND) is mapped to
    "Failed to fetch token balances: No identities found".
  • In src/ui/tokens/tokens_screen.rs, the UI checks msg.contains("Failed to fetch token balances"), which catches this case and sets refreshing_status to NotRefreshing with an appropriate message.

No further changes are needed—calling code already handles the NO_IDENTITIES_FOUND error gracefully.

src/ui/tokens/tokens_screen.rs (4)

45-46: LGTM! Clean import organization.

The import changes properly group TokenTask and add the necessary NO_IDENTITIES_FOUND constant. The organization follows Rust conventions and supports the new error handling functionality.


5524-5524: Correct implementation of NO_IDENTITIES_FOUND handling.

The addition of the NO_IDENTITIES_FOUND condition properly extends the existing message handling pattern for the MyTokens subscreen. This aligns with the backend changes and ensures consistent error handling.


5529-5533: Excellent debugging improvement.

The structured debug logging provides valuable information for troubleshooting unsupported messages. Using tracing::debug! with structured fields (?msg, ?msg_type) follows best practices and will aid in debugging without cluttering logs.


5805-5808: Good improvement to action handling.

Replacing the wildcard match with explicit AppAction::None handling and trace logging for unsupported actions improves code clarity and debugging capabilities. The structured logging will help identify when new action types need explicit handling.

@QuantumExplorer QuantumExplorer merged commit 5907df8 into v0.9-dev May 29, 2025
1 check passed
@QuantumExplorer QuantumExplorer deleted the fix/tokens-refresh-forever-no-identity branch May 29, 2025 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants