BlueWallet/screen/settings/SettingsPrivacy.tsx

234 lines
7.6 KiB
TypeScript
Raw Normal View History

2024-05-31 19:18:01 +02:00
import React, { useEffect, useState } from 'react';
2024-05-20 11:54:13 +02:00
import { Platform, Pressable, ScrollView, StyleSheet, Text, TouchableWithoutFeedback, View } from 'react-native';
2023-10-23 20:50:17 +02:00
import { openSettings } from 'react-native-permissions';
import A from '../../blue_modules/analytics';
2024-05-20 11:54:13 +02:00
import { BlueCard, BlueSpacing20, BlueSpacing40, BlueText } from '../../BlueComponents';
2024-05-04 00:33:23 +02:00
import { Header } from '../../components/Header';
2024-08-22 17:50:12 +02:00
import ListItem, { PressableWrapper } from '../../components/ListItem';
2024-05-20 11:54:13 +02:00
import { useTheme } from '../../components/themes';
import { setBalanceDisplayAllowed } from '../../components/WidgetCommunication';
import loc from '../../loc';
2024-05-31 19:18:01 +02:00
import { useStorage } from '../../hooks/context/useStorage';
import { useSettings } from '../../hooks/context/useSettings';
2024-05-03 19:18:41 +02:00
enum SettingsPrivacySection {
None,
All,
ReadClipboard,
QuickActions,
Widget,
2024-08-13 21:21:50 +02:00
TemporaryScreenshots,
2024-08-22 17:50:12 +02:00
TotalBalance,
2024-05-03 19:18:41 +02:00
}
const SettingsPrivacy: React.FC = () => {
const { colors } = useTheme();
2024-08-22 17:50:12 +02:00
const { isStorageEncrypted, wallets } = useStorage();
2024-04-18 03:05:48 +02:00
const {
isDoNotTrackEnabled,
setDoNotTrackStorage,
2024-08-13 21:21:50 +02:00
isPrivacyBlurEnabled,
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-08-22 17:50:12 +02:00
isTotalBalanceEnabled,
setIsTotalBalanceEnabledStorage,
2024-04-18 03:05:48 +02:00
} = useSettings();
2024-05-03 19:18:41 +02:00
const [isLoading, setIsLoading] = useState<number>(SettingsPrivacySection.All);
2024-05-03 19:18:41 +02:00
const [storageIsEncrypted, setStorageIsEncrypted] = useState<boolean>(true);
2023-10-23 20:50:17 +02:00
const styleHooks = StyleSheet.create({
2024-05-03 19:18:41 +02:00
root: {
backgroundColor: colors.background,
},
2023-10-23 20:50:17 +02:00
widgetsHeader: {
color: colors.foregroundColor,
},
});
useEffect(() => {
(async () => {
try {
setStorageIsEncrypted(await isStorageEncrypted());
} catch (e) {
console.log(e);
}
2024-05-03 19:18:41 +02:00
setIsLoading(SettingsPrivacySection.None);
})();
2024-05-03 19:18:41 +02:00
}, [isStorageEncrypted]);
2024-05-03 19:18:41 +02:00
const onDoNotTrackValueChange = async (value: boolean) => {
setIsLoading(SettingsPrivacySection.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) {
2024-05-03 19:18:41 +02:00
console.debug('onDoNotTrackValueChange catch', e);
}
2024-05-03 19:18:41 +02:00
setIsLoading(SettingsPrivacySection.None);
};
2024-05-03 19:18:41 +02:00
const onQuickActionsValueChange = async (value: boolean) => {
setIsLoading(SettingsPrivacySection.QuickActions);
try {
2024-04-18 19:48:22 +02:00
setIsQuickActionsEnabledStorage(value);
} catch (e) {
2024-05-03 19:18:41 +02:00
console.debug('onQuickActionsValueChange catch', e);
}
2024-05-03 19:18:41 +02:00
setIsLoading(SettingsPrivacySection.None);
};
2024-05-03 19:18:41 +02:00
const onWidgetsTotalBalanceValueChange = async (value: boolean) => {
setIsLoading(SettingsPrivacySection.Widget);
try {
await setBalanceDisplayAllowed(value);
2024-04-18 03:05:48 +02:00
setIsWidgetBalanceDisplayAllowedStorage(value);
} catch (e) {
2024-05-03 19:18:41 +02:00
console.debug('onWidgetsTotalBalanceValueChange catch', e);
}
2024-05-03 19:18:41 +02:00
setIsLoading(SettingsPrivacySection.None);
};
2024-08-22 17:50:12 +02:00
const onTotalBalanceEnabledValueChange = async (value: boolean) => {
setIsLoading(SettingsPrivacySection.TotalBalance);
try {
setIsTotalBalanceEnabledStorage(value);
} catch (e) {
console.debug('onTotalBalanceEnabledValueChange catch', e);
}
setIsLoading(SettingsPrivacySection.None);
};
2024-08-13 21:21:50 +02:00
const onTemporaryScreenshotsValueChange = (value: boolean) => {
setIsLoading(SettingsPrivacySection.TemporaryScreenshots);
2024-08-13 23:24:00 +02:00
setIsPrivacyBlurEnabledState(!value);
2024-08-13 21:21:50 +02:00
setIsLoading(SettingsPrivacySection.None);
};
2024-08-13 21:21:50 +02:00
const openApplicationSettings = () => {
openSettings();
2021-09-25 17:04:45 +02:00
};
return (
2024-05-03 19:18:41 +02:00
<ScrollView style={[styles.root, styleHooks.root]} contentInsetAdjustmentBehavior="automatic" automaticallyAdjustContentInsets>
2024-05-04 00:33:23 +02:00
{Platform.OS === 'android' ? (
<View style={styles.headerContainer}>
<Header leftText={loc.settings.general} />
2024-05-04 00:33:23 +02:00
</View>
) : null}
2023-12-16 22:44:35 +01:00
<ListItem
title={loc.settings.privacy_read_clipboard}
Component={TouchableWithoutFeedback}
2024-04-18 03:05:48 +02:00
switch={{
onValueChange: setIsClipboardGetContentEnabledStorage,
value: isClipboardGetContentEnabled,
2024-05-03 19:18:41 +02:00
disabled: isLoading === SettingsPrivacySection.All,
2024-04-18 03:05:48 +02:00
testID: 'ClipboardSwitch',
}}
/>
<BlueCard>
2024-08-13 21:21:50 +02:00
<Pressable accessibilityRole="button">
2024-04-18 19:48:22 +02:00
<BlueText>{loc.settings.privacy_clipboard_explanation}</BlueText>
</Pressable>
</BlueCard>
<BlueSpacing20 />
<ListItem
title={loc.settings.privacy_quickactions}
Component={TouchableWithoutFeedback}
switch={{
onValueChange: onQuickActionsValueChange,
value: storageIsEncrypted ? false : isQuickActionsEnabled,
disabled: isLoading === SettingsPrivacySection.All || storageIsEncrypted,
testID: 'QuickActionsSwitch',
}}
/>
<BlueCard>
<BlueText>{loc.settings.privacy_quickactions_explanation}</BlueText>
<BlueSpacing20 />
{storageIsEncrypted && <BlueText>{loc.settings.encrypted_feature_disabled}</BlueText>}
</BlueCard>
2024-08-22 17:50:12 +02:00
<ListItem
title={loc.total_balance_view.title}
Component={PressableWrapper}
switch={{
onValueChange: onTotalBalanceEnabledValueChange,
value: isTotalBalanceEnabled,
disabled: isLoading === SettingsPrivacySection.All || wallets.length < 2,
testID: 'TotalBalanceSwitch',
}}
/>
<BlueCard>
<BlueText>{loc.total_balance_view.explanation}</BlueText>
<BlueSpacing20 />
</BlueCard>
2024-08-13 21:21:50 +02:00
<ListItem
title={loc.settings.privacy_temporary_screenshots}
Component={TouchableWithoutFeedback}
switch={{
onValueChange: onTemporaryScreenshotsValueChange,
2024-08-13 23:24:00 +02:00
value: !isPrivacyBlurEnabled,
2024-08-13 21:21:50 +02:00
disabled: isLoading === SettingsPrivacySection.All,
}}
/>
<BlueCard>
<BlueText>{loc.settings.privacy_temporary_screenshots_instructions}</BlueText>
</BlueCard>
2023-12-16 22:44:35 +01:00
<ListItem
2023-10-23 20:50:17 +02:00
title={loc.settings.privacy_do_not_track}
Component={TouchableWithoutFeedback}
2024-05-03 19:18:41 +02:00
switch={{ onValueChange: onDoNotTrackValueChange, value: isDoNotTrackEnabled, disabled: isLoading === SettingsPrivacySection.All }}
2023-10-23 20:50:17 +02:00
/>
<BlueCard>
<BlueText>{loc.settings.privacy_do_not_track_explanation}</BlueText>
</BlueCard>
{Platform.OS === 'ios' && (
<>
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
title={loc.settings.total_balance}
Component={TouchableWithoutFeedback}
switch={{
onValueChange: onWidgetsTotalBalanceValueChange,
value: storageIsEncrypted ? false : isWidgetBalanceDisplayAllowed,
disabled: isLoading === SettingsPrivacySection.All || storageIsEncrypted,
}}
/>
<BlueCard>
<BlueText>{loc.settings.total_balance_explanation}</BlueText>
<BlueSpacing20 />
{storageIsEncrypted && <BlueText>{loc.settings.encrypted_feature_disabled}</BlueText>}
</BlueCard>
</>
)}
2024-08-13 23:24:00 +02:00
<BlueSpacing20 />
<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,
},
2024-05-04 00:33:23 +02:00
headerContainer: {
paddingVertical: 16,
},
});
export default SettingsPrivacy;