BlueWallet/screen/settings/settings.js

96 lines
3.2 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
2019-05-19 21:49:42 +02:00
import { ScrollView, Switch, TouchableOpacity } from 'react-native';
import {
BlueText,
BlueCard,
BlueLoading,
SafeBlueArea,
BlueNavigationStyle,
BlueHeaderDefaultSub,
BlueListItem,
} from '../../BlueComponents';
import AsyncStorage from '@react-native-community/async-storage';
import PropTypes from 'prop-types';
2019-05-19 21:49:42 +02:00
import { AppStorage } from '../../class';
let loc = require('../../loc');
export default class Settings extends Component {
static navigationOptions = {
...BlueNavigationStyle,
};
constructor(props) {
super(props);
this.state = {
isLoading: true,
language: loc.getLanguage(),
};
}
async componentDidMount() {
2019-05-19 21:49:42 +02:00
let advancedModeEnabled = !!(await AsyncStorage.getItem(AppStorage.ADVANCED_MODE_ENABLED));
this.setState({
isLoading: false,
2019-05-19 21:49:42 +02:00
advancedModeEnabled,
});
}
2019-05-19 21:49:42 +02:00
async onAdvancedModeSwitch(value) {
if (value) {
await AsyncStorage.setItem(AppStorage.ADVANCED_MODE_ENABLED, '1');
} else {
await AsyncStorage.removeItem(AppStorage.ADVANCED_MODE_ENABLED);
}
this.setState({ advancedModeEnabled: value });
}
render() {
if (this.state.isLoading) {
return <BlueLoading />;
}
return (
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
<BlueHeaderDefaultSub leftText={loc.settings.header} rightComponent={null} />
<ScrollView maxHeight={450}>
<TouchableOpacity onPress={() => this.props.navigation.navigate('EncryptStorage')}>
<BlueListItem title={loc.settings.encrypt_storage} />
</TouchableOpacity>
2018-11-04 22:21:07 +01:00
<TouchableOpacity onPress={() => this.props.navigation.navigate('LightningSettings')}>
<BlueListItem title={loc.settings.lightning_settings} />
2018-11-04 22:21:07 +01:00
</TouchableOpacity>
<TouchableOpacity onPress={() => this.props.navigation.navigate('Language')}>
<BlueListItem title={loc.settings.language} />
</TouchableOpacity>
2018-12-24 07:14:53 +01:00
<TouchableOpacity onPress={() => this.props.navigation.navigate('Currency')}>
<BlueListItem title={loc.settings.currency} />
</TouchableOpacity>
2019-07-18 12:22:01 +02:00
<TouchableOpacity onPress={() => this.props.navigation.navigate('ElectrumSettings')}>
<BlueListItem title={'Electrum server'} />
</TouchableOpacity>
2019-05-19 21:49:42 +02:00
<TouchableOpacity onPress={() => this.setState({ showAdvancedOptions: !this.state.showAdvancedOptions })}>
<BlueListItem title={loc.settings.advanced_options} />
</TouchableOpacity>
{this.state.showAdvancedOptions && (
<BlueCard>
<BlueText>{loc.settings.enable_advanced_mode}</BlueText>
<Switch value={this.state.advancedModeEnabled} onValueChange={value => this.onAdvancedModeSwitch(value)} />
</BlueCard>
)}
<TouchableOpacity onPress={() => this.props.navigation.navigate('About')}>
<BlueListItem title={loc.settings.about} />
</TouchableOpacity>
</ScrollView>
</SafeBlueArea>
);
}
}
Settings.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
goBack: PropTypes.func,
}),
};