import AsyncStorage from '@react-native-community/async-storage'; import { StackNavigationProp } from '@react-navigation/stack'; import React, { useEffect, useState } from 'react'; import { Switch } from 'react-native'; import * as List from '../containers/List'; import SafeAreaView from '../containers/SafeAreaView'; import StatusBar from '../containers/StatusBar'; import I18n from '../i18n'; import { ANALYTICS_EVENTS_KEY, CRASH_REPORT_KEY, isFDroidBuild, SWITCH_TRACK_COLOR } from '../lib/constants'; import { useAppSelector } from '../lib/hooks'; import useServer from '../lib/methods/useServer'; import { SettingsStackParamList } from '../stacks/types'; import { handleLocalAuthentication } from '../lib/methods/helpers/localAuthentication'; import { events, getReportAnalyticsEventsValue, getReportCrashErrorsValue, logEvent, toggleAnalyticsEventsReport, toggleCrashErrorsReport } from '../lib/methods/helpers/log'; interface ISecurityPrivacyViewProps { navigation: StackNavigationProp; } const SecurityPrivacyView = ({ navigation }: ISecurityPrivacyViewProps): JSX.Element => { const [crashReportState, setCrashReportState] = useState(getReportCrashErrorsValue()); const [analyticsEventsState, setAnalyticsEventsState] = useState(getReportAnalyticsEventsValue()); const [server] = useServer(); const e2eEnabled = useAppSelector(state => state.settings.E2E_Enable); useEffect(() => { navigation.setOptions({ title: I18n.t('Security_and_privacy') }); }, [navigation]); const toggleCrashReport = (value: boolean) => { logEvent(events.SP_TOGGLE_CRASH_REPORT); AsyncStorage.setItem(CRASH_REPORT_KEY, JSON.stringify(value)); setCrashReportState(value); toggleCrashErrorsReport(value); }; const toggleAnalyticsEvents = (value: boolean) => { logEvent(events.SP_TOGGLE_ANALYTICS_EVENTS); AsyncStorage.setItem(ANALYTICS_EVENTS_KEY, JSON.stringify(value)); setAnalyticsEventsState(value); toggleAnalyticsEventsReport(value); }; const navigateToScreen = (screen: 'E2EEncryptionSecurityView' | 'ScreenLockConfigView') => { // @ts-ignore logEvent(events[`SP_GO_${screen.replace('View', '').toUpperCase()}`]); navigation.navigate(screen); }; const navigateToScreenLockConfigView = async () => { if (server?.autoLock) { await handleLocalAuthentication(true); } navigateToScreen('ScreenLockConfigView'); }; return ( {e2eEnabled ? ( <> navigateToScreen('E2EEncryptionSecurityView')} testID='security-privacy-view-e2e-encryption' /> ) : null} {!isFDroidBuild ? ( <> ( )} /> ( )} /> ) : null} ); }; export default SecurityPrivacyView;