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): add DeviceCompromisedModal for FW revision check #16722

Merged

Conversation

Lemonexe
Copy link
Contributor

@Lemonexe Lemonexe commented Jan 30, 2025

Description

FW revision check part II.

  • when device FW revision check fails & it's enabled in App settings & feature flag's enabled:
  • display the Device compromised modal 👻

Related Issue

Resolve #16448

Screenshots / QA instructions

  • Connect a device with officially released FW (e.g. emulator T3T1 2.8.1)
    • there should be no visible change - after connecting a device dashboard is displayed normally.
  • Connect emulator any model with unreleased FW (2-main or 1-main) to continue.
  • Turned off Authenticity check in App settings (setting added in #16435 ): no visible change
  • Turned off feature flag IsFwRevisionCheckEnabled: no visible change
  • Turned off both of the above: no visible change
  • Turned on both of the above (the default on dev env): you should see:

DeviceCompro

Pressing the Contact Support button opens browser with chatbot flow:
hal

Pressing back returns back to normal dashboard
dashboard

@Lemonexe Lemonexe added the mobile Suite Lite issues and PRs label Jan 30, 2025
@Lemonexe Lemonexe force-pushed the feat/native-FW-revision-check-DeviceCompromisedModal branch from 80124af to 8cae3e0 Compare January 31, 2025 12:02
Copy link

coderabbitai bot commented Jan 31, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

error Error: http://10.0.0.28:4873/@trezor%2feslint: no such package available
at params.callback [as _callback] (/opt/yarn-v1.22.22/lib/cli.js:66685:18)
at self.callback (/opt/yarn-v1.22.22/lib/cli.js:141415:22)
at Request.emit (node:events:519:28)
at Request. (/opt/yarn-v1.22.22/lib/cli.js:142387:10)
at Request.emit (node:events:519:28)
at IncomingMessage. (/opt/yarn-v1.22.22/lib/cli.js:142309:12)
at Object.onceWrapper (node:events:633:28)
at IncomingMessage.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1698:12)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21)

Walkthrough

This pull request introduces a comprehensive implementation of a device compromised modal for firmware revision checks in the Suite Native application. The changes span multiple files across different modules, including the creation of a new @suite-native/module-authenticity-checks module. The implementation adds navigation capabilities, translations, and state management for handling scenarios where a device might be compromised due to firmware authenticity issues. The modifications include adding a new stack navigator, creating a device compromised modal screen, updating routing configurations, and integrating new selectors and hooks to manage the device connection and authenticity check flow.

Assessment against linked issues

Objective Addressed Explanation
Add DeviceCompromisedModal as a separate screen
Remember device as dismissed (during session)
Add contact support button
Navigate to modal on FW revision check hard failure Partial implementation requires feature flag and settings confirmation
Implement feature flag IsFwRevisionCheckEnabled No evidence of feature flag implementation in this PR

Possibly related PRs

Suggested labels

no-project

Suggested reviewers

  • mroz22
  • komret
  • HajekOndrej

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 49fd2cb and 8cae3e0.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (13)
  • suite-native/app/e2e/utils.ts (1 hunks)
  • suite-native/app/package.json (1 hunks)
  • suite-native/app/src/navigation/RootStackNavigator.tsx (2 hunks)
  • suite-native/app/tsconfig.json (1 hunks)
  • suite-native/device/src/hooks/useHandleDeviceConnection.ts (7 hunks)
  • suite-native/intl/src/en.ts (1 hunks)
  • suite-native/module-authenticity-checks/package.json (1 hunks)
  • suite-native/module-authenticity-checks/src/index.ts (1 hunks)
  • suite-native/module-authenticity-checks/src/navigation/AuthenticityChecksStackNavigator.tsx (1 hunks)
  • suite-native/module-authenticity-checks/src/screens/DeviceCompromisedModalScreen.tsx (1 hunks)
  • suite-native/module-authenticity-checks/tsconfig.json (1 hunks)
  • suite-native/navigation/src/navigators.ts (3 hunks)
  • suite-native/navigation/src/routes.ts (2 hunks)
✅ Files skipped from review due to trivial changes (3)
  • suite-native/module-authenticity-checks/tsconfig.json
  • suite-native/module-authenticity-checks/package.json
  • suite-native/module-authenticity-checks/src/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: run_android_e2e_tests
🔇 Additional comments (17)
suite-native/module-authenticity-checks/src/navigation/AuthenticityChecksStackNavigator.tsx (1)

1-23: LGTM! Clean and well-structured navigator implementation.

The implementation follows React Navigation best practices with proper type safety and reusable configuration.

suite-native/module-authenticity-checks/src/screens/DeviceCompromisedModalScreen.tsx (3)

19-21: Address the TODO comment regarding desktop vs mobile UX.

The comment indicates this page is designed for desktop and needs mobile-specific UX. This should be tracked and addressed to ensure optimal mobile experience.

Would you like me to help create a new issue to track the mobile UX implementation?


23-33: LGTM! Clear and consistent list implementation.

The InformativeList component effectively communicates critical information using consistent styling and translations.


47-63: Simplify navigation and dismissal logic.

The navigation handling is convoluted with different behaviors for the X icon and Close button. Consider unifying the behavior by extracting the navigation logic into a shared handler.

+const handleDismiss = () => {
+  if (navigation.canGoBack()) {
+    navigation.goBack();
+  } else {
+    navigation.navigate(RootStackRoutes.AppTabs, {
+      screen: AppTabsRoutes.HomeStack,
+      params: { screen: HomeStackRoutes.Home },
+    });
+  }
+  dismissCheck();
+};

-const handleClose = () => {
-  if (navigation.canGoBack()) {
-    navigation.goBack();
-  } else {
-    navigation.navigate(RootStackRoutes.AppTabs, {
-      screen: AppTabsRoutes.HomeStack,
-      params: { screen: HomeStackRoutes.Home },
-    });
-  }
-  dismissCheck();
-};

Then use handleDismiss for both the header and button:

-<Screen header={<ScreenHeader closeActionType="close" closeAction={dismissCheck} />}>
+<Screen header={<ScreenHeader closeActionType="close" closeAction={handleDismiss} />}>

-<Button colorScheme="redElevation0" onPress={handleClose}>
+<Button colorScheme="redElevation0" onPress={handleDismiss}>
suite-native/navigation/src/routes.ts (1)

19-19: LGTM! Consistent route definitions.

The new routes follow the established pattern and integrate well with the existing navigation structure.

Also applies to: 127-130

suite-native/app/e2e/utils.ts (1)

108-109: LGTM! Well-documented test setup change.

The addition of the firmware version parameter is properly documented and ensures consistent test behavior.

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

195-197: LGTM! Clean type definition for the authenticity checks stack.

The type definition follows the established pattern and correctly defines the modal screen without parameters.


223-223: LGTM! Proper integration with root stack params.

The authenticity checks stack is properly integrated into the root stack param list using NavigatorScreenParams.

suite-native/app/src/navigation/RootStackNavigator.tsx (2)

12-12: LGTM! Clean import of the authenticity checks navigator.

The import follows the established pattern of module imports.


122-125: LGTM! Proper screen configuration in the root stack.

The screen is properly configured with the correct name and component, following the established pattern.

suite-native/device/src/hooks/useHandleDeviceConnection.ts (4)

52-57: LGTM! Well-structured firmware check logic.

The implementation properly combines the firmware check status with the dismissal state to determine if the compromised modal should be shown.


77-78: LGTM! Proper integration with device authorization flow.

The compromised device check is correctly integrated into the authorization flow, preventing authorization when the device is potentially compromised.


92-96: LGTM! Clean navigation implementation.

The navigation to the compromised modal is properly implemented when required.


109-109: LGTM! Proper dependency tracking.

The effect's dependency array correctly includes the new navigation condition.

suite-native/intl/src/en.ts (1)

1213-1225: LGTM! Clear and well-structured translations.

The translations are user-friendly and provide clear guidance for users encountering a potentially compromised device. The messages effectively communicate:

  • The security concern
  • Required user actions
  • Next steps with support
suite-native/app/tsconfig.json (1)

51-53: LGTM! Module reference properly configured.

The addition of the module reference for "@suite-native/module-authenticity-checks" follows the established pattern and is correctly placed in the references array.

suite-native/app/package.json (1)

62-62: LGTM! Dependency properly configured.

The addition of "@suite-native/module-authenticity-checks" as a workspace dependency is consistent with other @suite-native modules and correctly configured.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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

github-actions bot commented Jan 31, 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

@Lemonexe Lemonexe marked this pull request as ready for review January 31, 2025 12:27
@Lemonexe Lemonexe requested a review from a team as a code owner January 31, 2025 12:27
@trezor trezor deleted a comment from Lemonexe Feb 4, 2025
@PeKne
Copy link
Contributor

PeKne commented Feb 4, 2025

I just realized that the device authenticity check screen that @yanascz implemented recently looks almost the same (the copy is identical). Might be good idea to unify it? Or is there any reason why we do not want it?
Screenshot 2025-02-04 at 9 55 06 AM

@Lemonexe Lemonexe force-pushed the feat/native-FW-revision-check-DeviceCompromisedModal branch from 8cae3e0 to 0b7f605 Compare February 5, 2025 12:07
@Lemonexe Lemonexe requested a review from PeKne February 5, 2025 12:40
@Lemonexe
Copy link
Contributor Author

Lemonexe commented Feb 5, 2025

Ad similar screens for authenticity checks: discussed personally, but here it's for visibility - there are multiple similar screens like this one, but since they are mostly WIP, it's still too early to try to unify it.
We'll see, maybe common UX will be abstracted to the @suite-native/module-authenticity-checks package for all of them, or maybe even a new package..

// TODO: this hook is getting very complex, and it's hard to understand the logic when it navigates there and back again.
// Ideally there'd be a single source of truth, a function returning "where we should be as per current state"
// rather than multiple useEffects with imperative instructions "go there when X changes"
if (isDeviceCompromisedModalFocused) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

at first I tried to use shouldNavigateToDeviceCompromisedModal for this condition, but then I realized - even if you don't dismiss the modal, this variable still becomes false when disconnecting device, because whole state.device is anulled when you disconnect device.

lastRoute might not be an ideal way to determine current state of UI, but I didn't think of anything else without overengineering it..

Copy link
Contributor

@PeKne PeKne left a comment

Choose a reason for hiding this comment

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

Well done, thanks for adjusting the code to my comments ;).

@Lemonexe
Copy link
Contributor Author

Lemonexe commented Feb 6, 2025

/rebase

Copy link

github-actions bot commented Feb 6, 2025

@trezor-ci trezor-ci force-pushed the feat/native-FW-revision-check-DeviceCompromisedModal branch from 816f368 to 358df52 Compare February 6, 2025 07:48
@Lemonexe
Copy link
Contributor Author

Lemonexe commented Feb 6, 2025

Merging despite broken E2E tests, they're broken globally (slack discussion)

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.

DeviceCompromisedModal for FW revision check
2 participants