|
| 1 | +import { useDispatch } from 'react-redux'; |
| 2 | + |
| 3 | +import { CommonActions } from '@react-navigation/core'; |
| 4 | + |
| 5 | +import { setIsOnboardingFinished } from '@suite-native/settings'; |
| 6 | +import { |
| 7 | + HomeStackRoutes, |
| 8 | + OnboardingStackParamList, |
| 9 | + OnboardingStackRoutes, |
| 10 | + RootStackRoutes, |
| 11 | + Screen, |
| 12 | + ScreenHeader, |
| 13 | + StackProps, |
| 14 | +} from '@suite-native/navigation'; |
| 15 | +import { Box, Button, HStack, Text, VStack } from '@suite-native/atoms'; |
| 16 | +import { Translation } from '@suite-native/intl'; |
| 17 | +import { EventType, analytics } from '@suite-native/analytics'; |
| 18 | +import { BiometricsSvg, useBiometricsSettings } from '@suite-native/biometrics'; |
| 19 | +import { Icon } from '@suite-native/icons'; |
| 20 | + |
| 21 | +export const BiometricsScreen = ({ |
| 22 | + navigation, |
| 23 | +}: StackProps<OnboardingStackParamList, OnboardingStackRoutes.Biometrics>) => { |
| 24 | + const { toggleBiometricsOption } = useBiometricsSettings(); |
| 25 | + |
| 26 | + const dispatch = useDispatch(); |
| 27 | + |
| 28 | + const enableBiometrics = async () => { |
| 29 | + const result = await toggleBiometricsOption(); |
| 30 | + if (result === 'enabled') { |
| 31 | + analytics.report({ |
| 32 | + type: EventType.BiometricsChange, |
| 33 | + payload: { |
| 34 | + enabled: true, |
| 35 | + origin: 'bottomSheet', |
| 36 | + }, |
| 37 | + }); |
| 38 | + } |
| 39 | + }; |
| 40 | + |
| 41 | + const exitOnboardingFlow = () => { |
| 42 | + dispatch(setIsOnboardingFinished()); |
| 43 | + |
| 44 | + navigation.dispatch( |
| 45 | + CommonActions.reset({ |
| 46 | + index: 0, |
| 47 | + routes: [ |
| 48 | + { |
| 49 | + name: RootStackRoutes.AppTabs, |
| 50 | + params: { |
| 51 | + screen: HomeStackRoutes.Home, |
| 52 | + }, |
| 53 | + }, |
| 54 | + ], |
| 55 | + }), |
| 56 | + ); |
| 57 | + }; |
| 58 | + |
| 59 | + const handleEnableButtonPress = async () => { |
| 60 | + await enableBiometrics(); |
| 61 | + exitOnboardingFlow(); |
| 62 | + }; |
| 63 | + |
| 64 | + const handleNotNowButtonPress = () => { |
| 65 | + exitOnboardingFlow(); |
| 66 | + }; |
| 67 | + |
| 68 | + return ( |
| 69 | + <Screen header={<ScreenHeader />}> |
| 70 | + <VStack justifyContent="space-between" flex={1}> |
| 71 | + <Box flex={1} alignItems="center" paddingTop="sp32"> |
| 72 | + <BiometricsSvg /> |
| 73 | + </Box> |
| 74 | + <VStack spacing={40}> |
| 75 | + <VStack spacing="sp16"> |
| 76 | + <HStack spacing="sp8" alignItems="center"> |
| 77 | + <Icon |
| 78 | + name="fingerprint" |
| 79 | + color="textSecondaryHighlight" |
| 80 | + size="mediumLarge" |
| 81 | + /> |
| 82 | + <Text color="textSecondaryHighlight"> |
| 83 | + <Translation id="moduleOnboarding.biometricsScreen.title" /> |
| 84 | + </Text> |
| 85 | + </HStack> |
| 86 | + <Text variant="titleMedium"> |
| 87 | + <Translation id="moduleOnboarding.biometricsScreen.description" /> |
| 88 | + </Text> |
| 89 | + </VStack> |
| 90 | + <VStack spacing="sp12"> |
| 91 | + <Button |
| 92 | + testID="@onboarding/UserDataConsent/enable" |
| 93 | + onPress={handleEnableButtonPress} |
| 94 | + > |
| 95 | + <Translation id="generic.buttons.enable" /> |
| 96 | + </Button> |
| 97 | + <Button |
| 98 | + colorScheme="tertiaryElevation0" |
| 99 | + testID="@onboarding/Biometrics/skip" |
| 100 | + onPress={handleNotNowButtonPress} |
| 101 | + > |
| 102 | + <Translation id="moduleOnboarding.biometricsScreen.button.notNow" /> |
| 103 | + </Button> |
| 104 | + </VStack> |
| 105 | + </VStack> |
| 106 | + </VStack> |
| 107 | + </Screen> |
| 108 | + ); |
| 109 | +}; |
0 commit comments