2020-10-24 19:20:59 +02:00
|
|
|
import React, { useContext, useEffect, useState } from 'react';
|
2023-12-16 22:44:35 +01:00
|
|
|
import { ScrollView, Platform, StyleSheet } from 'react-native';
|
2020-12-25 17:09:53 +01:00
|
|
|
|
|
|
|
import navigationStyle from '../../components/navigationStyle';
|
2023-12-16 22:44:35 +01:00
|
|
|
import { BlueLoading, BlueText, BlueSpacing20, BlueCard } from '../../BlueComponents';
|
2023-10-24 03:28:44 +02:00
|
|
|
import { useNavigation } 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';
|
2023-10-24 03:28:44 +02:00
|
|
|
import { useTheme } from '../../components/themes';
|
2023-12-16 22:44:35 +01:00
|
|
|
import ListItem, { PressableWrapper } from '../../components/ListItem';
|
2020-03-29 04:06:45 +02:00
|
|
|
|
2020-05-24 11:17:26 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-04-12 20:06:19 +02:00
|
|
|
const GeneralSettings: React.FC = () => {
|
2023-03-18 13:31:27 +01:00
|
|
|
const { isAdvancedModeEnabled, setIsAdvancedModeEnabled, wallets, isHandOffUseEnabled, setIsHandOffUseEnabledAsyncStorage } =
|
2022-01-26 18:50:41 +01:00
|
|
|
useContext(BlueStorageContext);
|
2020-03-29 04:06:45 +02:00
|
|
|
const [isLoading, setIsLoading] = useState(true);
|
2023-03-04 16:30:51 +01:00
|
|
|
const [isAdvancedModeSwitchEnabled, setIsAdvancedModeSwitchEnabled] = 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();
|
2023-04-12 20:06:19 +02:00
|
|
|
const onAdvancedModeSwitch = async (value: boolean) => {
|
2023-03-18 13:31:27 +01:00
|
|
|
await setIsAdvancedModeEnabled(value);
|
2023-03-04 16:30:51 +01:00
|
|
|
setIsAdvancedModeSwitchEnabled(value);
|
2020-03-29 04:06:45 +02:00
|
|
|
};
|
2023-04-12 20:06:19 +02:00
|
|
|
const onLegacyURv1Switch = async (value: boolean) => {
|
2021-07-09 12:52:09 +02:00
|
|
|
setIsURv1SwitchEnabled(value);
|
|
|
|
return value ? setUseURv1() : clearUseURv1();
|
|
|
|
};
|
2020-03-29 04:06:45 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
2023-03-04 16:30:51 +01:00
|
|
|
setIsAdvancedModeSwitchEnabled(await isAdvancedModeEnabled());
|
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 = () => {
|
2023-04-12 20:06:19 +02:00
|
|
|
// @ts-ignore: Fix later
|
2021-04-06 12:31:56 +02:00
|
|
|
navigate('SettingsPrivacy');
|
|
|
|
};
|
|
|
|
|
2020-07-15 19:32:59 +02:00
|
|
|
const stylesWithThemeHook = {
|
|
|
|
root: {
|
|
|
|
backgroundColor: colors.background,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-03-29 04:06:45 +02:00
|
|
|
return isLoading ? (
|
|
|
|
<BlueLoading />
|
|
|
|
) : (
|
2023-04-12 20:06:19 +02:00
|
|
|
<ScrollView style={[styles.root, stylesWithThemeHook.root]}>
|
2020-10-24 19:20:59 +02:00
|
|
|
{wallets.length > 1 && (
|
2020-07-15 19:32:59 +02:00
|
|
|
<>
|
2023-04-12 20:06:19 +02:00
|
|
|
{/* @ts-ignore: Fix later */}
|
2023-12-16 22:44:35 +01:00
|
|
|
<ListItem onPress={() => navigate('DefaultView')} title={loc.settings.default_title} chevron />
|
2020-07-15 19:32:59 +02:00
|
|
|
</>
|
|
|
|
)}
|
2023-12-16 22:44:35 +01:00
|
|
|
<ListItem title={loc.settings.privacy} onPress={navigateToPrivacy} testID="SettingsPrivacy" chevron />
|
2020-07-15 19:32:59 +02:00
|
|
|
{Platform.OS === 'ios' ? (
|
|
|
|
<>
|
2023-12-16 22:44:35 +01:00
|
|
|
<ListItem
|
2020-07-15 19:32:59 +02:00
|
|
|
hideChevron
|
2020-07-20 15:38:46 +02:00
|
|
|
title={loc.settings.general_continuity}
|
2023-12-16 22:44:35 +01:00
|
|
|
Component={PressableWrapper}
|
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}
|
2023-12-16 22:44:35 +01:00
|
|
|
<ListItem
|
|
|
|
Component={PressableWrapper}
|
2020-07-20 15:38:46 +02:00
|
|
|
title={loc.settings.general_adv_mode}
|
2023-03-04 16:30:51 +01:00
|
|
|
switch={{ onValueChange: onAdvancedModeSwitch, value: isAdvancedModeSwitchEnabled, 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 />
|
2023-12-16 22:44:35 +01:00
|
|
|
<ListItem
|
|
|
|
Component={PressableWrapper}
|
2021-07-09 12:52:09 +02:00
|
|
|
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
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-04-12 20:06:19 +02:00
|
|
|
// @ts-ignore: Fix later
|
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;
|