()
| 59 | }; |
| 60 | |
| 61 | const EncryptStorage = () => { |
| 62 | const { isStorageEncrypted } = useStorage(); |
| 63 | const { isDeviceBiometricCapable, biometricEnabled, setBiometricUseEnabled, deviceBiometricType } = useBiometrics(); |
| 64 | const [state, dispatch] = useReducer(reducer, initialState); |
| 65 | const navigation = useExtendedNavigation(); |
| 66 | const { colors } = useTheme(); |
| 67 | |
| 68 | const styleHooks = StyleSheet.create({ |
| 69 | root: { |
| 70 | backgroundColor: colors.background, |
| 71 | }, |
| 72 | }); |
| 73 | |
| 74 | const initializeState = useCallback(async () => { |
| 75 | const isStorageEncryptedSwitchEnabled = await isStorageEncrypted(); |
| 76 | const isDeviceBiometricCapableSync = await isDeviceBiometricCapable(); |
| 77 | dispatch({ type: ActionType.SetStorageEncryptedSwitch, payload: isStorageEncryptedSwitchEnabled }); |
| 78 | dispatch({ type: ActionType.SetDeviceBiometricCapable, payload: isDeviceBiometricCapableSync }); |
| 79 | dispatch({ type: ActionType.SetLoading, payload: false }); |
| 80 | }, [isStorageEncrypted, isDeviceBiometricCapable]); |
| 81 | |
| 82 | useEffect(() => { |
| 83 | initializeState(); |
| 84 | }, [initializeState]); |
| 85 | |
| 86 | useFocusEffect( |
| 87 | useCallback(() => { |
| 88 | initializeState(); |
| 89 | dispatch({ type: ActionType.SetLoading, payload: false }); |
| 90 | dispatch({ type: ActionType.SetCurrentLoadingSwitch, payload: null }); |
| 91 | }, [initializeState]), |
| 92 | ); |
| 93 | |
| 94 | const handleDecryptStorage = async () => { |
| 95 | dispatch({ type: ActionType.SetModalType, payload: MODAL_TYPES.ENTER_PASSWORD }); |
| 96 | navigation.navigate('PromptPasswordConfirmationSheet', { |
| 97 | modalType: MODAL_TYPES.ENTER_PASSWORD, |
| 98 | returnTo: 'EncryptStorage', |
| 99 | }); |
| 100 | }; |
| 101 | |
| 102 | const onEncryptStorageSwitch = async (value: boolean) => { |
| 103 | dispatch({ type: ActionType.SetCurrentLoadingSwitch, payload: 'encrypt' }); |
| 104 | dispatch({ type: ActionType.SetLoading, payload: true }); |
| 105 | |
| 106 | if (value) { |
| 107 | dispatch({ type: ActionType.SetModalType, payload: MODAL_TYPES.CREATE_PASSWORD }); |
| 108 | navigation.navigate('PromptPasswordConfirmationSheet', { |
| 109 | modalType: MODAL_TYPES.CREATE_PASSWORD, |
| 110 | returnTo: 'EncryptStorage', |
| 111 | }); |
| 112 | } else { |
| 113 | Alert.alert( |
| 114 | loc.settings.encrypt_decrypt, |
| 115 | loc.settings.encrypt_decrypt_q, |
| 116 | [ |
| 117 | { |
| 118 | text: loc._.cancel, |
nothing calls this directly
no test coverage detected