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

feat(native-suite): handling discovery/disconnect state in Settings #17544

Conversation

BrantalikP
Copy link

Description

Enhancement of handling disconnect and discovery states in settings.

Related Issue

Resolve #16010

Screenshots:

Discovery State

Screenrecorder-2025-03-10-12-46-53-688.mp4

Disconnect State

Screenrecorder-2025-03-10-18-55-34-853.mp4

@BrantalikP BrantalikP requested a review from a team as a code owner March 10, 2025 18:03
Copy link

coderabbitai bot commented Mar 10, 2025

Walkthrough

The pull request introduces a new dependency (react-native-reanimated at version ^3.16.7) and refactors the device settings module to improve the handling of device connection and discovery states. A custom hook named useSettingsProtection is added, which uses Redux selectors to determine if a device is connected or if discovery is active, and it provides a function to trigger device connection navigation. This hook is now utilized in several components—DeviceAuthenticityCard, DeviceFirmwareCard, and DevicePinActionButton—to conditionally manage control flows based on connection status. In these components, UI elements such as buttons are set to a disabled state during discovery, and a LoadingIndicator component is conditionally rendered to provide visual feedback. Additionally, a new animated LoadingIndicator component has been implemented using react-native-reanimated to display a fade-in effect.

✨ Finishing Touches
  • 📝 Generate Docstrings

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

@BrantalikP BrantalikP closed this Mar 10, 2025
Copy link

🚀 Expo preview is ready!

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

Learn more about 𝝠 Expo Github Action

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)
suite-native/module-device-settings/src/hooks/useSettingsProtection.ts (1)

1-43: Good abstraction of device connection and discovery states

This hook cleanly encapsulates the logic for checking device connection and discovery status, as well as handling device connection navigation. It appropriately uses Redux selectors to determine the states and provides a convenient interface for components to use.

One suggestion to consider - perhaps add a comment explaining the hook's purpose and when it should be used to make the code more maintainable for future developers.

+/**
+ * Hook that provides device connection status, discovery status, and connection handling
+ * for device settings screens that require an active device connection.
+ */
export const useSettingsProtection = () => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b54ce1f and 7d3dd92.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (6)
  • suite-native/module-device-settings/package.json (1 hunks)
  • suite-native/module-device-settings/src/components/DeviceAuthenticityCard.tsx (5 hunks)
  • suite-native/module-device-settings/src/components/DeviceFirmwareCard.tsx (4 hunks)
  • suite-native/module-device-settings/src/components/DevicePinActionButton.tsx (4 hunks)
  • suite-native/module-device-settings/src/components/LoadingIndicator.tsx (1 hunks)
  • suite-native/module-device-settings/src/hooks/useSettingsProtection.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: PR-check / node-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: PR-check / web-override init-api-flaky
  • GitHub Check: PR-check / node-override init-api-flaky
  • GitHub Check: PR-check / web-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: transport-e2e-test
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: build-deploy
  • 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=passphrase, 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: EAS Update
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: build-web
  • GitHub Check: prepare_android_test_app
  • GitHub Check: test
  • GitHub Check: Socket Security: Pull Request Alerts
🔇 Additional comments (19)
suite-native/module-device-settings/package.json (1)

37-37: LGTM: Added react-native-reanimated dependency for animation support

The addition of this dependency is properly aligned with the implementation of the new animated LoadingIndicator component in the module.

suite-native/module-device-settings/src/components/LoadingIndicator.tsx (1)

1-11: LGTM: Clean implementation of animated loading indicator

The component is well-structured with a clear single responsibility. It uses react-native-reanimated for the fade-in animation and displays a loader with appropriate styling for the disabled state.

suite-native/module-device-settings/src/components/DevicePinActionButton.tsx (6)

20-21: LGTM: Appropriate imports for new components

The imports for the LoadingIndicator and useSettingsProtection hook are correctly added.


65-65: LGTM: Integration of useSettingsProtection hook

Good use of destructuring to get the needed values from the hook.


102-104: LGTM: Early return for disconnected device

Appropriate early check for device connection status, redirecting to device connection flow when needed.


142-151: LGTM: Updated dependency array

The dependency array for the useCallback hook has been properly updated to include the new dependencies.


159-159: LGTM: Button disabled state during discovery

Good UX improvement to disable the button while discovery is running.


161-161: LGTM: Conditional rendering of LoadingIndicator

The LoadingIndicator is correctly shown during discovery, providing clear visual feedback to the user.

suite-native/module-device-settings/src/components/DeviceFirmwareCard.tsx (5)

28-28: Clean hook addition for better state management.

Adding the useSettingsProtection hook is a good abstraction that centralizes device connection and discovery state management.


68-68: Good use of custom hook for state management.

The hook provides a clean way to access connection status and discovery state, removing the need for individual selectors and simplifying the component.


80-80: Simplified conditional logic.

The condition has been refined to remove the direct dependency on device connection state. This allows the firmware update card to be visible even when a device isn't connected, improving discoverability of the feature.


101-101: Good implementation of device connection check.

Instead of hiding the button, this approach allows the button to be visible but handles the connection flow when needed, improving the user experience.


104-105: Appropriate visual feedback during discovery.

The button is correctly disabled and shows a loading state during discovery, providing users with clear feedback about the system state.

suite-native/module-device-settings/src/components/DeviceAuthenticityCard.tsx (6)

22-23: Good component and hook imports.

The addition of the LoadingIndicator component and useSettingsProtection hook properly supports the new functionality for handling discovery and connection states.


33-33: Effective use of custom hook.

Using the useSettingsProtection hook provides a consistent approach to handling device connection and discovery states across different components.


48-48: Early return for device connection handling.

This implementation correctly checks if the device is connected before proceeding with the authenticity check, ensuring proper UX flow.


86-86: Updated dependency array.

The dependency array has been properly updated to include the new dependencies (handleConnectDevice and isDeviceConnected), ensuring the useCallback works as expected.


126-126: Appropriate button state handling.

The button is correctly disabled during discovery, preventing multiple requests or confusing user interactions.


128-133: Good conditional rendering for loading state.

The component properly shows the LoadingIndicator during discovery, providing clear visual feedback to the user about the ongoing process.

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.

Device settings - handle disconnected device and discover running
1 participant