forked from BlueWallet/BlueWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsPrivacy.js
181 lines (164 loc) · 6.21 KB
/
SettingsPrivacy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import React, { useContext, useEffect, useState } from 'react';
import { ScrollView, TouchableWithoutFeedback, StyleSheet, Linking, Platform, Pressable } from 'react-native';
import { useTheme } from '@react-navigation/native';
import navigationStyle from '../../components/navigationStyle';
import { BlueText, BlueSpacing20, BlueListItem, BlueCard, BlueHeaderDefaultSub } from '../../BlueComponents';
import loc from '../../loc';
import DeviceQuickActions from '../../class/quick-actions';
import BlueClipboard from '../../blue_modules/clipboard';
import { BlueStorageContext } from '../../blue_modules/storage-context';
import WidgetCommunication from '../../blue_modules/WidgetCommunication';
const A = require('../../blue_modules/analytics');
const SettingsPrivacy = () => {
const { colors } = useTheme();
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);
const [isPrivacyBlurEnabledTapped, setIsPrivacyBlurEnabledTapped] = useState(0);
useEffect(() => {
(async () => {
try {
setDoNotTrackSwitchValue(await isDoNotTrackEnabled());
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 {
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 = () => {
Linking.openSettings();
};
const onDisablePrivacyTapped = () => {
setIsPrivacyBlurEnabled(!(isPrivacyBlurEnabledTapped >= 10));
setIsPrivacyBlurEnabledTapped(prev => prev + 1);
};
return (
<ScrollView style={[styles.root, stylesWithThemeHook.root]}>
<Pressable accessibilityRole="button" onPress={onDisablePrivacyTapped}>
<BlueHeaderDefaultSub leftText={loc.settings.general} rightComponent={null} />
</Pressable>
<BlueListItem
hideChevron
title={loc.settings.privacy_read_clipboard}
Component={TouchableWithoutFeedback}
switch={{ onValueChange, value: isReadClipboardAllowed, disabled: isLoading === sections.ALL, testID: 'ClipboardSwith' }}
/>
<BlueCard>
<BlueText>{loc.settings.privacy_clipboard_explanation}</BlueText>
</BlueCard>
<BlueSpacing20 />
{!storageIsEncrypted && (
<>
<BlueListItem
hideChevron
title={loc.settings.privacy_quickactions}
Component={TouchableWithoutFeedback}
switch={{
onValueChange: onQuickActionsValueChange,
value: isQuickActionsEnabled,
disabled: isLoading === sections.ALL,
testID: 'QuickActionsSwith',
}}
/>
<BlueCard>
<BlueText>{loc.settings.privacy_quickactions_explanation}</BlueText>
</BlueCard>
</>
)}
{Platform.OS === 'ios' && !storageIsEncrypted && (
<>
<BlueHeaderDefaultSub leftText={loc.settings.widgets} rightComponent={null} />
<BlueListItem
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 />
<BlueListItem
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>
<BlueSpacing20 />
<BlueListItem title={loc.settings.privacy_system_settings} chevron onPress={openApplicationSettings} testID="PrivacySystemSettings" />
<BlueSpacing20 />
</ScrollView>
);
};
const styles = StyleSheet.create({
root: {
flex: 1,
},
});
SettingsPrivacy.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.settings.privacy }));
export default SettingsPrivacy;