2019-12-24 23:44:33 -06:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2019-08-19 21:17:24 +01:00
|
|
|
import { ScrollView, View, Switch, TouchableOpacity } from 'react-native';
|
2019-05-19 20:49:42 +01:00
|
|
|
import {
|
|
|
|
BlueText,
|
2019-12-24 23:44:33 -06:00
|
|
|
BlueNavigationStyle,
|
2019-05-19 20:49:42 +01:00
|
|
|
BlueCard,
|
|
|
|
BlueLoading,
|
|
|
|
SafeBlueArea,
|
|
|
|
BlueHeaderDefaultSub,
|
|
|
|
BlueListItem,
|
|
|
|
} from '../../BlueComponents';
|
|
|
|
import AsyncStorage from '@react-native-community/async-storage';
|
|
|
|
import { AppStorage } from '../../class';
|
2019-10-29 23:00:07 -04:00
|
|
|
import { useNavigation } from 'react-navigation-hooks';
|
2019-10-05 21:12:55 -04:00
|
|
|
const BlueApp = require('../../BlueApp');
|
2019-10-29 23:00:07 -04:00
|
|
|
const loc = require('../../loc');
|
2018-09-30 04:31:09 -04:00
|
|
|
|
2019-12-24 23:44:33 -06:00
|
|
|
const Settings = () => {
|
2019-10-29 23:00:07 -04:00
|
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
const [showAdvancedOptions, setShowAdvancedOptions] = useState(false);
|
|
|
|
const [advancedModeEnabled, setAdvancedModeEnabled] = useState(false);
|
|
|
|
const { navigate } = useNavigation();
|
2018-09-30 04:31:09 -04:00
|
|
|
|
2019-10-29 23:00:07 -04:00
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
setAdvancedModeEnabled(!!(await AsyncStorage.getItem(AppStorage.ADVANCED_MODE_ENABLED)));
|
|
|
|
setIsLoading(false);
|
|
|
|
})();
|
|
|
|
});
|
2018-09-30 04:31:09 -04:00
|
|
|
|
2019-10-29 23:00:07 -04:00
|
|
|
const onAdvancedModeSwitch = async value => {
|
2019-05-19 20:49:42 +01:00
|
|
|
if (value) {
|
|
|
|
await AsyncStorage.setItem(AppStorage.ADVANCED_MODE_ENABLED, '1');
|
|
|
|
} else {
|
|
|
|
await AsyncStorage.removeItem(AppStorage.ADVANCED_MODE_ENABLED);
|
|
|
|
}
|
2019-10-29 23:00:07 -04:00
|
|
|
setAdvancedModeEnabled(value);
|
|
|
|
};
|
2019-05-19 20:49:42 +01:00
|
|
|
|
2019-10-29 23:00:07 -04:00
|
|
|
const onShowAdvancedOptions = () => {
|
|
|
|
setShowAdvancedOptions(!showAdvancedOptions);
|
|
|
|
};
|
|
|
|
|
|
|
|
return isLoading ? (
|
|
|
|
<BlueLoading />
|
|
|
|
) : (
|
|
|
|
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
|
|
|
|
<BlueHeaderDefaultSub leftText={loc.settings.header} rightComponent={null} />
|
|
|
|
<ScrollView>
|
|
|
|
{BlueApp.getWallets().length > 1 && (
|
|
|
|
<BlueListItem component={TouchableOpacity} onPress={() => navigate('DefaultView')} title="On Launch" />
|
|
|
|
)}
|
2020-03-18 15:38:52 +00:00
|
|
|
<BlueListItem
|
2020-03-18 16:07:09 +00:00
|
|
|
title="Security"
|
2020-03-18 15:38:52 +00:00
|
|
|
onPress={() => navigate('EncryptStorage')}
|
|
|
|
component={TouchableOpacity}
|
2020-03-18 16:07:09 +00:00
|
|
|
testID="EncryptStorageButton"
|
2020-03-18 15:38:52 +00:00
|
|
|
/>
|
2019-10-29 23:00:07 -04:00
|
|
|
<BlueListItem title={loc.settings.lightning_settings} component={TouchableOpacity} onPress={() => navigate('LightningSettings')} />
|
|
|
|
<BlueListItem title={loc.settings.language} component={TouchableOpacity} onPress={() => navigate('Language')} />
|
|
|
|
<BlueListItem title={loc.settings.currency} component={TouchableOpacity} onPress={() => navigate('Currency')} />
|
|
|
|
<BlueListItem title={'Electrum server'} component={TouchableOpacity} onPress={() => navigate('ElectrumSettings')} />
|
|
|
|
<BlueListItem title={loc.settings.advanced_options} component={TouchableOpacity} onPress={onShowAdvancedOptions} />
|
|
|
|
{showAdvancedOptions && (
|
|
|
|
<BlueCard>
|
|
|
|
<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' }}>
|
|
|
|
<BlueText>{loc.settings.enable_advanced_mode}</BlueText>
|
|
|
|
<Switch value={advancedModeEnabled} onValueChange={onAdvancedModeSwitch} />
|
|
|
|
</View>
|
|
|
|
</BlueCard>
|
|
|
|
)}
|
2018-09-30 04:31:09 -04:00
|
|
|
|
2019-10-29 23:00:07 -04:00
|
|
|
<BlueListItem title={loc.settings.about} component={TouchableOpacity} onPress={() => navigate('About')} />
|
|
|
|
</ScrollView>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
};
|
2019-12-24 23:44:33 -06:00
|
|
|
Settings.navigationOptions = {
|
|
|
|
...BlueNavigationStyle,
|
|
|
|
};
|
|
|
|
export default Settings;
|