BlueWallet/screen/settings.js

141 lines
4.1 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-03-31 14:43:08 +01:00
import { ScrollView, View } 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-01-30 22:42:38 +00:00
export default class Settings extends Component {
static navigationOptions = {
tabBarLabel: 'Settings',
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-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={{
text: 'Settings',
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')
}
title="Plausible deniability..."
/>
2018-03-31 14:43:08 +01:00
</View>
);
} else {
return (
<View>
<FormValidationMessage>
Storage: not encrypted
</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(
'Password',
'Create the password you will use to decrypt the storage',
);
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(
'Password',
'Re-type the password',
);
if (p1 === p2) {
await BlueApp.encryptStorage(p1);
this.setState({
isLoading: false,
storageIsEncrypted: await BlueApp.storageIsEncrypted(),
});
} else {
this.setState({ isLoading: false });
alert('Passwords do not match. Please try again');
}
}}
title="Encrypt storage"
/>
</View>
);
}
})()}
2018-03-24 21:24:20 +00:00
<BlueButton
2018-03-31 14:43:08 +01:00
onPress={() => this.props.navigation.navigate('About')}
title="About"
2018-03-24 21:24:20 +00:00
/>
2018-01-30 22:42:38 +00:00
</ScrollView>
</BlueCard>
</SafeBlueArea>
);
}
}
2018-03-18 15:15:10 +00:00
Settings.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
}),
};