forked from BlueWallet/BlueWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneralSettings.tsx
105 lines (96 loc) · 3.6 KB
/
GeneralSettings.tsx
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
import React, { useContext, useEffect, useState } from 'react';
import { ScrollView, Platform, Pressable, TouchableOpacity, StyleSheet } from 'react-native';
import navigationStyle from '../../components/navigationStyle';
import { BlueLoading, BlueText, BlueSpacing20, BlueListItem, BlueCard } from '../../BlueComponents';
import { useNavigation, useTheme } from '@react-navigation/native';
import loc from '../../loc';
import { BlueStorageContext } from '../../blue_modules/storage-context';
import { isURv1Enabled, clearUseURv1, setUseURv1 } from '../../blue_modules/ur';
const styles = StyleSheet.create({
root: {
flex: 1,
},
});
const GeneralSettings: React.FC = () => {
const { isAdvancedModeEnabled, setIsAdvancedModeEnabled, wallets, isHandOffUseEnabled, setIsHandOffUseEnabledAsyncStorage } =
useContext(BlueStorageContext);
const [isLoading, setIsLoading] = useState(true);
const [isAdvancedModeSwitchEnabled, setIsAdvancedModeSwitchEnabled] = useState(false);
const [isURv1SwitchEnabled, setIsURv1SwitchEnabled] = useState(false);
const { navigate } = useNavigation();
const { colors } = useTheme();
const onAdvancedModeSwitch = async (value: boolean) => {
await setIsAdvancedModeEnabled(value);
setIsAdvancedModeSwitchEnabled(value);
};
const onLegacyURv1Switch = async (value: boolean) => {
setIsURv1SwitchEnabled(value);
return value ? setUseURv1() : clearUseURv1();
};
useEffect(() => {
(async () => {
setIsAdvancedModeSwitchEnabled(await isAdvancedModeEnabled());
setIsURv1SwitchEnabled(await isURv1Enabled());
setIsLoading(false);
})();
});
const navigateToPrivacy = () => {
// @ts-ignore: Fix later
navigate('SettingsPrivacy');
};
const stylesWithThemeHook = {
root: {
backgroundColor: colors.background,
},
};
return isLoading ? (
<BlueLoading />
) : (
<ScrollView style={[styles.root, stylesWithThemeHook.root]}>
{wallets.length > 1 && (
<>
{/* @ts-ignore: Fix later */}
<BlueListItem component={TouchableOpacity} onPress={() => navigate('DefaultView')} title={loc.settings.default_title} chevron />
</>
)}
{/* @ts-ignore: Fix later */}
<BlueListItem title={loc.settings.privacy} onPress={navigateToPrivacy} testID="SettingsPrivacy" chevron />
{Platform.OS === 'ios' ? (
<>
<BlueListItem
// @ts-ignore: Fix later
hideChevron
title={loc.settings.general_continuity}
Component={Pressable}
switch={{ onValueChange: setIsHandOffUseEnabledAsyncStorage, value: isHandOffUseEnabled }}
/>
<BlueCard>
<BlueText>{loc.settings.general_continuity_e}</BlueText>
</BlueCard>
<BlueSpacing20 />
</>
) : null}
<BlueListItem
// @ts-ignore: Fix later
Component={Pressable}
title={loc.settings.general_adv_mode}
switch={{ onValueChange: onAdvancedModeSwitch, value: isAdvancedModeSwitchEnabled, testID: 'AdvancedMode' }}
/>
<BlueCard>
<BlueText>{loc.settings.general_adv_mode_e}</BlueText>
</BlueCard>
<BlueSpacing20 />
{/* @ts-ignore: Fix later */}
<BlueListItem
// @ts-ignore: Fix later
Component={Pressable}
title="Legacy URv1 QR"
switch={{ onValueChange: onLegacyURv1Switch, value: isURv1SwitchEnabled }}
/>
<BlueSpacing20 />
</ScrollView>
);
};
// @ts-ignore: Fix later
GeneralSettings.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.settings.general }));
export default GeneralSettings;