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';
|
2020-12-25 17:09:53 +01:00
|
|
|
|
|
|
|
import navigationStyle from '../components/navigationStyle';
|
2023-12-27 07:52:11 +01:00
|
|
|
import { BlueLoading, 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';
|
2023-11-15 09:40:22 +01:00
|
|
|
import Button from '../components/Button';
|
2023-12-29 12:52:12 +01:00
|
|
|
import triggerHapticFeedback, { HapticFeedbackTypes } from '../blue_modules/hapticFeedback';
|
2023-12-27 07:52:11 +01:00
|
|
|
import SafeArea from '../components/SafeArea';
|
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);
|
2023-12-29 12:52:12 +01:00
|
|
|
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
|
2020-11-22 09:04:04 +01:00
|
|
|
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);
|
2023-12-29 12:52:12 +01:00
|
|
|
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
|
2020-11-22 09:04:04 +01:00
|
|
|
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();
|
2023-12-29 12:52:12 +01:00
|
|
|
triggerHapticFeedback(HapticFeedbackTypes.NotificationSuccess);
|
2020-11-22 09:04:04 +01:00
|
|
|
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 ? (
|
2023-12-27 07:52:11 +01:00
|
|
|
<SafeArea>
|
2020-11-22 09:04:04 +01:00
|
|
|
<BlueLoading />
|
2023-12-27 07:52:11 +01:00
|
|
|
</SafeArea>
|
2020-11-22 09:04:04 +01:00
|
|
|
) : (
|
2023-12-27 07:52:11 +01:00
|
|
|
<SafeArea>
|
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
|
|
|
|
2023-11-15 09:40:22 +01:00
|
|
|
<Button
|
2020-11-22 09:04:04 +01:00
|
|
|
testID="CreateFakeStorageButton"
|
|
|
|
title={loc.plausibledeniability.create_fake_storage}
|
|
|
|
onPress={handleOnCreateFakeStorageButtonPressed}
|
|
|
|
/>
|
|
|
|
</ScrollView>
|
|
|
|
</BlueCard>
|
2023-12-27 07:52:11 +01:00
|
|
|
</SafeArea>
|
2020-11-22 09:04:04 +01:00
|
|
|
);
|
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,
|
|
|
|
});
|