BlueWallet/screen/settings.js

126 lines
4.6 KiB
JavaScript
Raw Normal View History

2018-03-31 14:43:08 +01:00
/* global alert */
2018-01-30 22:42:38 +00:00
import React, { Component } from 'react';
2018-06-28 02:43:28 +01:00
import { ScrollView, View, Picker } from 'react-native';
import { FormValidationMessage } from 'react-native-elements';
2018-07-07 14:04:32 +01:00
import { BlueLoading, BlueButton, SafeBlueArea, BlueCard, BlueText, BlueHeaderDefaultSub } from '../BlueComponents';
2018-03-18 15:15:10 +00:00
import PropTypes from 'prop-types';
2018-03-31 14:43:08 +01:00
/** @type {AppStorage} */
2018-03-18 15:15:10 +00:00
let BlueApp = require('../BlueApp');
2018-03-31 14:43:08 +01:00
let prompt = require('../prompt');
2018-05-28 20:18:11 +01:00
let loc = require('../loc');
2018-01-30 22:42:38 +00:00
export default class Settings extends Component {
static navigationOptions = {
2018-06-24 23:22:46 +01:00
tabBarVisible: false,
2018-03-18 15:15:10 +00:00
};
2018-01-30 22:42:38 +00:00
constructor(props) {
super(props);
this.state = {
isLoading: true,
2018-05-28 20:18:11 +01:00
language: loc.getLanguage(),
2018-03-18 15:15:10 +00:00
};
2018-01-30 22:42:38 +00:00
}
async componentDidMount() {
this.setState({
isLoading: false,
2018-03-31 14:43:08 +01:00
storageIsEncrypted: await BlueApp.storageIsEncrypted(),
2018-03-18 15:15:10 +00:00
});
2018-01-30 22:42:38 +00:00
}
render() {
if (this.state.isLoading) {
2018-03-18 15:15:10 +00:00
return <BlueLoading />;
2018-01-30 22:42:38 +00:00
}
return (
2018-03-18 15:15:10 +00:00
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
2018-07-07 14:04:32 +01:00
<BlueHeaderDefaultSub leftText={loc.settings.header} onClose={() => this.props.navigation.goBack()} />
2018-03-24 21:24:20 +00:00
2018-01-30 22:42:38 +00:00
<BlueCard>
2018-03-18 15:15:10 +00:00
<ScrollView maxHeight={450}>
2018-03-31 14:43:08 +01:00
{(() => {
if (this.state.storageIsEncrypted) {
return (
<View>
2018-05-30 00:17:44 +01:00
<BlueText>{loc.settings.storage_encrypted}</BlueText>
2018-04-01 00:16:42 +01:00
<BlueButton
2018-07-07 14:04:32 +01:00
onPress={() => this.props.navigation.navigate('PlausibleDeniability')}
2018-05-28 20:18:11 +01:00
title={loc.settings.plausible_deniability}
2018-04-01 00:16:42 +01:00
/>
2018-03-31 14:43:08 +01:00
</View>
);
} else {
return (
<View>
2018-07-07 14:04:32 +01:00
<FormValidationMessage>{loc.settings.storage_not_encrypted}</FormValidationMessage>
2018-03-31 14:43:08 +01:00
<BlueButton
2018-06-24 23:22:46 +01:00
icon={{
name: 'shield',
type: 'octicon',
color: BlueApp.settings.buttonTextColor,
}}
2018-03-31 14:43:08 +01:00
onPress={async () => {
this.setState({ isLoading: true });
2018-09-18 02:48:53 -04:00
let p1 = await prompt(loc.settings.password, loc.settings.password_explain).catch(() => {
this.setState({ isLoading: false });
this.props.navigation.goBack();
});
2018-04-01 00:16:42 +01:00
if (!p1) {
this.setState({ isLoading: false });
return;
}
2018-09-18 02:48:53 -04:00
let p2 = await prompt(loc.settings.password, loc.settings.retype_password).catch(() => {
this.setState({ isLoading: false });
this.props.navigation.goBack();
});
2018-03-31 14:43:08 +01:00
if (p1 === p2) {
await BlueApp.encryptStorage(p1);
this.setState({
isLoading: false,
storageIsEncrypted: await BlueApp.storageIsEncrypted(),
});
} else {
this.setState({ isLoading: false });
2018-05-28 20:18:11 +01:00
alert(loc.settings.passwords_do_not_match);
2018-03-31 14:43:08 +01:00
}
}}
2018-05-28 20:18:11 +01:00
title={loc.settings.encrypt_storage}
2018-03-31 14:43:08 +01:00
/>
</View>
);
}
})()}
2018-03-24 21:24:20 +00:00
2018-07-07 14:04:32 +01:00
<BlueButton onPress={() => this.props.navigation.navigate('About')} title={loc.settings.about} />
2018-01-30 22:42:38 +00:00
</ScrollView>
2018-05-28 20:18:11 +01:00
<Picker
selectedValue={this.state.language}
onValueChange={(itemValue, itemIndex) => {
console.log('setLanguage', itemValue);
loc.setLanguage(itemValue);
loc.saveLanguage(itemValue);
return this.setState({ language: itemValue });
}}
>
2018-07-07 14:04:32 +01:00
<Picker.Item color={BlueApp.settings.foregroundColor} label="English" value="en" />
<Picker.Item color={BlueApp.settings.foregroundColor} label="Русский" value="ru" />
<Picker.Item color={BlueApp.settings.foregroundColor} label="Українська" value="ua" />
<Picker.Item color={BlueApp.settings.foregroundColor} label="Spanish" value="es" />
<Picker.Item color={BlueApp.settings.foregroundColor} label="Portuguese" value="pt" />
2018-05-28 20:18:11 +01:00
</Picker>
2018-01-30 22:42:38 +00:00
</BlueCard>
</SafeBlueArea>
);
}
}
2018-03-18 15:15:10 +00:00
Settings.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
2018-06-24 23:22:46 +01:00
goBack: PropTypes.func,
2018-03-18 15:15:10 +00:00
}),
};