MCPcopy Index your code
hub / github.com/BlueWallet/BlueWallet / EncryptStorage

Function EncryptStorage

screen/settings/EncryptStorage.tsx:61–201  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59};
60
61const 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,

Callers

nothing calls this directly

Calls 5

useStorageFunction · 0.90
useBiometricsFunction · 0.90
useExtendedNavigationFunction · 0.90
useThemeFunction · 0.90
dispatchFunction · 0.85

Tested by

no test coverage detected