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(suite-native): FW install in onboarding flow #17111

Merged
merged 2 commits into from
Feb 20, 2025

Conversation

PeKne
Copy link
Contributor

@PeKne PeKne commented Feb 19, 2025

Description

  • installation FW for firmwareless device in onboarding flow added
    • there is a separate firmware installation screen for both onboarding flow and device settings
    • these two screen share the UI and device handling via the FirmwareInstallationScreenContent component

⚠️ This PR do not implement FW update of already initialized device! It will be done in: #16431

How to test it:

  1. enable device onboarding feature flag
  2. connect factory reseted device (no seed, no firmware)
  3. go through the onboarding flow, you should end up with a device with latest FW installed

Related Issue

Resolve #16289

Screenshots:

  • no screenshots needed the UI looks the same as in device settings FW update

@coderabbitai ignore 🐰 ☠️

@PeKne PeKne added the mobile Suite Lite issues and PRs label Feb 19, 2025
@PeKne PeKne requested a review from a team as a code owner February 19, 2025 13:20
Copy link

coderabbitai bot commented Feb 19, 2025

Walkthrough

This update replaces the previous firmware update component with a new firmware installation workflow. A new component, FirmwareInstallationScreenContent, is introduced to handle firmware installation success and failure via dedicated callbacks rather than navigation redirection. The changes adjust asynchronous logic, state management, and error handling in the component. Navigation updates include renaming routes and updating the exports across modules to replace references of FirmwareUpdateInProgressScreen with the new firmware installation components. The device settings and onboarding navigators now reference the updated FirmwareInstallation routes, and new screens, such as FirmwareInstallationScreen, have been added to manage the installation process and related navigation actions. Additionally, modifications include updates to type declarations and parameter lists in the routing configuration to support the new workflow. All alterations maintain the existing structure while standardizing the firmware management process.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (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.

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

🧹 Nitpick comments (4)
suite-native/module-onboarding/src/screens/SecurityCheckScreen.tsx (1)

70-78: Consider simplifying the handlePressConfirmButton function.

The current implementation can be more concise by combining the conditions.

 const handlePressConfirmButton = () => {
-    if (currentStep < 3) {
-        setCurrentStep(currentStep + 1);
-
-        return;
-    }
-
-    navigation.navigate(OnboardingStackRoutes.FirmwareInstallationScreen);
+    currentStep < 3
+        ? setCurrentStep(currentStep + 1)
+        : navigation.navigate(OnboardingStackRoutes.FirmwareInstallationScreen);
 };
suite-native/navigation/src/routes.ts (1)

36-36: Consider consistent naming between route enums.

There's a naming inconsistency between OnboardingStackRoutes.FirmwareInstallationScreen and DeviceStackRoutes.FirmwareInstallation. Consider using consistent naming across route enums:

Option 1: Use full names

 export enum OnboardingStackRoutes {
     // ...
     FirmwareInstallationScreen = 'FirmwareInstallationScreen',
 }
 export enum DeviceStackRoutes {
     // ...
-    FirmwareInstallation = 'FirmwareInstallation',
+    FirmwareInstallationScreen = 'FirmwareInstallationScreen',
 }

Option 2: Use concise names

 export enum OnboardingStackRoutes {
     // ...
-    FirmwareInstallationScreen = 'FirmwareInstallationScreen',
+    FirmwareInstallation = 'FirmwareInstallation',
 }
 export enum DeviceStackRoutes {
     // ...
     FirmwareInstallation = 'FirmwareInstallation',
 }

Also applies to: 51-51

suite-native/firmware/src/components/FirmwareInstallationScreenContent.tsx (2)

95-102: Consider handling edge cases in the success callback.

The success callback is called immediately after device authorization, but there's no error handling if the authorization fails.

Consider wrapping the callback in a try-catch:

 const handleFirmwareUpdateFinished = useCallback(async () => {
-    await requestPrioritizedDeviceAccess({
-        deviceCallback: () => dispatch(authorizeDeviceThunk()),
-    });
+    try {
+        await requestPrioritizedDeviceAccess({
+            deviceCallback: () => dispatch(authorizeDeviceThunk()),
+        });
 
-    setIsFirmwareInstallationRunning(false);
-    onFirmwareInstallationSuccess();
+        setIsFirmwareInstallationRunning(false);
+        onFirmwareInstallationSuccess();
+    } catch (error) {
+        setIsFirmwareInstallationRunning(false);
+        onFirmwareInstallationFailure();
+    }
 }, [dispatch, onFirmwareInstallationSuccess, setIsFirmwareInstallationRunning]);

108-141: Consider adding a loading state during firmware update.

The startFirmwareUpdate function sets isFirmwareInstallationRunning but doesn't handle the loading state during the update process.

Consider adding a loading state to prevent multiple update attempts:

 const startFirmwareUpdate = useCallback(async () => {
+    if (isFirmwareInstallationRunning) return;
     setIsFirmwareInstallationRunning(true);
     const result = await firmwareUpdate();
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ab195c and e74a13d.

📒 Files selected for processing (10)
  • suite-native/firmware/src/components/FirmwareInstallationScreenContent.tsx (9 hunks)
  • suite-native/firmware/src/index.ts (1 hunks)
  • suite-native/module-device-settings/src/navigation/DeviceSettingsStackNavigator.tsx (2 hunks)
  • suite-native/module-device-settings/src/screens/FirmwareInstallationScreen.tsx (1 hunks)
  • suite-native/module-device-settings/src/screens/FirmwareUpdateScreen/FirmwareUpdateScreen.tsx (1 hunks)
  • suite-native/module-onboarding/src/navigation/OnboardingStackNavigator.tsx (2 hunks)
  • suite-native/module-onboarding/src/screens/FirmwareInstallationScreen.tsx (1 hunks)
  • suite-native/module-onboarding/src/screens/SecurityCheckScreen.tsx (3 hunks)
  • suite-native/navigation/src/navigators.ts (2 hunks)
  • suite-native/navigation/src/routes.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: EAS Update
  • GitHub Check: prepare_android_test_app
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (9)
suite-native/firmware/src/index.ts (1)

3-3: LGTM! Export changes align with the new firmware installation workflow.

The export change correctly reflects the transition from FirmwareUpdateInProgressScreen to FirmwareInstallationScreenContent.

suite-native/module-device-settings/src/screens/FirmwareInstallationScreen.tsx (1)

19-27: Review success handler's fallback behavior.

The success handler's fallback to popToTop() might leave the user in an unexpected state if the initial route is not available.

Consider:

  1. Adding logging to track this edge case
  2. Defining a specific fallback route instead of popToTop()
 const handleFirmwareInstallationSuccess = () => {
     const initialRoute = navigation.getState().routes.at(0)?.name;
     if (initialRoute) {
         navigation.navigate(initialRoute);
     } else {
-        // This cause should not happen, but just to be safe
-        navigation.popToTop();
+        // Log the edge case for monitoring
+        console.warn('No initial route found in navigation state');
+        // Navigate to a specific fallback route
+        navigation.navigate(DeviceStackRoutes.DeviceSettings);
     }
 };
suite-native/module-device-settings/src/navigation/DeviceSettingsStackNavigator.tsx (1)

42-45: LGTM! Navigation changes align with the new firmware installation workflow.

The navigator correctly integrates the new FirmwareInstallationScreen component.

suite-native/module-onboarding/src/navigation/OnboardingStackNavigator.tsx (1)

11-11: LGTM! The firmware installation screen is properly integrated into the onboarding flow.

The changes correctly implement the firmware installation feature in the onboarding navigation stack, aligning with the PR's objective to enhance the onboarding flow for firmwareless devices.

Also applies to: 45-48

suite-native/module-device-settings/src/screens/FirmwareUpdateScreen/FirmwareUpdateScreen.tsx (1)

58-58: LGTM! Navigation route correctly updated to match the new firmware installation workflow.

The change maintains the existing functionality while properly integrating with the new firmware installation process.

suite-native/module-onboarding/src/screens/SecurityCheckScreen.tsx (1)

7-14: LGTM! Navigation implementation properly integrates firmware installation into the security check flow.

The changes correctly implement type-safe navigation to the firmware installation screen after completing the security checks.

Also applies to: 65-67, 77-77

suite-native/navigation/src/navigators.ts (1)

126-126:

✅ Verification successful

LGTM! Route changes align with the new firmware installation workflow.

The addition of FirmwareInstallationScreen to onboarding and renaming of FirmwareUpdateInProgress to FirmwareInstallation in device settings maintains consistency across both flows.

Let's verify that these routes are properly used in the navigation components:

Also applies to: 171-171


🏁 Script executed:

#!/bin/bash
# Search for usage of the new routes
ast-grep --pattern 'FirmwareInstallationScreen'
ast-grep --pattern 'FirmwareInstallation'

Length of output: 1670


Verified Navigation Routes and Consistent Firmware Workflow

The new routes have been confirmed in both the onboarding and device settings navigation components. Our search results show that:

  • FirmwareInstallationScreen is correctly imported and used in both DeviceSettingsStackNavigator.tsx and OnboardingStackNavigator.tsx.
  • The updated FirmwareInstallation component is properly referenced in the suite components (e.g., in firmware-related views and steps).

LGTM! The changes maintain consistency across both flows.

suite-native/firmware/src/components/FirmwareInstallationScreenContent.tsx (2)

44-54: LGTM! Well-structured component with clear props interface.

The component is properly documented as shared between modules, with a clear warning against module-specific logic.


250-263: LGTM! Clean implementation of the success state UI.

The success state UI is properly animated and includes a continue button that triggers the success callback.

Comment on lines +18 to +20
// TODO: will be implemented as part of follow up issue: https://github.com/trezor/trezor-suite/issues/16291
onFirmwareInstallationFailure={() => null}
/>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement failure handler.

The failure handler is currently a no-op. While issue #16291 is tracking this, consider implementing a basic error handling flow for better user experience until the full implementation is ready.

Consider implementing basic error handling:

-// TODO: will be implemented as part of follow up issue: https://github.com/trezor/trezor-suite/issues/16291
-onFirmwareInstallationFailure={() => null}
+onFirmwareInstallationFailure={() => {
+    showToast({
+        variant: 'error',
+        message: 'Firmware installation failed. Please try again.',
+    });
+}}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// TODO: will be implemented as part of follow up issue: https://github.com/trezor/trezor-suite/issues/16291
onFirmwareInstallationFailure={() => null}
/>
onFirmwareInstallationFailure={() => {
showToast({
variant: 'error',
message: 'Firmware installation failed. Please try again.',
});
}}
/>

Comment on lines +7 to +12
const handleFirmwareInstallationSuccess = () => {
showToast({
variant: 'warning',
message: 'Firmware installation successful! TODO: redirect to the device AC screen.',
});
};
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement actual redirection in success handler.

The success handler only shows a toast without implementing the actual redirection to the device AC screen.

Consider implementing the redirection logic:

 const handleFirmwareInstallationSuccess = () => {
     showToast({
         variant: 'warning',
         message: 'Firmware installation successful! TODO: redirect to the device AC screen.',
     });
+    // TODO: Add navigation to device AC screen
+    // navigation.navigate(OnboardingStackRoutes.DeviceAC);
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleFirmwareInstallationSuccess = () => {
showToast({
variant: 'warning',
message: 'Firmware installation successful! TODO: redirect to the device AC screen.',
});
};
const handleFirmwareInstallationSuccess = () => {
showToast({
variant: 'warning',
message: 'Firmware installation successful! TODO: redirect to the device AC screen.',
});
// TODO: Add navigation to device AC screen
// navigation.navigate(OnboardingStackRoutes.DeviceAC);
};

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

@PeKne PeKne changed the title fix(suite-native): suspicious device screen back navigation feat(suite-native): FW install in onboarding flow Feb 19, 2025
Copy link
Contributor

@Nodonisko Nodonisko left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@PeKne PeKne merged commit 38e8a08 into develop Feb 20, 2025
18 of 19 checks passed
@PeKne PeKne deleted the feat/native/onboarding-fw-installation branch February 20, 2025 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Suite Lite issues and PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Onboarding - FW Installation
2 participants