Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(suite): rework DeviceWarning component #16854

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

mroz22
Copy link
Contributor

@mroz22 mroz22 commented Feb 5, 2025

Description

Related Issue

Resolve

Screenshots:

Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

The pull request revises device management within the UI components. In the CardWithDevice component, a new variable for storing device status messages is introduced along with conditional rendering that shows a banner when a device requires attention. This banner includes an action button that dispatches specific functions, either to acquire the device or to select it and redirect based on its state. The previous device warning property is removed from the component’s props. In the DeviceItem component, device management logic and associated imports have been eliminated, simplifying its responsibilities. Additionally, the dedicated DeviceWarning component responsible for displaying warnings has been removed. These changes collectively adjust the implementation to handle device attention and interactions through updated actions and conditional UI elements.


🪧 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. (Beta)
  • @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.

@mroz22 mroz22 marked this pull request as ready for review February 5, 2025 17:53
@mroz22 mroz22 force-pushed the device-needs-attention-refactor branch from 0d18264 to 5a1a841 Compare February 5, 2025 17:53
Copy link

@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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 126ad48 and 5a1a841.

📒 Files selected for processing (4)
  • packages/suite/src/views/suite/SwitchDevice/CardWithDevice.tsx (3 hunks)
  • packages/suite/src/views/suite/SwitchDevice/DeviceItem/DeviceItem.tsx (2 hunks)
  • packages/suite/src/views/suite/SwitchDevice/DeviceItem/DeviceWarning.tsx (0 hunks)
  • suite-common/wallet-core/src/device/deviceThunks.ts (10 hunks)
💤 Files with no reviewable changes (1)
  • packages/suite/src/views/suite/SwitchDevice/DeviceItem/DeviceWarning.tsx
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: EAS Update
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: build-web
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: prepare_android_test_app
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: build-web
🔇 Additional comments (3)
packages/suite/src/views/suite/SwitchDevice/DeviceItem/DeviceItem.tsx (1)

1-74: LGTM! Good separation of concerns.

The changes improve code organization by moving device management logic to CardWithDevice, allowing DeviceItem to focus solely on rendering device information.

packages/suite/src/views/suite/SwitchDevice/CardWithDevice.tsx (1)

92-115: LGTM! Good UX improvements.

The new banner component with interactive solutions improves user experience by:

  • Displaying clear device status messages
  • Providing immediate actions to resolve device issues
  • Handling different device states appropriately
suite-common/wallet-core/src/device/deviceThunks.ts (1)

1-675: LGTM! Good standardization of selectors.

The changes improve code consistency by standardizing the use of selectSelectedDevice across all functions while maintaining existing functionality.

Copy link

github-actions bot commented Feb 5, 2025

🚀 Expo preview is ready!

  • Project → trezor-suite-preview
  • Platforms → android, ios
  • Scheme → trezorsuitelite
  • Runtime Version → 24
  • More info

Learn more about 𝝠 Expo Github Action

@mroz22 mroz22 marked this pull request as draft February 5, 2025 18:14
@mroz22 mroz22 force-pushed the device-needs-attention-refactor branch 2 times, most recently from f2f4ec2 to ceb62d6 Compare February 10, 2025 15:54
@mroz22 mroz22 marked this pull request as ready for review February 10, 2025 15:55
Copy link

@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/suite/src/views/suite/SwitchDevice/CardWithDevice.tsx (1)

100-115: Consider adding error handling for action failures.

The banner implementation effectively displays device attention states and provides user interaction. However, consider adding error handling for cases where the solve issue actions fail.

Add error handling to catch and display action failures:

 const onSolveIssueClick = () => {
+    try {
         const needsAcquire =
             device.type === 'unacquired' ||
             deviceStatus === 'used-in-other-window' ||
             deviceStatus === 'was-used-in-other-window';
         if (needsAcquire) {
-            dispatch(acquireDevice(device));
+            await dispatch(acquireDevice(device));
         } else {
-            dispatch(selectDeviceThunk({ device }));
-            dispatch(redirectAfterWalletSelectedThunk());
+            await dispatch(selectDeviceThunk({ device }));
+            await dispatch(redirectAfterWalletSelectedThunk());
             onCancel?.(false);
         }
+    } catch (error) {
+        // Handle error appropriately (e.g., show error message in banner)
+        console.error('Failed to solve device issue:', error);
+    }
 };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5a1a841 and ceb62d6.

📒 Files selected for processing (3)
  • packages/suite/src/views/suite/SwitchDevice/CardWithDevice.tsx (3 hunks)
  • packages/suite/src/views/suite/SwitchDevice/DeviceItem/DeviceItem.tsx (2 hunks)
  • packages/suite/src/views/suite/SwitchDevice/DeviceItem/DeviceWarning.tsx (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/suite/src/views/suite/SwitchDevice/DeviceItem/DeviceWarning.tsx
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: Unit Tests
  • GitHub Check: Releases revision Checks
  • GitHub Check: Other Checks
  • GitHub Check: Build libs for publishing
  • GitHub Check: Linting and formatting
  • GitHub Check: Type Checking
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: build-web
🔇 Additional comments (5)
packages/suite/src/views/suite/SwitchDevice/DeviceItem/DeviceItem.tsx (2)

4-4: LGTM! Import cleanup aligns with component's simplified responsibilities.

The removal of device management-related imports and the Redux dispatch hook aligns with moving this functionality to the CardWithDevice component.

Also applies to: 8-8


40-40: LGTM! Filter condition simplified.

The filter condition has been simplified while maintaining its core functionality of filtering instances with valid states.

packages/suite/src/views/suite/SwitchDevice/CardWithDevice.tsx (3)

7-8: LGTM! Imports added for new device management functionality.

The new imports support the component's enhanced responsibilities for device management and UI feedback.

Also applies to: 11-13


69-71: LGTM! Enhanced device state management.

The addition of device status message and lock state tracking improves the component's ability to handle device states effectively.


73-85: LGTM! Clear and effective issue resolution handling.

The function properly handles both device acquisition and selection scenarios, with appropriate action dispatching based on the device's state.

@mroz22
Copy link
Contributor Author

mroz22 commented Feb 12, 2025

note for future refactoring, I was able to get into this state on develop, after ejecting device
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant