mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-19 05:45:15 +01:00
REF: SettingsPrivacy TSX
This commit is contained in:
parent
4e9b34df07
commit
955523e5e9
@ -486,7 +486,11 @@ const DetailViewStackScreensStack = () => {
|
|||||||
options={LightningSettings.navigationOptions(theme)}
|
options={LightningSettings.navigationOptions(theme)}
|
||||||
/>
|
/>
|
||||||
<DetailViewRoot.Screen name="ElectrumSettings" component={ElectrumSettings} options={ElectrumSettings.navigationOptions(theme)} />
|
<DetailViewRoot.Screen name="ElectrumSettings" component={ElectrumSettings} options={ElectrumSettings.navigationOptions(theme)} />
|
||||||
<DetailViewRoot.Screen name="SettingsPrivacy" component={SettingsPrivacy} options={SettingsPrivacy.navigationOptions(theme)} />
|
<DetailViewRoot.Screen
|
||||||
|
name="SettingsPrivacy"
|
||||||
|
component={SettingsPrivacy}
|
||||||
|
options={navigationStyle({ headerLargeTitle: true, title: loc.settings.privacy })(theme)}
|
||||||
|
/>
|
||||||
<DetailViewRoot.Screen name="Tools" component={Tools} options={Tools.navigationOptions(theme)} />
|
<DetailViewRoot.Screen name="Tools" component={Tools} options={Tools.navigationOptions(theme)} />
|
||||||
<DetailViewRoot.Screen name="LNDViewInvoice" component={LNDViewInvoice} options={LNDViewInvoice.navigationOptions(theme)} />
|
<DetailViewRoot.Screen name="LNDViewInvoice" component={LNDViewInvoice} options={LNDViewInvoice.navigationOptions(theme)} />
|
||||||
<DetailViewRoot.Screen
|
<DetailViewRoot.Screen
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import React, { useContext, useEffect, useState } from 'react';
|
import React, { useContext, useEffect, useState } from 'react';
|
||||||
import { ScrollView, TouchableWithoutFeedback, StyleSheet, Platform, Pressable, Text } from 'react-native';
|
import { ScrollView, TouchableWithoutFeedback, StyleSheet, Platform, Pressable, Text } from 'react-native';
|
||||||
import { openSettings } from 'react-native-permissions';
|
import { openSettings } from 'react-native-permissions';
|
||||||
|
|
||||||
import navigationStyle from '../../components/navigationStyle';
|
|
||||||
import { BlueText, BlueSpacing20, BlueCard, BlueHeaderDefaultSub, BlueSpacing40 } from '../../BlueComponents';
|
import { BlueText, BlueSpacing20, BlueCard, BlueHeaderDefaultSub, BlueSpacing40 } from '../../BlueComponents';
|
||||||
import loc from '../../loc';
|
import loc from '../../loc';
|
||||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||||
@ -12,7 +10,15 @@ import A from '../../blue_modules/analytics';
|
|||||||
import { useSettings } from '../../components/Context/SettingsContext';
|
import { useSettings } from '../../components/Context/SettingsContext';
|
||||||
import { setBalanceDisplayAllowed } from '../../components/WidgetCommunication';
|
import { setBalanceDisplayAllowed } from '../../components/WidgetCommunication';
|
||||||
|
|
||||||
const SettingsPrivacy = () => {
|
enum SettingsPrivacySection {
|
||||||
|
None,
|
||||||
|
All,
|
||||||
|
ReadClipboard,
|
||||||
|
QuickActions,
|
||||||
|
Widget,
|
||||||
|
}
|
||||||
|
|
||||||
|
const SettingsPrivacy: React.FC = () => {
|
||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
const { isStorageEncrypted } = useContext(BlueStorageContext);
|
const { isStorageEncrypted } = useContext(BlueStorageContext);
|
||||||
const {
|
const {
|
||||||
@ -26,12 +32,14 @@ const SettingsPrivacy = () => {
|
|||||||
isQuickActionsEnabled,
|
isQuickActionsEnabled,
|
||||||
setIsQuickActionsEnabledStorage,
|
setIsQuickActionsEnabledStorage,
|
||||||
} = useSettings();
|
} = useSettings();
|
||||||
const sections = Object.freeze({ ALL: 0, CLIPBOARDREAD: 1, QUICKACTION: 2, WIDGETS: 3 });
|
const [isLoading, setIsLoading] = useState<number>(SettingsPrivacySection.All);
|
||||||
const [isLoading, setIsLoading] = useState(sections.ALL);
|
|
||||||
|
|
||||||
const [storageIsEncrypted, setStorageIsEncrypted] = useState(true);
|
const [storageIsEncrypted, setStorageIsEncrypted] = useState<boolean>(true);
|
||||||
const [isPrivacyBlurEnabledTapped, setIsPrivacyBlurEnabledTapped] = useState(0);
|
const [isPrivacyBlurEnabledTapped, setIsPrivacyBlurEnabledTapped] = useState<number>(0);
|
||||||
const styleHooks = StyleSheet.create({
|
const styleHooks = StyleSheet.create({
|
||||||
|
root: {
|
||||||
|
backgroundColor: colors.background,
|
||||||
|
},
|
||||||
widgetsHeader: {
|
widgetsHeader: {
|
||||||
color: colors.foregroundColor,
|
color: colors.foregroundColor,
|
||||||
},
|
},
|
||||||
@ -44,49 +52,42 @@ const SettingsPrivacy = () => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
setIsLoading(false);
|
setIsLoading(SettingsPrivacySection.None);
|
||||||
})();
|
})();
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
}, [isStorageEncrypted]);
|
||||||
}, []);
|
|
||||||
|
|
||||||
const onDoNotTrackValueChange = async value => {
|
const onDoNotTrackValueChange = async (value: boolean) => {
|
||||||
setIsLoading(sections.ALL);
|
setIsLoading(SettingsPrivacySection.All);
|
||||||
try {
|
try {
|
||||||
setDoNotTrackStorage(value);
|
setDoNotTrackStorage(value);
|
||||||
A.setOptOut(value);
|
A.setOptOut(value);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.debug('onDoNotTrackValueChange catch', e);
|
||||||
}
|
}
|
||||||
setIsLoading(false);
|
setIsLoading(SettingsPrivacySection.None);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onQuickActionsValueChange = async value => {
|
const onQuickActionsValueChange = async (value: boolean) => {
|
||||||
setIsLoading(sections.QUICKACTION);
|
setIsLoading(SettingsPrivacySection.QuickActions);
|
||||||
try {
|
try {
|
||||||
setIsQuickActionsEnabledStorage(value);
|
setIsQuickActionsEnabledStorage(value);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.debug('onQuickActionsValueChange catch', e);
|
||||||
}
|
}
|
||||||
setIsLoading(false);
|
setIsLoading(SettingsPrivacySection.None);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onWidgetsTotalBalanceValueChange = async value => {
|
const onWidgetsTotalBalanceValueChange = async (value: boolean) => {
|
||||||
setIsLoading(sections.WIDGETS);
|
setIsLoading(SettingsPrivacySection.Widget);
|
||||||
try {
|
try {
|
||||||
await setBalanceDisplayAllowed(value);
|
await setBalanceDisplayAllowed(value);
|
||||||
setIsWidgetBalanceDisplayAllowedStorage(value);
|
setIsWidgetBalanceDisplayAllowedStorage(value);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.debug('onWidgetsTotalBalanceValueChange catch', e);
|
||||||
}
|
}
|
||||||
setIsLoading(false);
|
setIsLoading(SettingsPrivacySection.None);
|
||||||
};
|
};
|
||||||
|
|
||||||
const stylesWithThemeHook = StyleSheet.create({
|
|
||||||
root: {
|
|
||||||
backgroundColor: colors.background,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const openApplicationSettings = () => {
|
const openApplicationSettings = () => {
|
||||||
openSettings();
|
openSettings();
|
||||||
};
|
};
|
||||||
@ -97,8 +98,8 @@ const SettingsPrivacy = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView style={[styles.root, stylesWithThemeHook.root]} contentInsetAdjustmentBehavior="automatic" automaticallyAdjustContentInsets>
|
<ScrollView style={[styles.root, styleHooks.root]} contentInsetAdjustmentBehavior="automatic" automaticallyAdjustContentInsets>
|
||||||
{Platform.OS === 'android' ? <BlueHeaderDefaultSub leftText={loc.settings.general} /> : <></>}
|
{Platform.OS === 'android' ? <BlueHeaderDefaultSub leftText={loc.settings.general} /> : null}
|
||||||
<ListItem
|
<ListItem
|
||||||
hideChevron
|
hideChevron
|
||||||
title={loc.settings.privacy_read_clipboard}
|
title={loc.settings.privacy_read_clipboard}
|
||||||
@ -106,7 +107,7 @@ const SettingsPrivacy = () => {
|
|||||||
switch={{
|
switch={{
|
||||||
onValueChange: setIsClipboardGetContentEnabledStorage,
|
onValueChange: setIsClipboardGetContentEnabledStorage,
|
||||||
value: isClipboardGetContentEnabled,
|
value: isClipboardGetContentEnabled,
|
||||||
disabled: isLoading === sections.ALL,
|
disabled: isLoading === SettingsPrivacySection.All,
|
||||||
testID: 'ClipboardSwitch',
|
testID: 'ClipboardSwitch',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@ -125,7 +126,7 @@ const SettingsPrivacy = () => {
|
|||||||
switch={{
|
switch={{
|
||||||
onValueChange: onQuickActionsValueChange,
|
onValueChange: onQuickActionsValueChange,
|
||||||
value: isQuickActionsEnabled,
|
value: isQuickActionsEnabled,
|
||||||
disabled: isLoading === sections.ALL,
|
disabled: isLoading === SettingsPrivacySection.All,
|
||||||
testID: 'QuickActionsSwitch',
|
testID: 'QuickActionsSwitch',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@ -138,7 +139,7 @@ const SettingsPrivacy = () => {
|
|||||||
hideChevron
|
hideChevron
|
||||||
title={loc.settings.privacy_do_not_track}
|
title={loc.settings.privacy_do_not_track}
|
||||||
Component={TouchableWithoutFeedback}
|
Component={TouchableWithoutFeedback}
|
||||||
switch={{ onValueChange: onDoNotTrackValueChange, value: isDoNotTrackEnabled, disabled: isLoading === sections.ALL }}
|
switch={{ onValueChange: onDoNotTrackValueChange, value: isDoNotTrackEnabled, disabled: isLoading === SettingsPrivacySection.All }}
|
||||||
/>
|
/>
|
||||||
<BlueCard>
|
<BlueCard>
|
||||||
<BlueText>{loc.settings.privacy_do_not_track_explanation}</BlueText>
|
<BlueText>{loc.settings.privacy_do_not_track_explanation}</BlueText>
|
||||||
@ -156,7 +157,7 @@ const SettingsPrivacy = () => {
|
|||||||
switch={{
|
switch={{
|
||||||
onValueChange: onWidgetsTotalBalanceValueChange,
|
onValueChange: onWidgetsTotalBalanceValueChange,
|
||||||
value: isWidgetBalanceDisplayAllowed,
|
value: isWidgetBalanceDisplayAllowed,
|
||||||
disabled: isLoading === sections.ALL,
|
disabled: isLoading === SettingsPrivacySection.All,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<BlueCard>
|
<BlueCard>
|
||||||
@ -184,6 +185,4 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
SettingsPrivacy.navigationOptions = navigationStyle({ headerLargeTitle: true }, opts => ({ ...opts, title: loc.settings.privacy }));
|
|
||||||
|
|
||||||
export default SettingsPrivacy;
|
export default SettingsPrivacy;
|
Loading…
Reference in New Issue
Block a user