-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite-native): add Check Settings to toggle FW revision check
- Loading branch information
Showing
10 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
suite-native/module-settings/src/components/TurnOffFirmwareAuthenticityCheckCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
|
||
import { | ||
selectIsFirmwareAuthenticityCheckEnabled, | ||
setCheckFirmwareAuthenticity, | ||
SettingsCardWithIconLayout, | ||
} from '@suite-native/settings'; | ||
import { Translation } from '@suite-native/intl'; | ||
import { Button, HStack, Text, VStack } from '@suite-native/atoms'; | ||
import { SettingsStackRoutes } from '@suite-native/navigation'; | ||
import { useOpenLink } from '@suite-native/link'; | ||
import { useToast } from '@suite-native/toasts'; | ||
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; | ||
|
||
import { useSettingsNavigateTo } from '../navigation/useSettingsNavigateTo'; | ||
|
||
// TODO this page is for desktop; await creation of new page tailored to the suite-native UX | ||
const HELP_CENTER_FIRMWARE_REVISION_CHECK = | ||
'https://trezor.io/learn/a/trezor-firmware-authenticity-check'; | ||
|
||
const fullWidthButtonStyle = prepareNativeStyle(() => ({ flex: 1 })); | ||
|
||
const LearnMoreButton = () => { | ||
const { applyStyle } = useNativeStyles(); | ||
const openLink = useOpenLink(); | ||
const handleButtonPress = () => openLink(HELP_CENTER_FIRMWARE_REVISION_CHECK); | ||
|
||
return ( | ||
<Button | ||
size="small" | ||
onPress={handleButtonPress} | ||
colorScheme="tertiaryElevation0" | ||
style={applyStyle(fullWidthButtonStyle)} | ||
> | ||
<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.buttonLearnMore" /> | ||
</Button> | ||
); | ||
}; | ||
|
||
const TurnOnButton = () => { | ||
const { applyStyle } = useNativeStyles(); | ||
const dispatch = useDispatch(); | ||
const { showToast } = useToast(); | ||
const handleButtonPress = () => { | ||
dispatch(setCheckFirmwareAuthenticity(true)); | ||
showToast({ | ||
variant: 'default', | ||
message: 'Authenticity check turned on', | ||
icon: 'check', | ||
}); | ||
}; | ||
|
||
return ( | ||
<Button | ||
size="small" | ||
onPress={handleButtonPress} | ||
colorScheme="primary" | ||
style={applyStyle(fullWidthButtonStyle)} | ||
> | ||
<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.buttonTurnOn" /> | ||
</Button> | ||
); | ||
}; | ||
|
||
const TurnOffButton = () => { | ||
const navigateTo = useSettingsNavigateTo(); | ||
|
||
const handleButtonPress = () => { | ||
navigateTo(SettingsStackRoutes.TurnOffFirmwareAuthenticityCheckModal); | ||
}; | ||
|
||
return ( | ||
<Button size="small" onPress={handleButtonPress} colorScheme="redElevation0"> | ||
<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.buttonTurnOff" /> | ||
</Button> | ||
); | ||
}; | ||
|
||
export const TurnOffFirmwareAuthenticityCheckCard = () => { | ||
const isFwAuthenticityCheckEnabled = useSelector(selectIsFirmwareAuthenticityCheckEnabled); | ||
|
||
return ( | ||
<SettingsCardWithIconLayout | ||
icon="shieldCheck" | ||
title={<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.title" />} | ||
> | ||
<VStack spacing="sp16"> | ||
<Text variant="hint" color="textSubdued"> | ||
<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.subtitle" /> | ||
</Text> | ||
<HStack spacing="sp8"> | ||
{isFwAuthenticityCheckEnabled ? ( | ||
<> | ||
<TurnOffButton /> | ||
<LearnMoreButton /> | ||
</> | ||
) : ( | ||
<> | ||
<LearnMoreButton /> | ||
<TurnOnButton /> | ||
</> | ||
)} | ||
</HStack> | ||
</VStack> | ||
</SettingsCardWithIconLayout> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
suite-native/module-settings/src/screens/SettingsDeviceChecksScreen.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Screen, ScreenHeader } from '@suite-native/navigation'; | ||
import { useTranslate } from '@suite-native/intl'; | ||
|
||
import { TurnOffFirmwareAuthenticityCheckCard } from '../components/TurnOffFirmwareAuthenticityCheckCard'; | ||
|
||
export const SettingsDeviceChecksScreen = () => { | ||
const { translate } = useTranslate(); | ||
|
||
return ( | ||
<Screen header={<ScreenHeader content={translate('moduleSettings.deviceChecks.title')} />}> | ||
<TurnOffFirmwareAuthenticityCheckCard /> | ||
</Screen> | ||
); | ||
}; |
119 changes: 119 additions & 0 deletions
119
suite-native/module-settings/src/screens/TurnOffFirmwareAuthenticityCheckModalScreen.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { useState } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { Pressable } from 'react-native'; | ||
import Animated, { FadeIn, FadeOut } from 'react-native-reanimated'; | ||
|
||
import { useNavigation } from '@react-navigation/native'; | ||
|
||
import { | ||
Screen, | ||
ScreenHeader, | ||
SettingsStackParamList, | ||
SettingsStackRoutes, | ||
StackNavigationProps, | ||
} from '@suite-native/navigation'; | ||
import { | ||
Button, | ||
Card, | ||
CheckBox, | ||
HStack, | ||
IconListItem, | ||
Text, | ||
TitleHeader, | ||
VStack, | ||
} from '@suite-native/atoms'; | ||
import { Translation } from '@suite-native/intl'; | ||
import { setCheckFirmwareAuthenticity } from '@suite-native/settings'; | ||
import { useToast } from '@suite-native/toasts'; | ||
|
||
const CHECKBOX_ANIMATION_DURATION = 200; // same as in useAccordionAnimation | ||
|
||
const InformativeList = () => ( | ||
<VStack spacing="sp24"> | ||
<IconListItem icon="warning" variant="yellow" iconSize="large" verticalAlign="flex-start"> | ||
<VStack spacing="sp4"> | ||
<Text variant="highlight"> | ||
<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.turnOffModal.item1" /> | ||
</Text> | ||
<Text variant="hint" color="textSubdued"> | ||
<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.turnOffModal.item1Explanation" /> | ||
</Text> | ||
</VStack> | ||
</IconListItem> | ||
<IconListItem icon="code" variant="yellow" iconSize="large" verticalAlign="flex-start"> | ||
<VStack spacing="sp4"> | ||
<Text variant="highlight"> | ||
<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.turnOffModal.item2" /> | ||
</Text> | ||
<Text variant="hint" color="textSubdued"> | ||
<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.turnOffModal.item2Explanation" /> | ||
</Text> | ||
</VStack> | ||
</IconListItem> | ||
</VStack> | ||
); | ||
|
||
type NavigationProp = StackNavigationProps< | ||
SettingsStackParamList, | ||
SettingsStackRoutes.SettingsDeviceChecks | ||
>; | ||
|
||
export const TurnOffFirmwareAuthenticityCheckModalScreen = () => { | ||
const [isChecked, setIsChecked] = useState(false); | ||
const navigation = useNavigation<NavigationProp>(); | ||
const dispatch = useDispatch(); | ||
const { showToast } = useToast(); | ||
|
||
const handleCheckboxPress = () => setIsChecked(prev => !prev); | ||
|
||
const handleButtonPress = () => { | ||
dispatch(setCheckFirmwareAuthenticity(false)); | ||
if (navigation.canGoBack()) { | ||
navigation.goBack(); | ||
} else { | ||
navigation.navigate(SettingsStackRoutes.SettingsDeviceChecks); | ||
} | ||
showToast({ | ||
variant: 'default', | ||
message: 'Authenticity check turned off', | ||
icon: 'check', | ||
}); | ||
}; | ||
|
||
return ( | ||
<Screen header={<ScreenHeader closeActionType="close" />}> | ||
<VStack spacing="sp32" flex={1}> | ||
<TitleHeader | ||
titleVariant="titleMedium" | ||
title={ | ||
<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.turnOffModal.title" /> | ||
} | ||
subtitle={ | ||
<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.turnOffModal.content" /> | ||
} | ||
/> | ||
<InformativeList /> | ||
<Pressable onPress={handleCheckboxPress}> | ||
<Card> | ||
<HStack spacing="sp16"> | ||
<CheckBox isChecked={isChecked} onChange={handleCheckboxPress} /> | ||
<Text variant="highlight"> | ||
<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.turnOffModal.acknowledgement" /> | ||
</Text> | ||
</HStack> | ||
</Card> | ||
</Pressable> | ||
</VStack> | ||
{isChecked && ( | ||
<Animated.View | ||
entering={FadeIn.duration(CHECKBOX_ANIMATION_DURATION)} | ||
exiting={FadeOut.duration(CHECKBOX_ANIMATION_DURATION)} | ||
> | ||
<Button colorScheme="yellowBold" onPress={handleButtonPress}> | ||
<Translation id="moduleSettings.deviceChecks.firmwareAuthenticityCheck.turnOffModal.buttonTurnOff" /> | ||
</Button> | ||
</Animated.View> | ||
)} | ||
</Screen> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters