BlueWallet/screen/settings/SettingsPrivacy.js

196 lines
6.7 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 DeviceQuickActions from '../../class/quick-actions';
2020-12-25 17:09:53 +01:00
import BlueClipboard from '../../blue_modules/clipboard';
import { BlueStorageContext } from '../../blue_modules/storage-context';
import WidgetCommunication from '../../blue_modules/WidgetCommunication';
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';
const SettingsPrivacy = () => {
const { colors } = useTheme();
2021-09-25 17:04:45 +02:00
const { isStorageEncrypted, setDoNotTrack, isDoNotTrackEnabled, setIsPrivacyBlurEnabled } = useContext(BlueStorageContext);
const sections = Object.freeze({ ALL: 0, CLIPBOARDREAD: 1, QUICKACTION: 2, WIDGETS: 3 });
const [isLoading, setIsLoading] = useState(sections.ALL);
const [isReadClipboardAllowed, setIsReadClipboardAllowed] = useState(false);
const [doNotTrackSwitchValue, setDoNotTrackSwitchValue] = useState(false);
const [isDisplayWidgetBalanceAllowed, setIsDisplayWidgetBalanceAllowed] = useState(false);
const [isQuickActionsEnabled, setIsQuickActionsEnabled] = useState(false);
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 {
setDoNotTrackSwitchValue(await isDoNotTrackEnabled());
2023-03-30 02:46:11 +02:00
setIsReadClipboardAllowed(await BlueClipboard().isReadClipboardAllowed());
setStorageIsEncrypted(await isStorageEncrypted());
setIsQuickActionsEnabled(await DeviceQuickActions.getEnabled());
setIsDisplayWidgetBalanceAllowed(await WidgetCommunication.isBalanceDisplayAllowed());
} catch (e) {
console.log(e);
}
setIsLoading(false);
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const onValueChange = async value => {
setIsLoading(sections.CLIPBOARDREAD);
try {
2023-03-30 02:46:11 +02:00
await BlueClipboard().setReadClipboardAllowed(value);
setIsReadClipboardAllowed(value);
} catch (e) {
console.log(e);
}
setIsLoading(false);
};
const onDoNotTrackValueChange = async value => {
setIsLoading(sections.ALL);
try {
setDoNotTrackSwitchValue(value);
A.setOptOut(value);
await setDoNotTrack(value);
} catch (e) {
console.log(e);
}
setIsLoading(false);
};
const onQuickActionsValueChange = async value => {
setIsLoading(sections.QUICKACTION);
try {
await DeviceQuickActions.setEnabled(value);
setIsQuickActionsEnabled(value);
} catch (e) {
console.log(e);
}
setIsLoading(false);
};
const onWidgetsTotalBalanceValueChange = async value => {
setIsLoading(sections.WIDGETS);
try {
await WidgetCommunication.setBalanceDisplayAllowed(value);
setIsDisplayWidgetBalanceAllowed(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 = () => {
setIsPrivacyBlurEnabled(!(isPrivacyBlurEnabledTapped >= 10));
setIsPrivacyBlurEnabledTapped(prev => prev + 1);
};
return (
<ScrollView style={[styles.root, stylesWithThemeHook.root]} contentInsetAdjustmentBehavior="automatic" automaticallyAdjustContentInsets>
<Pressable accessibilityRole="button" onPress={onDisablePrivacyTapped}>
2023-10-23 20:50:17 +02:00
{Platform.OS === 'android' ? <BlueHeaderDefaultSub leftText={loc.settings.general} /> : <></>}
2021-09-25 17:04:45 +02:00
</Pressable>
2023-12-16 22:44:35 +01:00
<ListItem
hideChevron
title={loc.settings.privacy_read_clipboard}
Component={TouchableWithoutFeedback}
2023-03-30 02:46:11 +02:00
switch={{ onValueChange, value: isReadClipboardAllowed, disabled: isLoading === sections.ALL, testID: 'ClipboardSwitch' }}
/>
<BlueCard>
2020-11-22 09:04:04 +01:00
<BlueText>{loc.settings.privacy_clipboard_explanation}</BlueText>
</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}
switch={{ onValueChange: onDoNotTrackValueChange, value: doNotTrackSwitchValue, disabled: isLoading === sections.ALL }}
/>
<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,
value: isDisplayWidgetBalanceAllowed,
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;