BlueWallet/screen/plausibledeniability.js

95 lines
3.0 KiB
JavaScript
Raw Normal View History

2018-04-01 01:16:42 +02:00
/* global alert */
import React, { Component } from 'react';
import { ScrollView, StyleSheet } from 'react-native';
import { BlueLoading, BlueButton, SafeBlueArea, BlueCard, BlueText, BlueNavigationStyle, BlueSpacing20 } from '../BlueComponents';
2018-04-01 01:16:42 +02:00
import PropTypes from 'prop-types';
2019-08-23 09:04:23 +02:00
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import { AppStorage } from '../class';
const BlueApp: AppStorage = require('../BlueApp');
const prompt = require('../prompt');
const EV = require('../events');
const loc = require('../loc');
2018-04-01 01:16:42 +02:00
const styles = StyleSheet.create({
root: {
flex: 1,
},
});
2018-04-01 01:16:42 +02:00
export default class PlausibleDeniability extends Component {
static navigationOptions = {
...BlueNavigationStyle(),
title: loc.plausibledeniability.title,
2018-04-01 01:16:42 +02:00
};
constructor(props) {
super(props);
this.state = {
isLoading: true,
};
}
async componentDidMount() {
this.setState({
isLoading: false,
});
}
render() {
if (this.state.isLoading) {
return <BlueLoading />;
}
return (
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.root}>
2018-04-01 01:16:42 +02:00
<BlueCard>
<ScrollView maxHeight={450}>
2018-05-30 01:17:44 +02:00
<BlueText>{loc.plausibledeniability.help}</BlueText>
2018-04-01 01:16:42 +02:00
<BlueText />
2018-05-30 01:17:44 +02:00
<BlueText>{loc.plausibledeniability.help2}</BlueText>
2018-04-01 01:16:42 +02:00
<BlueSpacing20 />
2018-04-01 01:16:42 +02:00
<BlueButton
2020-03-19 16:51:35 +01:00
testID="CreateFakeStorageButton"
2018-05-30 01:17:44 +02:00
title={loc.plausibledeniability.create_fake_storage}
2018-04-01 01:16:42 +02:00
onPress={async () => {
const p1 = await prompt(loc.plausibledeniability.create_password, loc.plausibledeniability.create_password_explanation);
2019-08-23 09:04:23 +02:00
const isPasswordInUse = p1 === BlueApp.cachedPassword || (await BlueApp.isPasswordInUse(p1));
if (isPasswordInUse) {
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
2018-07-07 15:04:32 +02:00
return alert(loc.plausibledeniability.password_should_not_match);
2018-04-01 01:16:42 +02:00
}
if (!p1) {
return;
}
const p2 = await prompt(loc.plausibledeniability.retype_password);
2018-04-01 01:16:42 +02:00
if (p1 !== p2) {
2019-08-23 09:04:23 +02:00
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
2018-05-30 01:17:44 +02:00
return alert(loc.plausibledeniability.passwords_do_not_match);
2018-04-01 01:16:42 +02:00
}
await BlueApp.createFakeStorage(p1);
EV(EV.enum.WALLETS_COUNT_CHANGED);
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED);
2019-08-23 09:04:23 +02:00
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
2018-05-30 01:17:44 +02:00
alert(loc.plausibledeniability.success);
this.props.navigation.popToTop();
2018-04-01 01:16:42 +02:00
}}
/>
</ScrollView>
</BlueCard>
</SafeBlueArea>
);
}
}
PlausibleDeniability.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
2020-05-29 23:10:43 +02:00
popToTop: PropTypes.func,
2018-04-01 01:16:42 +02:00
}),
};