BlueWallet/screen/settings/SettingsPrivacy.js

190 lines
6.0 KiB
JavaScript
Raw Normal View History

import React, { useContext, useEffect, useState } from 'react';
2023-10-23 20:50:17 +02:00
import { ScrollView, TouchableWithoutFeedback, StyleSheet, Platform, Pressable, Text } from 'react-native';
import { openSettings } from 'react-native-permissions';
2020-12-25 17:09:53 +01:00
import navigationStyle from '../../components/navigationStyle';
2023-12-16 22:44:35 +01:00
import { BlueText, BlueSpacing20, BlueCard, BlueHeaderDefaultSub, BlueSpacing40 } from '../../BlueComponents';
import loc from '../../loc';
import { BlueStorageContext } from '../../blue_modules/storage-context';
2023-10-24 03:28:44 +02:00
import { useTheme } from '../../components/themes';
2023-12-16 22:44:35 +01:00
import ListItem from '../../components/ListItem';
import A from '../../blue_modules/analytics';
2024-04-18 03:05:48 +02:00
import { useSettings } from '../../components/Context/SettingsContext';
import { setBalanceDisplayAllowed } from '../../components/WidgetCommunication';
const SettingsPrivacy = () => {
const { colors } = useTheme();
2024-04-18 03:05:48 +02:00
const { isStorageEncrypted } = useContext(BlueStorageContext);
const {
isDoNotTrackEnabled,
setDoNotTrackStorage,
2024-04-18 19:48:22 +02:00
setIsPrivacyBlurEnabledState,
2024-04-18 03:05:48 +02:00
isWidgetBalanceDisplayAllowed,
setIsWidgetBalanceDisplayAllowedStorage,
isClipboardGetContentEnabled,
setIsClipboardGetContentEnabledStorage,
2024-04-18 19:48:22 +02:00
isQuickActionsEnabled,
setIsQuickActionsEnabledStorage,
2024-04-18 03:05:48 +02:00
} = useSettings();
const sections = Object.freeze({ ALL: 0, CLIPBOARDREAD: 1, QUICKACTION: 2, WIDGETS: 3 });
const [isLoading, setIsLoading] = useState(sections.ALL);
const [storageIsEncrypted, setStorageIsEncrypted] = useState(true);
2021-09-25 17:04:45 +02:00
const [isPrivacyBlurEnabledTapped, setIsPrivacyBlurEnabledTapped] = useState(0);
2023-10-23 20:50:17 +02:00
const styleHooks = StyleSheet.create({
widgetsHeader: {
color: colors.foregroundColor,
},
});
useEffect(() => {
(async () => {
try {
setStorageIsEncrypted(await isStorageEncrypted());
} catch (e) {
console.log(e);
}
setIsLoading(false);
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const onDoNotTrackValueChange = async value => {
setIsLoading(sections.ALL);
try {
2024-04-18 03:05:48 +02:00
setDoNotTrackStorage(value);
2024-04-07 02:13:12 +02:00
A.setOptOut(value);
} catch (e) {
console.log(e);
}
setIsLoading(false);
};
const onQuickActionsValueChange = async value => {
setIsLoading(sections.QUICKACTION);
try {
2024-04-18 19:48:22 +02:00
setIsQuickActionsEnabledStorage(value);
} catch (e) {
console.log(e);
}
setIsLoading(false);
};
const onWidgetsTotalBalanceValueChange = async value => {
setIsLoading(sections.WIDGETS);
try {
await setBalanceDisplayAllowed(value);
2024-04-18 03:05:48 +02:00
setIsWidgetBalanceDisplayAllowedStorage(value);
} catch (e) {
console.log(e);
}
setIsLoading(false);
};
const stylesWithThemeHook = StyleSheet.create({
root: {
backgroundColor: colors.background,
},
});
const openApplicationSettings = () => {
2023-10-23 20:50:17 +02:00
openSettings();
};
2021-09-25 17:04:45 +02:00
const onDisablePrivacyTapped = () => {
2024-04-18 19:48:22 +02:00
setIsPrivacyBlurEnabledState(!(isPrivacyBlurEnabledTapped >= 10));
2021-09-25 17:04:45 +02:00
setIsPrivacyBlurEnabledTapped(prev => prev + 1);
};
return (
<ScrollView style={[styles.root, stylesWithThemeHook.root]} contentInsetAdjustmentBehavior="automatic" automaticallyAdjustContentInsets>
2024-04-18 19:48:22 +02:00
{Platform.OS === 'android' ? <BlueHeaderDefaultSub leftText={loc.settings.general} /> : <></>}
2023-12-16 22:44:35 +01:00
<ListItem
hideChevron
title={loc.settings.privacy_read_clipboard}
Component={TouchableWithoutFeedback}
2024-04-18 03:05:48 +02:00
switch={{
onValueChange: setIsClipboardGetContentEnabledStorage,
value: isClipboardGetContentEnabled,
disabled: isLoading === sections.ALL,
testID: 'ClipboardSwitch',
}}
/>
<BlueCard>
2024-04-18 19:48:22 +02:00
<Pressable accessibilityRole="button" onPress={onDisablePrivacyTapped}>
<BlueText>{loc.settings.privacy_clipboard_explanation}</BlueText>
</Pressable>
</BlueCard>
<BlueSpacing20 />
{!storageIsEncrypted && (
<>
2023-12-16 22:44:35 +01:00
<ListItem
hideChevron
title={loc.settings.privacy_quickactions}
Component={TouchableWithoutFeedback}
2021-03-01 11:20:01 +01:00
switch={{
onValueChange: onQuickActionsValueChange,
value: isQuickActionsEnabled,
disabled: isLoading === sections.ALL,
2023-03-30 02:46:11 +02:00
testID: 'QuickActionsSwitch',
2021-03-01 11:20:01 +01:00
}}
/>
<BlueCard>
2020-11-22 09:04:04 +01:00
<BlueText>{loc.settings.privacy_quickactions_explanation}</BlueText>
</BlueCard>
</>
)}
2023-12-16 22:44:35 +01:00
<ListItem
2023-10-23 20:50:17 +02:00
hideChevron
title={loc.settings.privacy_do_not_track}
Component={TouchableWithoutFeedback}
2024-04-18 03:05:48 +02:00
switch={{ onValueChange: onDoNotTrackValueChange, value: isDoNotTrackEnabled, disabled: isLoading === sections.ALL }}
2023-10-23 20:50:17 +02:00
/>
<BlueCard>
<BlueText>{loc.settings.privacy_do_not_track_explanation}</BlueText>
</BlueCard>
{Platform.OS === 'ios' && !storageIsEncrypted && (
<>
2023-10-23 20:50:17 +02:00
<BlueSpacing40 />
<Text adjustsFontSizeToFit style={[styles.widgetsHeader, styleHooks.widgetsHeader]}>
{loc.settings.widgets}
</Text>
2023-12-16 22:44:35 +01:00
<ListItem
hideChevron
title={loc.settings.total_balance}
Component={TouchableWithoutFeedback}
switch={{
onValueChange: onWidgetsTotalBalanceValueChange,
2024-04-18 03:05:48 +02:00
value: isWidgetBalanceDisplayAllowed,
disabled: isLoading === sections.ALL,
}}
/>
<BlueCard>
<BlueText>{loc.settings.total_balance_explanation}</BlueText>
</BlueCard>
</>
)}
<BlueSpacing20 />
<BlueSpacing20 />
2023-12-16 22:44:35 +01:00
<ListItem title={loc.settings.privacy_system_settings} chevron onPress={openApplicationSettings} testID="PrivacySystemSettings" />
<BlueSpacing20 />
</ScrollView>
);
};
const styles = StyleSheet.create({
root: {
flex: 1,
},
2023-10-23 20:50:17 +02:00
widgetsHeader: {
fontWeight: 'bold',
fontSize: 30,
marginLeft: 17,
},
});
2023-10-23 20:50:17 +02:00
SettingsPrivacy.navigationOptions = navigationStyle({ headerLargeTitle: true }, opts => ({ ...opts, title: loc.settings.privacy }));
export default SettingsPrivacy;