2020-10-24 19:20:59 +02:00
|
|
|
import React, { useContext, useEffect, useState } from 'react';
|
2020-05-24 11:17:26 +02:00
|
|
|
import { ScrollView, Platform, TouchableWithoutFeedback, TouchableOpacity, StyleSheet } from 'react-native';
|
2020-12-25 17:09:53 +01:00
|
|
|
|
|
|
|
import navigationStyle from '../../components/navigationStyle';
|
|
|
|
import { BlueLoading, BlueText, BlueSpacing20, BlueListItem, BlueCard } from '../../BlueComponents';
|
2020-07-15 19:32:59 +02:00
|
|
|
import { useNavigation, useTheme } from '@react-navigation/native';
|
2020-07-20 15:38:46 +02:00
|
|
|
import loc from '../../loc';
|
2020-10-24 19:20:59 +02:00
|
|
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
2021-07-09 12:52:09 +02:00
|
|
|
import { isURv1Enabled, clearUseURv1, setUseURv1 } from '../../blue_modules/ur';
|
2020-03-29 04:06:45 +02:00
|
|
|
|
2020-05-24 11:17:26 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-03-29 04:06:45 +02:00
|
|
|
const GeneralSettings = () => {
|
2021-01-19 04:40:11 +01:00
|
|
|
const { isAdancedModeEnabled, setIsAdancedModeEnabled, wallets, isHandOffUseEnabled, setIsHandOffUseEnabledAsyncStorage } = useContext(
|
|
|
|
BlueStorageContext,
|
|
|
|
);
|
2020-03-29 04:06:45 +02:00
|
|
|
const [isLoading, setIsLoading] = useState(true);
|
2020-10-24 19:20:59 +02:00
|
|
|
const [isAdancedModeSwitchEnabled, setIsAdancedModeSwitchEnabled] = useState(false);
|
2021-07-09 12:52:09 +02:00
|
|
|
const [isURv1SwitchEnabled, setIsURv1SwitchEnabled] = useState(false);
|
2020-03-29 18:46:22 +02:00
|
|
|
const { navigate } = useNavigation();
|
2020-07-15 19:32:59 +02:00
|
|
|
const { colors } = useTheme();
|
2020-03-29 04:06:45 +02:00
|
|
|
const onAdvancedModeSwitch = async value => {
|
2020-10-24 19:20:59 +02:00
|
|
|
await setIsAdancedModeEnabled(value);
|
|
|
|
setIsAdancedModeSwitchEnabled(value);
|
2020-03-29 04:06:45 +02:00
|
|
|
};
|
2021-07-09 12:52:09 +02:00
|
|
|
const onLegacyURv1Switch = async value => {
|
|
|
|
setIsURv1SwitchEnabled(value);
|
|
|
|
return value ? setUseURv1() : clearUseURv1();
|
|
|
|
};
|
2020-03-29 04:06:45 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
2020-10-24 19:20:59 +02:00
|
|
|
setIsAdancedModeSwitchEnabled(await isAdancedModeEnabled());
|
2021-07-09 12:52:09 +02:00
|
|
|
setIsURv1SwitchEnabled(await isURv1Enabled());
|
2020-03-29 04:06:45 +02:00
|
|
|
setIsLoading(false);
|
|
|
|
})();
|
|
|
|
});
|
|
|
|
|
2021-04-06 12:31:56 +02:00
|
|
|
const navigateToPrivacy = () => {
|
|
|
|
navigate('SettingsPrivacy');
|
|
|
|
};
|
|
|
|
|
2020-07-15 19:32:59 +02:00
|
|
|
const stylesWithThemeHook = {
|
|
|
|
root: {
|
|
|
|
...styles.root,
|
|
|
|
backgroundColor: colors.background,
|
|
|
|
},
|
|
|
|
scroll: {
|
|
|
|
...styles.scroll,
|
|
|
|
backgroundColor: colors.background,
|
|
|
|
},
|
|
|
|
scrollBody: {
|
|
|
|
...styles.scrollBody,
|
|
|
|
backgroundColor: colors.background,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-03-29 04:06:45 +02:00
|
|
|
return isLoading ? (
|
|
|
|
<BlueLoading />
|
|
|
|
) : (
|
2020-07-15 19:32:59 +02:00
|
|
|
<ScrollView style={stylesWithThemeHook.scroll}>
|
2020-10-24 19:20:59 +02:00
|
|
|
{wallets.length > 1 && (
|
2020-07-15 19:32:59 +02:00
|
|
|
<>
|
2020-09-22 03:53:28 +02:00
|
|
|
<BlueListItem component={TouchableOpacity} onPress={() => navigate('DefaultView')} title={loc.settings.default_title} chevron />
|
2020-07-15 19:32:59 +02:00
|
|
|
</>
|
|
|
|
)}
|
2021-04-06 12:31:56 +02:00
|
|
|
<BlueListItem title={loc.settings.privacy} onPress={navigateToPrivacy} testID="SettingsPrivacy" chevron />
|
2020-07-15 19:32:59 +02:00
|
|
|
{Platform.OS === 'ios' ? (
|
|
|
|
<>
|
2020-09-22 03:53:28 +02:00
|
|
|
<BlueListItem
|
2020-07-15 19:32:59 +02:00
|
|
|
hideChevron
|
2020-07-20 15:38:46 +02:00
|
|
|
title={loc.settings.general_continuity}
|
2020-07-15 19:32:59 +02:00
|
|
|
Component={TouchableWithoutFeedback}
|
2021-01-19 04:40:11 +01:00
|
|
|
switch={{ onValueChange: setIsHandOffUseEnabledAsyncStorage, value: isHandOffUseEnabled }}
|
2020-07-15 19:32:59 +02:00
|
|
|
/>
|
|
|
|
<BlueCard>
|
2020-11-22 09:04:04 +01:00
|
|
|
<BlueText>{loc.settings.general_continuity_e}</BlueText>
|
2020-07-15 19:32:59 +02:00
|
|
|
</BlueCard>
|
|
|
|
<BlueSpacing20 />
|
|
|
|
</>
|
|
|
|
) : null}
|
2020-09-22 03:53:28 +02:00
|
|
|
<BlueListItem
|
2020-07-15 19:32:59 +02:00
|
|
|
Component={TouchableWithoutFeedback}
|
2020-07-20 15:38:46 +02:00
|
|
|
title={loc.settings.general_adv_mode}
|
2021-03-01 11:20:01 +01:00
|
|
|
switch={{ onValueChange: onAdvancedModeSwitch, value: isAdancedModeSwitchEnabled, testID: 'AdvancedMode' }}
|
2020-07-15 19:32:59 +02:00
|
|
|
/>
|
|
|
|
<BlueCard>
|
2020-11-22 09:04:04 +01:00
|
|
|
<BlueText>{loc.settings.general_adv_mode_e}</BlueText>
|
2020-07-15 19:32:59 +02:00
|
|
|
</BlueCard>
|
|
|
|
<BlueSpacing20 />
|
2021-07-09 12:52:09 +02:00
|
|
|
<BlueListItem
|
|
|
|
Component={TouchableWithoutFeedback}
|
|
|
|
title="Legacy URv1 QR"
|
|
|
|
switch={{ onValueChange: onLegacyURv1Switch, value: isURv1SwitchEnabled }}
|
|
|
|
/>
|
|
|
|
<BlueSpacing20 />
|
2020-07-15 19:32:59 +02:00
|
|
|
</ScrollView>
|
2020-03-29 04:06:45 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-02-15 09:03:54 +01:00
|
|
|
GeneralSettings.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.settings.general }));
|
2020-03-29 04:06:45 +02:00
|
|
|
|
|
|
|
export default GeneralSettings;
|