2020-11-22 09:04:04 +01:00
|
|
|
import React, { useContext, useState } from 'react';
|
2021-03-22 12:54:17 +01:00
|
|
|
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';
|
2020-10-24 19:20:59 +02:00
|
|
|
import { BlueStorageContext } from '../blue_modules/storage-context';
|
2021-10-04 08:02:33 +02:00
|
|
|
import alert from '../components/Alert';
|
2022-09-05 20:34:02 +02:00
|
|
|
const prompt = require('../helpers/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-10-24 19:20:59 +02:00
|
|
|
|
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 ? (
|
2021-03-22 12:54:17 +01:00
|
|
|
<SafeBlueArea>
|
2020-11-22 09:04:04 +01:00
|
|
|
<BlueLoading />
|
|
|
|
</SafeBlueArea>
|
|
|
|
) : (
|
2021-03-22 12:54:17 +01:00
|
|
|
<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>
|
2018-12-11 23:52:46 +01:00
|
|
|
|
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,
|
|
|
|
});
|