Skip to content

Commit

Permalink
feat(suite-native): block receiving when device compromised
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemonexe committed Jan 31, 2025
1 parent 8cae3e0 commit 3b847d2
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 14 deletions.
3 changes: 3 additions & 0 deletions suite-native/intl/src/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@ export const en = {
reportIssueButton: 'Report security issue',
},
},
deviceCompromisedScreen: {
title: 'Receiving is disabled',
},
},
moduleSettings: {
items: {
Expand Down
1 change: 1 addition & 0 deletions suite-native/module-accounts-management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@suite-native/alerts": "workspace:*",
"@suite-native/analytics": "workspace:*",
"@suite-native/atoms": "workspace:*",
"@suite-native/device": "workspace:*",
"@suite-native/device-manager": "workspace:*",
"@suite-native/feature-flags": "workspace:*",
"@suite-native/formatters": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@suite-common/wallet-core';
import { AccountKey, TokenAddress } from '@suite-common/wallet-types';
import { Box, Button, HStack, Text, VStack } from '@suite-native/atoms';
import { selectHasFirmwareAuthenticityCheckHardFailed } from '@suite-native/device';
import { FeatureFlag, FeatureFlagsRootState, useFeatureFlag } from '@suite-native/feature-flags';
import { Translation } from '@suite-native/intl';
import {
Expand Down Expand Up @@ -96,6 +97,9 @@ export const TransactionListHeader = memo(
selectIsNetworkSendFlowEnabled(state, account?.symbol),
);
const isPortfolioTrackerDevice = useSelector(selectIsPortfolioTrackerDevice);
const hasFirmwareAuthenticityCheckHardFailed = useSelector(
selectHasFirmwareAuthenticityCheckHardFailed,
);

if (!account) return null;

Expand Down Expand Up @@ -125,6 +129,7 @@ export const TransactionListHeader = memo(

const isSendButtonDisplayed =
isDeviceConnectEnabled && isNetworkSendFlowEnabled && !isPortfolioTrackerDevice;
const isReceiveButtonDisplayed = !hasFirmwareAuthenticityCheckHardFailed;

return (
<>
Expand All @@ -135,15 +140,17 @@ export const TransactionListHeader = memo(
/>
{accountHasTransactions && (
<HStack paddingTop="sp8" paddingHorizontal="sp16" flex={1} spacing="sp12">
<Box flex={1}>
<Button
viewLeft="arrowLineDown"
onPress={handleReceive}
testID="@account-detail/receive-button"
>
<Translation id="transactions.receive" />
</Button>
</Box>
{isReceiveButtonDisplayed && (
<Box flex={1}>
<Button
viewLeft="arrowLineDown"
onPress={handleReceive}
testID="@account-detail/receive-button"
>
<Translation id="transactions.receive" />
</Button>
</Box>
)}
{isSendButtonDisplayed && (
<Box flex={1}>
<Button
Expand Down
1 change: 1 addition & 0 deletions suite-native/module-accounts-management/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{ "path": "../alerts" },
{ "path": "../analytics" },
{ "path": "../atoms" },
{ "path": "../device" },
{ "path": "../device-manager" },
{ "path": "../feature-flags" },
{ "path": "../formatters" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useNavigation } from '@react-navigation/native';
import { selectHasDeviceDiscovery, selectIsDeviceAuthorized } from '@suite-common/wallet-core';
import { Assets } from '@suite-native/assets';
import { AnimatedVStack, Button, VStack } from '@suite-native/atoms';
import { selectHasFirmwareAuthenticityCheckHardFailed } from '@suite-native/device';
import { Translation } from '@suite-native/intl';
import {
ReceiveStackRoutes,
Expand All @@ -22,7 +23,11 @@ export const PortfolioContent = forwardRef<PortfolioGraphRef>((_props, ref) => {

const isDeviceAuthorized = useSelector(selectIsDeviceAuthorized);
const hasDiscovery = useSelector(selectHasDeviceDiscovery);
const showReceiveButton = isDeviceAuthorized && !hasDiscovery;
const hasFirmwareAuthenticityCheckHardFailed = useSelector(
selectHasFirmwareAuthenticityCheckHardFailed,
);
const showReceiveButton =
isDeviceAuthorized && !hasDiscovery && !hasFirmwareAuthenticityCheckHardFailed;

const handleReceive = () => {
navigation.navigate(RootStackRoutes.ReceiveStack, {
Expand Down
9 changes: 9 additions & 0 deletions suite-native/receive/src/screens/ReceiveAccountsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useSelector } from 'react-redux';

import { useNavigation } from '@react-navigation/native';

import { AccountsList, AddAccountButton, OnSelectAccount } from '@suite-native/accounts';
import { selectHasFirmwareAuthenticityCheckHardFailed } from '@suite-native/device';
import { useTranslate } from '@suite-native/intl';
import {
ReceiveStackParamList,
Expand All @@ -10,6 +13,8 @@ import {
StackNavigationProps,
} from '@suite-native/navigation';

import { ReceiveBlockedDeviceCompromisedScreen } from './ReceiveBlockedDeviceCompromisedScreen';

type NavigationProp = StackNavigationProps<
ReceiveStackParamList,
ReceiveStackRoutes.ReceiveAccounts
Expand All @@ -18,6 +23,10 @@ type NavigationProp = StackNavigationProps<
export const ReceiveAccountsScreen = () => {
const { translate } = useTranslate();
const navigation = useNavigation<NavigationProp>();
const hasFirmwareAuthenticityCheckHardFailed = useSelector(
selectHasFirmwareAuthenticityCheckHardFailed,
);
if (hasFirmwareAuthenticityCheckHardFailed) return <ReceiveBlockedDeviceCompromisedScreen />;

const navigateToReceiveScreen: OnSelectAccount = ({ account, tokenAddress }) =>
navigation.navigate(ReceiveStackRoutes.ReceiveAccount, {
Expand Down
11 changes: 10 additions & 1 deletion suite-native/receive/src/screens/ReceiveAddressScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import {
} from '@suite-common/wallet-core';
import { AccountKey, TokenAddress } from '@suite-common/wallet-types';
import { Box, ErrorMessage, VStack } from '@suite-native/atoms';
import { ConfirmOnTrezorImage } from '@suite-native/device';
import {
ConfirmOnTrezorImage,
selectHasFirmwareAuthenticityCheckHardFailed,
} from '@suite-native/device';
import { Translation } from '@suite-native/intl';
import { CloseActionType, Screen } from '@suite-native/navigation';

import { ReceiveBlockedDeviceCompromisedScreen } from './ReceiveBlockedDeviceCompromisedScreen';
import { ReceiveAccountDetailsCard } from '../components/ReceiveAccountDetailsCard';
import { ReceiveAddressCard } from '../components/ReceiveAddressCard';
import { ReceiveScreenHeader } from '../components/ReceiveScreenHeader';
Expand Down Expand Up @@ -42,6 +46,11 @@ export const ReceiveAddressScreen = ({
const { address, isReceiveApproved, isUnverifiedAddressRevealed, handleShowAddress } =
useAccountReceiveAddress(accountKey);

const hasFirmwareAuthenticityCheckHardFailed = useSelector(
selectHasFirmwareAuthenticityCheckHardFailed,
);
if (hasFirmwareAuthenticityCheckHardFailed) return <ReceiveBlockedDeviceCompromisedScreen />;

const isAccountDetailVisible = !isUnverifiedAddressRevealed && !isReceiveApproved;

if (G.isNullable(account) || G.isNullable(address)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { PictogramTitleHeader, VStack } from '@suite-native/atoms';
import { Translation } from '@suite-native/intl';
import { Screen, ScreenHeader } from '@suite-native/navigation';

export const ReceiveBlockedDeviceCompromisedScreen = () => (
<Screen header={<ScreenHeader closeActionType="back" />}>
<VStack justifyContent="center" flex={1}>
<PictogramTitleHeader
variant="critical"
title={<Translation id="moduleReceive.deviceCompromisedScreen.title" />}
titleVariant="titleSmall"
/>
</VStack>
</Screen>
);
1 change: 1 addition & 0 deletions suite-native/transactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@suite-common/wallet-utils": "workspace:*",
"@suite-native/analytics": "workspace:*",
"@suite-native/atoms": "workspace:*",
"@suite-native/device": "workspace:*",
"@suite-native/formatters": "workspace:*",
"@suite-native/helpers": "workspace:*",
"@suite-native/icons": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useSelector } from 'react-redux';

import { useNavigation } from '@react-navigation/native';

import { Box, Button, Text, VStack } from '@suite-native/atoms';
import { selectHasFirmwareAuthenticityCheckHardFailed } from '@suite-native/device';
import { Translation } from '@suite-native/intl';
import {
ReceiveStackRoutes,
Expand All @@ -15,6 +18,10 @@ type NavigationProp = StackNavigationProps<RootStackParamList, RootStackRoutes.A

export const TransactionsEmptyState = ({ accountKey }: { accountKey: string }) => {
const navigation = useNavigation<NavigationProp>();
const hasFirmwareAuthenticityCheckHardFailed = useSelector(
selectHasFirmwareAuthenticityCheckHardFailed,
);
const showReceiveButton = !hasFirmwareAuthenticityCheckHardFailed;

const handleReceive = () => {
navigation.navigate(RootStackRoutes.ReceiveStack, {
Expand All @@ -39,9 +46,11 @@ export const TransactionsEmptyState = ({ accountKey }: { accountKey: string }) =
</Text>
</VStack>
</Box>
<Button viewLeft="arrowLineDown" onPress={handleReceive} size="large">
<Translation id="transactions.emptyState.button" />
</Button>
{showReceiveButton && (
<Button viewLeft="arrowLineDown" onPress={handleReceive} size="large">
<Translation id="transactions.emptyState.button" />
</Button>
)}
</VStack>
);
};
1 change: 1 addition & 0 deletions suite-native/transactions/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
{ "path": "../analytics" },
{ "path": "../atoms" },
{ "path": "../device" },
{ "path": "../formatters" },
{ "path": "../helpers" },
{ "path": "../icons" },
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10595,6 +10595,7 @@ __metadata:
"@suite-native/alerts": "workspace:*"
"@suite-native/analytics": "workspace:*"
"@suite-native/atoms": "workspace:*"
"@suite-native/device": "workspace:*"
"@suite-native/device-manager": "workspace:*"
"@suite-native/feature-flags": "workspace:*"
"@suite-native/formatters": "workspace:*"
Expand Down Expand Up @@ -11264,6 +11265,7 @@ __metadata:
"@suite-common/wallet-utils": "workspace:*"
"@suite-native/analytics": "workspace:*"
"@suite-native/atoms": "workspace:*"
"@suite-native/device": "workspace:*"
"@suite-native/formatters": "workspace:*"
"@suite-native/helpers": "workspace:*"
"@suite-native/icons": "workspace:*"
Expand Down

0 comments on commit 3b847d2

Please sign in to comment.