2018-04-01 00:16:42 +01:00
|
|
|
/* global alert */
|
|
|
|
import React, { Component } from 'react';
|
2020-05-24 12:17:26 +03:00
|
|
|
import { ScrollView, StyleSheet } from 'react-native';
|
2018-12-29 22:33:41 -05:00
|
|
|
import { BlueLoading, BlueButton, SafeBlueArea, BlueCard, BlueText, BlueNavigationStyle, BlueSpacing20 } from '../BlueComponents';
|
2018-04-01 00:16:42 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2019-08-23 03:04:23 -04:00
|
|
|
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
2020-07-20 16:38:46 +03:00
|
|
|
import loc from '../loc';
|
2020-10-24 13:20:59 -04:00
|
|
|
import { BlueStorageContext } from '../blue_modules/storage-context';
|
2020-07-01 12:56:52 +01:00
|
|
|
const prompt = require('../blue_modules/prompt');
|
2018-04-01 00:16:42 +01:00
|
|
|
|
2020-05-24 12:17:26 +03:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-04-01 00:16:42 +01:00
|
|
|
export default class PlausibleDeniability extends Component {
|
2020-10-24 13:20:59 -04:00
|
|
|
static contextType = BlueStorageContext;
|
|
|
|
|
2018-04-01 00:16:42 +01:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
isLoading: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (this.state.isLoading) {
|
|
|
|
return <BlueLoading />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-05-24 12:17:26 +03:00
|
|
|
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.root}>
|
2018-04-01 00:16:42 +01:00
|
|
|
<BlueCard>
|
|
|
|
<ScrollView maxHeight={450}>
|
2018-05-30 00:17:44 +01:00
|
|
|
<BlueText>{loc.plausibledeniability.help}</BlueText>
|
2018-04-01 00:16:42 +01:00
|
|
|
|
|
|
|
<BlueText />
|
|
|
|
|
2018-05-30 00:17:44 +01:00
|
|
|
<BlueText>{loc.plausibledeniability.help2}</BlueText>
|
2018-04-01 00:16:42 +01:00
|
|
|
|
2018-12-11 22:52:46 +00:00
|
|
|
<BlueSpacing20 />
|
|
|
|
|
2018-04-01 00:16:42 +01:00
|
|
|
<BlueButton
|
2020-03-19 15:51:35 +00:00
|
|
|
testID="CreateFakeStorageButton"
|
2018-05-30 00:17:44 +01:00
|
|
|
title={loc.plausibledeniability.create_fake_storage}
|
2018-04-01 00:16:42 +01:00
|
|
|
onPress={async () => {
|
2020-06-01 15:54:23 +03:00
|
|
|
const p1 = await prompt(loc.plausibledeniability.create_password, loc.plausibledeniability.create_password_explanation);
|
2020-10-24 13:20:59 -04:00
|
|
|
const isPasswordInUse = p1 === this.context.cachedPassword || (await this.context.isPasswordInUse(p1));
|
2019-08-23 03:04:23 -04:00
|
|
|
if (isPasswordInUse) {
|
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
2018-07-07 14:04:32 +01:00
|
|
|
return alert(loc.plausibledeniability.password_should_not_match);
|
2018-04-01 00:16:42 +01:00
|
|
|
}
|
|
|
|
if (!p1) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-01 15:54:23 +03:00
|
|
|
const p2 = await prompt(loc.plausibledeniability.retype_password);
|
2018-04-01 00:16:42 +01:00
|
|
|
if (p1 !== p2) {
|
2019-08-23 03:04:23 -04:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
2018-05-30 00:17:44 +01:00
|
|
|
return alert(loc.plausibledeniability.passwords_do_not_match);
|
2018-04-01 00:16:42 +01:00
|
|
|
}
|
|
|
|
|
2020-10-24 13:20:59 -04:00
|
|
|
await this.context.createFakeStorage(p1);
|
|
|
|
await this.context.resetWallets();
|
2019-08-23 03:04:23 -04:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
|
2018-05-30 00:17:44 +01:00
|
|
|
alert(loc.plausibledeniability.success);
|
2020-05-29 20:45:05 +01:00
|
|
|
this.props.navigation.popToTop();
|
2018-04-01 00:16:42 +01:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</ScrollView>
|
|
|
|
</BlueCard>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PlausibleDeniability.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
|
|
|
navigate: PropTypes.func,
|
2020-05-29 22:10:43 +01:00
|
|
|
popToTop: PropTypes.func,
|
2018-04-01 00:16:42 +01:00
|
|
|
}),
|
|
|
|
};
|
2020-07-15 13:32:59 -04:00
|
|
|
|
|
|
|
PlausibleDeniability.navigationOptions = ({ navigation, route }) => ({
|
|
|
|
...BlueNavigationStyle(),
|
|
|
|
title: loc.plausibledeniability.title,
|
|
|
|
});
|