BlueWallet/screen/settings/GeneralSettings.tsx

103 lines
3.5 KiB
TypeScript
Raw Normal View History

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