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): block receiving when device compromised #16749

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

Conversation

Lemonexe
Copy link
Contributor

@Lemonexe Lemonexe commented Jan 31, 2025

ℹ️ If you have been automatically assigned to review, it's a mistake. I rebased this PR to develop, and changed base to develop, but it caused this.. Sry!

Description

FW revision check part III.

  • when device FW revision check fails & it's enabled in App settings & feature flag's enabled:
  • remove Receive buttons from dashboard and account pages
  • any remaining Receive buttons will lead to the "error page" instead of receive UI

ℹ️ figma screen

Related Issue

Resolve #16451

Screenshots / QA instructions

  • Connect a device with officially released FW (e.g. emulator T3T1 2.8.1)
  • 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 Receive buttons removed: dashboard, account, empty account

this UX flow is IMHO very obscure, but you may try it:

  • turn on view only, disconnect trezor, activate new coins, and deactivate all coins except the new ones
  • then you see the EmptyConnectedDeviceState screen
  • click Receive assets leads to the Add new modal selection, but trying to select displays alert
  • reconnect trezor at the Add new modal, and you get the Receiving blocked 🎉

@Lemonexe Lemonexe added the mobile Suite Lite issues and PRs label Jan 31, 2025
Copy link

coderabbitai bot commented Jan 31, 2025

Walkthrough

This pull request introduces functionality to block the receiving process when a firmware authenticity check fails. It includes the addition of a new translation key for notifying users about a compromised device. A dependency on the device module is established, and new selectors, specifically selectHasFirmwareAuthenticityCheckHardFailed, are implemented in several components. These selectors control the conditional rendering of the receive buttons across dashboard and account interfaces. When the firmware check fails, the UI either hides the receive button or routes the user to an error screen via the new ReceiveBlockedDeviceCompromisedScreen component. Additionally, updates are made to TypeScript configurations and package dependencies to support these changes.

Assessment against linked issues

Objective Addressed Explanation
Block receive functionality by hiding receive buttons and routing to error screen (#16451)

Suggested labels

bug, translations

Suggested reviewers

  • MiroslavProchazka
  • komret
  • tomasklim

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

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

@Lemonexe Lemonexe marked this pull request as ready for review January 31, 2025 17:31
@Lemonexe Lemonexe requested a review from a team as a code owner January 31, 2025 17:31
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.

Looks good 👌

@Lemonexe Lemonexe force-pushed the feat/native-FW-revision-check-ReceiveBlocked branch from 3b847d2 to 90fff0c Compare February 4, 2025 14:37
@Lemonexe Lemonexe changed the base branch from feat/native-FW-revision-check-DeviceCompromisedModal to develop February 4, 2025 14:37
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 (4)
suite-native/receive/src/screens/ReceiveBlockedDeviceCompromisedScreen.tsx (1)

5-15: LGTM! Well-structured component with proper error handling UI.

The component follows React best practices and provides a clear error message when the device is compromised.

A few suggestions to enhance user experience:

  1. Consider adding a descriptive message explaining why receiving is blocked.
  2. Add a call-to-action button to guide users on how to resolve the issue.
 export const ReceiveBlockedDeviceCompromisedScreen = () => (
     <Screen header={<ScreenHeader closeActionType="back" />}>
         <VStack justifyContent="center" flex={1}>
             <PictogramTitleHeader
                 variant="critical"
                 title={<Translation id="moduleReceive.deviceCompromisedScreen.title" />}
                 titleVariant="titleSmall"
             />
+            <Text color="textSubdued" textAlign="center">
+                <Translation id="moduleReceive.deviceCompromisedScreen.description" />
+            </Text>
+            <Button
+                onPress={handleLearnMore}
+                variant="tertiary"
+                size="small"
+            >
+                <Translation id="moduleReceive.deviceCompromisedScreen.learnMore" />
+            </Button>
         </VStack>
     </Screen>
 );
suite-native/transactions/src/components/TransactionsEmptyState.tsx (1)

21-24: Consider improving variable naming.

The variable name hasFirmwareAuthenticityCheckHardFailed is quite long and could be simplified for better readability.

-    const hasFirmwareAuthenticityCheckHardFailed = useSelector(
-        selectHasFirmwareAuthenticityCheckHardFailed,
-    );
+    const isDeviceCompromised = useSelector(selectHasFirmwareAuthenticityCheckHardFailed);
suite-native/module-home/src/screens/HomeScreen/components/PortfolioContent.tsx (1)

45-45: Fix typo in data-testID attribute.

There's a typo in the test ID: "recieve" should be "receive".

-                            data-testID="@home/portolio/recieve-button"
+                            data-testID="@home/portfolio/receive-button"
suite-native/intl/src/en.ts (1)

570-572: Consider enhancing the error message.

While the message is clear, it could be more informative by explaining why receiving is disabled and what actions users can take.

Consider expanding the message:

 deviceCompromisedScreen: {
-    title: 'Receiving is disabled',
+    title: 'Receiving is disabled due to compromised device',
+    description: 'Your device failed the firmware authenticity check. Please contact Trezor support for assistance.',
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a53e724 and 90fff0c.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (11)
  • suite-native/intl/src/en.ts (1 hunks)
  • suite-native/module-accounts-management/package.json (1 hunks)
  • suite-native/module-accounts-management/src/components/TransactionListHeader.tsx (4 hunks)
  • suite-native/module-accounts-management/tsconfig.json (1 hunks)
  • suite-native/module-home/src/screens/HomeScreen/components/PortfolioContent.tsx (2 hunks)
  • suite-native/receive/src/screens/ReceiveAccountsScreen.tsx (3 hunks)
  • suite-native/receive/src/screens/ReceiveAddressScreen.tsx (2 hunks)
  • suite-native/receive/src/screens/ReceiveBlockedDeviceCompromisedScreen.tsx (1 hunks)
  • suite-native/transactions/package.json (1 hunks)
  • suite-native/transactions/src/components/TransactionsEmptyState.tsx (3 hunks)
  • suite-native/transactions/tsconfig.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Socket Security: Pull Request Alerts
🔇 Additional comments (12)
suite-native/transactions/package.json (1)

29-29: Dependency Addition: "@suite-native/device"

The addition of "@suite-native/device": "workspace:*" aligns with the overall PR objective of enforcing firmware revision checks and enhancing device security. This workspace dependency ensures the module remains in sync with local developments. Please verify that the device module's API and functionality are compatible with the revisions introduced in this PR.

suite-native/module-accounts-management/package.json (1)

27-27: Dependency Addition: Validate Integration of @suite-native/device

The new dependency "@suite-native/device": "workspace:*" has been added to support the firmware revision check. This addition correctly aligns with the PR objectives to enhance device security and to block receiving on compromised devices. Please verify that all references to device functionality in this module and others are updated to use the newly added dependency and that the workspace resolution satisfies version consistency across the codebase.

suite-native/transactions/tsconfig.json (1)

31-31: Validate New Device Module Reference

The new reference { "path": "../device" } is added to support the firmware revision check functionality. Please verify that the relative path correctly points to the intended device module and that the module's types are properly resolved in this context.

suite-native/receive/src/screens/ReceiveAccountsScreen.tsx (1)

26-29: LGTM! Clean implementation of firmware check.

The early return pattern with the firmware check is clean and follows best practices.

suite-native/module-home/src/screens/HomeScreen/components/PortfolioContent.tsx (1)

26-30: LGTM! Clean implementation of firmware check.

The logic for showReceiveButton is clear and follows best practices.

suite-native/receive/src/screens/ReceiveAddressScreen.tsx (2)

13-16: LGTM! Clean import grouping.

The imports are well organized, with the new device-related imports grouped together.


49-52: LGTM! Early check for compromised device.

The firmware authenticity check is performed early in the component, before any other logic, which is the correct approach for security-critical checks.

suite-native/module-accounts-management/src/components/TransactionListHeader.tsx (4)

15-15: LGTM! Clean import.

The new device selector import is properly placed with other imports.


100-102: LGTM! Selector hook usage.

The firmware authenticity check selector is properly implemented using useSelector.


132-132: LGTM! Clear flag naming.

The isReceiveButtonDisplayed flag clearly indicates its purpose and is correctly derived from the firmware check.


143-153: LGTM! Proper conditional rendering.

The receive button is correctly wrapped in a conditional render block based on the firmware check.

suite-native/module-accounts-management/tsconfig.json (1)

25-25: LGTM! Proper module reference.

The device module reference is correctly added and maintains alphabetical ordering.

@Lemonexe Lemonexe force-pushed the feat/native-FW-revision-check-ReceiveBlocked branch from 90fff0c to f8d68ce Compare February 4, 2025 16:52
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 (2)
suite-native/transactions/src/components/TransactionsEmptyState.tsx (1)

49-53: Consider adding user feedback when receive button is hidden.

While the conditional rendering is correct, users might benefit from understanding why the receive button is not available when the device is compromised.

Consider adding an error message or info text when showReceiveButton is false:

-            {showReceiveButton && (
+            {showReceiveButton ? (
                 <Button viewLeft="arrowLineDown" onPress={handleReceive} size="large">
                     <Translation id="transactions.emptyState.button" />
                 </Button>
+            ) : (
+                <Text color="textSubdued" textAlign="center">
+                    <Translation id="transactions.emptyState.receiveDisabled" />
+                </Text>
             )}
suite-native/module-accounts-management/src/components/TransactionListHeader.tsx (1)

143-153: Consider adding user feedback when receive button is hidden.

While the conditional rendering is correct, users might benefit from understanding why the receive button is not available when the device is compromised.

Consider adding an error message or info text when isReceiveButtonDisplayed is false:

-            {isReceiveButtonDisplayed && (
+            {isReceiveButtonDisplayed ? (
                 <Box flex={1}>
                     <Button
                         viewLeft="arrowLineDown"
                         onPress={handleReceive}
                         testID="@account-detail/receive-button"
                     >
                         <Translation id="transactions.receive" />
                     </Button>
                 </Box>
+            ) : (
+                <Box flex={1}>
+                    <Text color="textSubdued" textAlign="center">
+                        <Translation id="transactions.receiveDisabled" />
+                    </Text>
+                </Box>
             )}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 90fff0c and f8d68ce.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (11)
  • suite-native/intl/src/en.ts (1 hunks)
  • suite-native/module-accounts-management/package.json (1 hunks)
  • suite-native/module-accounts-management/src/components/TransactionListHeader.tsx (4 hunks)
  • suite-native/module-accounts-management/tsconfig.json (1 hunks)
  • suite-native/module-home/src/screens/HomeScreen/components/PortfolioContent.tsx (2 hunks)
  • suite-native/receive/src/screens/ReceiveAccountsScreen.tsx (3 hunks)
  • suite-native/receive/src/screens/ReceiveAddressScreen.tsx (2 hunks)
  • suite-native/receive/src/screens/ReceiveBlockedDeviceCompromisedScreen.tsx (1 hunks)
  • suite-native/transactions/package.json (1 hunks)
  • suite-native/transactions/src/components/TransactionsEmptyState.tsx (3 hunks)
  • suite-native/transactions/tsconfig.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (9)
  • suite-native/module-accounts-management/package.json
  • suite-native/transactions/tsconfig.json
  • suite-native/module-accounts-management/tsconfig.json
  • suite-native/transactions/package.json
  • suite-native/receive/src/screens/ReceiveAccountsScreen.tsx
  • suite-native/module-home/src/screens/HomeScreen/components/PortfolioContent.tsx
  • suite-native/intl/src/en.ts
  • suite-native/receive/src/screens/ReceiveBlockedDeviceCompromisedScreen.tsx
  • suite-native/receive/src/screens/ReceiveAddressScreen.tsx
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: build-deploy
  • GitHub Check: build-deploy
  • GitHub Check: EAS Update
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: build
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: prepare_android_test_app
  • GitHub Check: test
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: transport-e2e-test
  • GitHub Check: build-web
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Socket Security: Pull Request Alerts
🔇 Additional comments (5)
suite-native/transactions/src/components/TransactionsEmptyState.tsx (2)

1-1: LGTM!

The new imports are correctly placed and necessary for implementing the firmware authenticity check.

Also applies to: 6-6


21-24: LGTM!

The firmware authenticity check is correctly implemented using the selector, and the showReceiveButton flag is appropriately derived from the check result.

suite-native/module-accounts-management/src/components/TransactionListHeader.tsx (3)

15-15: LGTM!

The new import is correctly placed and necessary for implementing the firmware authenticity check.


100-102: LGTM!

The firmware authenticity check is correctly implemented using the selector, and the isReceiveButtonDisplayed flag is appropriately derived from the check result.

Also applies to: 132-132


148-148: Verify test coverage for conditional rendering.

The component uses test ID @account-detail/receive-button. Please ensure that tests are updated to cover the new conditional rendering behavior.

Copy link

github-actions bot commented Feb 4, 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

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.

Block Receive as per FW revision check
2 participants