import React, { useContext, useEffect, useState } from 'react'; import { Platform, Pressable, ScrollView, StyleSheet, Text, TouchableWithoutFeedback, View } from 'react-native'; import { openSettings } from 'react-native-permissions'; import A from '../../blue_modules/analytics'; import { BlueStorageContext } from '../../blue_modules/storage-context'; import { BlueCard, BlueSpacing20, BlueSpacing40, BlueText } from '../../BlueComponents'; import { useSettings } from '../../components/Context/SettingsContext'; import { Header } from '../../components/Header'; import ListItem from '../../components/ListItem'; import { useTheme } from '../../components/themes'; import { setBalanceDisplayAllowed } from '../../components/WidgetCommunication'; import loc from '../../loc'; enum SettingsPrivacySection { None, All, ReadClipboard, QuickActions, Widget, } const SettingsPrivacy: React.FC = () => { const { colors } = useTheme(); const { isStorageEncrypted } = useStorage(); const { isDoNotTrackEnabled, setDoNotTrackStorage, setIsPrivacyBlurEnabledState, isWidgetBalanceDisplayAllowed, setIsWidgetBalanceDisplayAllowedStorage, isClipboardGetContentEnabled, setIsClipboardGetContentEnabledStorage, isQuickActionsEnabled, setIsQuickActionsEnabledStorage, } = useSettings(); const [isLoading, setIsLoading] = useState(SettingsPrivacySection.All); const [storageIsEncrypted, setStorageIsEncrypted] = useState(true); const [isPrivacyBlurEnabledTapped, setIsPrivacyBlurEnabledTapped] = useState(0); const styleHooks = StyleSheet.create({ root: { backgroundColor: colors.background, }, widgetsHeader: { color: colors.foregroundColor, }, }); useEffect(() => { (async () => { try { setStorageIsEncrypted(await isStorageEncrypted()); } catch (e) { console.log(e); } setIsLoading(SettingsPrivacySection.None); })(); }, [isStorageEncrypted]); const onDoNotTrackValueChange = async (value: boolean) => { setIsLoading(SettingsPrivacySection.All); try { setDoNotTrackStorage(value); A.setOptOut(value); } catch (e) { console.debug('onDoNotTrackValueChange catch', e); } setIsLoading(SettingsPrivacySection.None); }; const onQuickActionsValueChange = async (value: boolean) => { setIsLoading(SettingsPrivacySection.QuickActions); try { setIsQuickActionsEnabledStorage(value); } catch (e) { console.debug('onQuickActionsValueChange catch', e); } setIsLoading(SettingsPrivacySection.None); }; const onWidgetsTotalBalanceValueChange = async (value: boolean) => { setIsLoading(SettingsPrivacySection.Widget); try { await setBalanceDisplayAllowed(value); setIsWidgetBalanceDisplayAllowedStorage(value); } catch (e) { console.debug('onWidgetsTotalBalanceValueChange catch', e); } setIsLoading(SettingsPrivacySection.None); }; const openApplicationSettings = () => { openSettings(); }; const onDisablePrivacyTapped = () => { setIsPrivacyBlurEnabledState(!(isPrivacyBlurEnabledTapped >= 10)); setIsPrivacyBlurEnabledTapped(prev => prev + 1); }; return ( {Platform.OS === 'android' ? (
) : null} {loc.settings.privacy_clipboard_explanation} {} {loc.settings.privacy_quickactions_explanation} {storageIsEncrypted && {loc.settings.encrypted_feature_disabled}} {loc.settings.privacy_do_not_track_explanation} {Platform.OS === 'ios' && ( <> {loc.settings.widgets} {loc.settings.total_balance_explanation} {storageIsEncrypted && {loc.settings.encrypted_feature_disabled}} )} ); }; const styles = StyleSheet.create({ root: { flex: 1, }, widgetsHeader: { fontWeight: 'bold', fontSize: 30, marginLeft: 17, }, headerContainer: { paddingVertical: 16, }, }); export default SettingsPrivacy;