BlueWallet/screen/plausibledeniability.js

81 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-11-22 09:04:04 +01:00
import React, { useContext, useState } from 'react';
import { ScrollView } from 'react-native';
import { useNavigation } from '@react-navigation/native';
2019-08-23 09:04:23 +02:00
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
2020-12-25 17:09:53 +01:00
import navigationStyle from '../components/navigationStyle';
import { BlueLoading, BlueButton, SafeBlueArea, BlueCard, BlueText, BlueSpacing20 } from '../BlueComponents';
2020-07-20 15:38:46 +02:00
import loc from '../loc';
import { BlueStorageContext } from '../blue_modules/storage-context';
import alert from '../components/Alert';
const prompt = require('../blue_modules/prompt');
2018-04-01 01:16:42 +02:00
2020-11-22 09:04:04 +01:00
const PlausibleDeniability = () => {
const { cachedPassword, isPasswordInUse, createFakeStorage, resetWallets } = useContext(BlueStorageContext);
const [isLoading, setIsLoading] = useState(false);
const { popToTop } = useNavigation();
2020-11-22 09:04:04 +01:00
const handleOnCreateFakeStorageButtonPressed = async () => {
setIsLoading(true);
try {
const p1 = await prompt(loc.plausibledeniability.create_password, loc.plausibledeniability.create_password_explanation);
const isProvidedPasswordInUse = p1 === cachedPassword || (await isPasswordInUse(p1));
if (isProvidedPasswordInUse) {
setIsLoading(false);
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
return alert(loc.plausibledeniability.password_should_not_match);
}
if (!p1) {
setIsLoading(false);
return;
}
const p2 = await prompt(loc.plausibledeniability.retype_password);
if (p1 !== p2) {
setIsLoading(false);
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
return alert(loc.plausibledeniability.passwords_do_not_match);
}
2018-04-01 01:16:42 +02:00
2020-11-22 09:04:04 +01:00
await createFakeStorage(p1);
await resetWallets();
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
alert(loc.plausibledeniability.success);
popToTop();
} catch {
setIsLoading(false);
2018-04-01 01:16:42 +02:00
}
2020-11-22 09:04:04 +01:00
};
2018-04-01 01:16:42 +02:00
2020-11-22 09:04:04 +01:00
return isLoading ? (
<SafeBlueArea>
2020-11-22 09:04:04 +01:00
<BlueLoading />
</SafeBlueArea>
) : (
<SafeBlueArea>
2020-11-22 09:04:04 +01:00
<BlueCard>
<ScrollView maxHeight={450}>
<BlueText>{loc.plausibledeniability.help}</BlueText>
2018-04-01 01:16:42 +02:00
2020-11-22 09:04:04 +01:00
<BlueText />
2018-04-01 01:16:42 +02:00
2020-11-22 09:04:04 +01:00
<BlueText>{loc.plausibledeniability.help2}</BlueText>
2020-11-22 09:04:04 +01:00
<BlueSpacing20 />
2018-04-01 01:16:42 +02:00
2020-11-22 09:04:04 +01:00
<BlueButton
testID="CreateFakeStorageButton"
title={loc.plausibledeniability.create_fake_storage}
onPress={handleOnCreateFakeStorageButtonPressed}
/>
</ScrollView>
</BlueCard>
</SafeBlueArea>
);
2018-04-01 01:16:42 +02:00
};
2020-07-15 19:32:59 +02:00
2020-11-22 09:04:04 +01:00
export default PlausibleDeniability;
2020-12-25 17:09:53 +01:00
PlausibleDeniability.navigationOptions = navigationStyle({
2020-07-15 19:32:59 +02:00
title: loc.plausibledeniability.title,
});