BlueWallet/screen/settings.js

164 lines
4.9 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-05-28 20:18:11 +01:00
import { ScrollView, View, Picker } from 'react-native';
2018-01-30 22:42:38 +00:00
import Ionicons from 'react-native-vector-icons/Ionicons';
2018-03-31 14:43:08 +01:00
import { Icon, FormValidationMessage } from 'react-native-elements';
2018-01-30 22:42:38 +00:00
import {
2018-03-18 15:15:10 +00:00
BlueLoading,
BlueSpacing20,
BlueButton,
SafeBlueArea,
BlueCard,
BlueText,
BlueHeader,
} from '../BlueComponents';
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-05-28 20:18:11 +01:00
tabBarLabel: loc.settings.tabBarLabel,
2018-01-30 22:42:38 +00:00
tabBarIcon: ({ tintColor, focused }) => (
<Ionicons
name={focused ? 'ios-settings' : 'ios-settings-outline'}
size={26}
style={{ color: tintColor }}
/>
),
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-01-30 22:42:38 +00:00
<BlueHeader
backgroundColor={BlueApp.settings.brandingColor}
2018-03-18 15:15:10 +00:00
leftComponent={
<Icon
name="menu"
2018-05-22 18:10:53 +01:00
color={BlueApp.settings.foregroundColor}
2018-03-18 15:15:10 +00:00
onPress={() => this.props.navigation.navigate('DrawerToggle')}
/>
}
centerComponent={{
2018-05-28 20:18:11 +01:00
text: loc.settings.header,
2018-05-22 18:10:53 +01:00
style: { color: BlueApp.settings.foregroundColor, fontSize: 23 },
2018-03-18 15:15:10 +00:00
}}
2018-01-30 22:42:38 +00:00
/>
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}>
<BlueSpacing20 />
2018-03-31 14:43:08 +01:00
{(() => {
if (this.state.storageIsEncrypted) {
return (
<View>
<BlueText>Storage: encrypted</BlueText>
2018-04-01 00:16:42 +01:00
<BlueButton
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>
<FormValidationMessage>
2018-05-28 20:18:11 +01:00
{loc.settings.storage_not_encrypted}
2018-03-31 14:43:08 +01:00
</FormValidationMessage>
<BlueButton
2018-04-01 00:16:42 +01:00
icon={{ name: 'shield', type: 'octicon' }}
2018-03-31 14:43:08 +01:00
onPress={async () => {
this.setState({ isLoading: true });
let p1 = await prompt(
2018-05-28 20:18:11 +01:00
loc.settings.password,
loc.settings.password_explain,
2018-03-31 14:43:08 +01:00
);
2018-04-01 00:16:42 +01:00
if (!p1) {
this.setState({ isLoading: false });
return;
}
2018-03-31 14:43:08 +01:00
let p2 = await prompt(
2018-05-28 20:18:11 +01:00
loc.settings.password,
loc.settings.retype_password,
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
<BlueButton
2018-03-31 14:43:08 +01:00
onPress={() => this.props.navigation.navigate('About')}
2018-05-28 20:18:11 +01:00
title={loc.settings.about}
2018-03-24 21:24:20 +00:00
/>
2018-01-30 22:42:38 +00:00
</ScrollView>
2018-05-28 20:18:11 +01:00
<Picker
selectedValue={this.state.language}
style={{ height: 150 }}
onValueChange={(itemValue, itemIndex) => {
console.log('setLanguage', itemValue);
loc.setLanguage(itemValue);
loc.saveLanguage(itemValue);
return this.setState({ language: itemValue });
}}
>
<Picker.Item
color={BlueApp.settings.foregroundColor}
label="English"
value="en"
/>
<Picker.Item
color={BlueApp.settings.foregroundColor}
label="Русский"
value="ru"
/>
</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,
}),
};