REF: Plausible deniability uses Hooks

This commit is contained in:
marcosrdz 2020-11-22 03:04:04 -05:00
parent 9ddddf5f9d
commit c0b525de8a
17 changed files with 112 additions and 133 deletions

View file

@ -736,21 +736,7 @@ export class BlueCard extends Component {
}
}
export class BlueText extends Component {
render() {
return (
<Text
style={{
color: BlueCurrentTheme.colors.foregroundColor,
...this.props.style,
}}
{...this.props}
/>
);
}
}
export const BlueTextHooks = props => {
export const BlueText = props => {
const { colors } = useTheme();
return (
<Text
@ -762,13 +748,8 @@ export const BlueTextHooks = props => {
/>
);
};
export class BlueTextCentered extends Component {
render() {
return <Text {...this.props} style={{ color: BlueCurrentTheme.colors.foregroundColor, textAlign: 'center' }} />;
}
}
export const BlueTextCenteredHooks = props => {
export const BlueTextCentered = props => {
const { colors } = useTheme();
return <Text {...props} style={{ color: colors.foregroundColor, textAlign: 'center' }} />;
};

View file

@ -1,6 +1,6 @@
{
"_": {
"bad_password": "Wrong password, please try again.",
"bad_password": "Incorrect password, please try again.",
"cancel": "Cancel",
"continue": "Continue",
"enter_password": "Enter password",
@ -121,7 +121,7 @@
"help": "Under certain circumstances, you might be forced to disclose a password. To keep your coins safe, BlueWallet can create another encrypted storage, with a different password. Under pressure, you can disclose this password to a 3rd party. If entered in BlueWallet, it will unlock a new 'fake' storage. This will seem legit to a 3rd party, but it will secretly keep your main storage with coins safe.",
"help2": "The new storage will be fully functional, and you can store some minimum amounts there so it looks more believable.",
"password_should_not_match": "Password is currently in use. Please, try a different password.",
"passwords_do_not_match": "Passwords do not match, try again",
"passwords_do_not_match": "Passwords do not match, please try again.",
"retype_password": "Retype password",
"success": "Success",
"title": "Plausible Deniability"

View file

@ -1,11 +1,11 @@
/* global alert */
import React, { Component } from 'react';
import React, { useContext, useState } from 'react';
import { ScrollView, StyleSheet } from 'react-native';
import { BlueLoading, BlueButton, SafeBlueArea, BlueCard, BlueText, BlueNavigationStyle, BlueSpacing20 } from '../BlueComponents';
import PropTypes from 'prop-types';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import loc from '../loc';
import { BlueStorageContext } from '../blue_modules/storage-context';
import { useNavigation, useTheme } from '@react-navigation/native';
const prompt = require('../blue_modules/prompt');
const styles = StyleSheet.create({
@ -14,80 +14,78 @@ const styles = StyleSheet.create({
},
});
export default class PlausibleDeniability extends Component {
static contextType = BlueStorageContext;
const PlausibleDeniability = () => {
const { cachedPassword, isPasswordInUse, createFakeStorage, resetWallets } = useContext(BlueStorageContext);
const [isLoading, setIsLoading] = useState(false);
const { popToTop } = useNavigation();
const { colors } = useTheme();
const stylesHook = StyleSheet.create({
root: {
backgroundColor: colors.background,
},
});
constructor(props) {
super(props);
this.state = {
isLoading: true,
};
}
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);
}
async componentDidMount() {
this.setState({
isLoading: false,
});
}
render() {
if (this.state.isLoading) {
return <BlueLoading />;
await createFakeStorage(p1);
await resetWallets();
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
alert(loc.plausibledeniability.success);
popToTop();
} catch {
setIsLoading(false);
}
};
return (
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.root}>
<BlueCard>
<ScrollView maxHeight={450}>
<BlueText>{loc.plausibledeniability.help}</BlueText>
return isLoading ? (
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={[styles.root, stylesHook.root]}>
<BlueLoading />
</SafeBlueArea>
) : (
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={[styles.root, stylesHook.root]}>
<BlueCard>
<ScrollView maxHeight={450}>
<BlueText>{loc.plausibledeniability.help}</BlueText>
<BlueText />
<BlueText />
<BlueText>{loc.plausibledeniability.help2}</BlueText>
<BlueText>{loc.plausibledeniability.help2}</BlueText>
<BlueSpacing20 />
<BlueSpacing20 />
<BlueButton
testID="CreateFakeStorageButton"
title={loc.plausibledeniability.create_fake_storage}
onPress={async () => {
const p1 = await prompt(loc.plausibledeniability.create_password, loc.plausibledeniability.create_password_explanation);
const isPasswordInUse = p1 === this.context.cachedPassword || (await this.context.isPasswordInUse(p1));
if (isPasswordInUse) {
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
return alert(loc.plausibledeniability.password_should_not_match);
}
if (!p1) {
return;
}
const p2 = await prompt(loc.plausibledeniability.retype_password);
if (p1 !== p2) {
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
return alert(loc.plausibledeniability.passwords_do_not_match);
}
await this.context.createFakeStorage(p1);
await this.context.resetWallets();
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
alert(loc.plausibledeniability.success);
this.props.navigation.popToTop();
}}
/>
</ScrollView>
</BlueCard>
</SafeBlueArea>
);
}
}
PlausibleDeniability.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
popToTop: PropTypes.func,
}),
<BlueButton
testID="CreateFakeStorageButton"
title={loc.plausibledeniability.create_fake_storage}
onPress={handleOnCreateFakeStorageButtonPressed}
/>
</ScrollView>
</BlueCard>
</SafeBlueArea>
);
};
PlausibleDeniability.navigationOptions = ({ navigation, route }) => ({
export default PlausibleDeniability;
PlausibleDeniability.navigationOptions = () => ({
...BlueNavigationStyle(),
title: loc.plausibledeniability.title,
});

View file

@ -7,7 +7,7 @@ import ImagePicker from 'react-native-image-picker';
import { decodeUR, extractSingleWorkload } from 'bc-ur';
import { useNavigation, useRoute, useIsFocused, useTheme } from '@react-navigation/native';
import loc from '../../loc';
import { BlueLoadingHook, BlueTextHooks, BlueButtonHook, BlueSpacing40 } from '../../BlueComponents';
import { BlueLoadingHook, BlueText, BlueButtonHook, BlueSpacing40 } from '../../BlueComponents';
import { BlueCurrentTheme } from '../../components/themes';
import { openPrivacyDesktopSettings } from '../../class/camera';
const LocalQRCode = require('@remobile/react-native-qrcode-local-image');
@ -253,7 +253,7 @@ const ScanQRCode = () => {
)}
{cameraStatus === RNCamera.Constants.CameraStatus.NOT_AUTHORIZED && (
<View style={[styles.openSettingsContainer, stylesHook.openSettingsContainer]}>
<BlueTextHooks>{loc.send.permission_camera_message}</BlueTextHooks>
<BlueText>{loc.send.permission_camera_message}</BlueText>
<BlueSpacing40 />
<BlueButtonHook title={loc.send.open_settings} onPress={openPrivacyDesktopSettings} />
</View>
@ -271,15 +271,15 @@ const ScanQRCode = () => {
)}
{urTotal > 0 && (
<View style={styles.progressWrapper} testID="UrProgressBar">
<BlueTextHooks>
<BlueText>
{urHave} / {urTotal}
</BlueTextHooks>
</BlueText>
</View>
)}
{backdoorVisible && (
<View style={styles.backdoorInputWrapper}>
<BlueTextHooks>Provide QR code contents manually:</BlueTextHooks>
<BlueText>Provide QR code contents manually:</BlueText>
<TextInput
testID="scanQrBackdoorInput"
multiline

View file

@ -1,6 +1,6 @@
import React, { useContext, useEffect, useState } from 'react';
import { ScrollView, Platform, TouchableWithoutFeedback, TouchableOpacity, StyleSheet } from 'react-native';
import { BlueLoading, BlueTextHooks, BlueSpacing20, BlueListItem, BlueNavigationStyle, BlueCard } from '../../BlueComponents';
import { BlueLoading, BlueText, BlueSpacing20, BlueListItem, BlueNavigationStyle, BlueCard } from '../../BlueComponents';
import { useNavigation, useTheme } from '@react-navigation/native';
import HandoffSettings from '../../class/handoff';
import loc from '../../loc';
@ -70,7 +70,7 @@ const GeneralSettings = () => {
switch={{ onValueChange: onHandOffEnabledSwitch, value: isHandoffUseEnabled }}
/>
<BlueCard>
<BlueTextHooks>{loc.settings.general_continuity_e}</BlueTextHooks>
<BlueText>{loc.settings.general_continuity_e}</BlueText>
</BlueCard>
<BlueSpacing20 />
</>
@ -81,7 +81,7 @@ const GeneralSettings = () => {
switch={{ onValueChange: onAdvancedModeSwitch, value: isAdancedModeSwitchEnabled }}
/>
<BlueCard>
<BlueTextHooks>{loc.settings.general_adv_mode_e}</BlueTextHooks>
<BlueText>{loc.settings.general_adv_mode_e}</BlueText>
</BlueCard>
<BlueSpacing20 />
</ScrollView>

View file

@ -1,6 +1,6 @@
import React, { useContext, useEffect, useState } from 'react';
import { ScrollView, TouchableWithoutFeedback, StyleSheet, Linking } from 'react-native';
import { BlueTextHooks, BlueSpacing20, BlueListItem, BlueNavigationStyle, BlueCard } from '../../BlueComponents';
import { BlueText, BlueSpacing20, BlueListItem, BlueNavigationStyle, BlueCard } from '../../BlueComponents';
import { useTheme } from '@react-navigation/native';
import loc from '../../loc';
import BlueClipboard from '../../blue_modules/clipboard';
@ -71,7 +71,7 @@ const SettingsPrivacy = () => {
switch={{ onValueChange, value: isReadClipboardAllowed, disabled: isLoading === sections.ALL }}
/>
<BlueCard>
<BlueTextHooks>{loc.settings.privacy_clipboard_explanation}</BlueTextHooks>
<BlueText>{loc.settings.privacy_clipboard_explanation}</BlueText>
</BlueCard>
<BlueSpacing20 />
{!storageIsEncrypted && (
@ -83,7 +83,7 @@ const SettingsPrivacy = () => {
switch={{ onValueChange: onQuickActionsValueChange, value: isQuickActionsEnabled, disabled: isLoading === sections.ALL }}
/>
<BlueCard>
<BlueTextHooks>{loc.settings.privacy_quickactions_explanation}</BlueTextHooks>
<BlueText>{loc.settings.privacy_quickactions_explanation}</BlueText>
</BlueCard>
</>
)}

View file

@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import { FlatList, TouchableOpacity, ActivityIndicator, View, StyleSheet } from 'react-native';
import { SafeBlueArea, BlueListItem, BlueTextHooks, BlueCard, BlueNavigationStyle } from '../../BlueComponents';
import { SafeBlueArea, BlueListItem, BlueText, BlueCard, BlueNavigationStyle } from '../../BlueComponents';
import PropTypes from 'prop-types';
import { FiatUnit } from '../../models/fiatUnit';
import loc from '../../loc';
@ -70,7 +70,7 @@ const Currency = () => {
}}
/>
<BlueCard>
<BlueTextHooks>{loc.settings.currency_source}</BlueTextHooks>
<BlueText>{loc.settings.currency_source}</BlueText>
</BlueCard>
</SafeBlueArea>
);

View file

@ -1,7 +1,7 @@
import React, { useContext, useEffect, useState } from 'react';
import { View, TouchableWithoutFeedback, StyleSheet } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { SafeBlueArea, BlueCard, BlueNavigationStyle, BlueListItem, BlueTextHooks } from '../../BlueComponents';
import { SafeBlueArea, BlueCard, BlueNavigationStyle, BlueListItem, BlueText } from '../../BlueComponents';
import OnAppLaunch from '../../class/on-app-launch';
import loc from '../../loc';
import { BlueStorageContext } from '../../blue_modules/storage-context';
@ -68,7 +68,7 @@ const DefaultView = () => {
}}
/>
<BlueCard>
<BlueTextHooks>{loc.settings.default_desc}</BlueTextHooks>
<BlueText>{loc.settings.default_desc}</BlueText>
</BlueCard>
{!viewAllWalletsEnabled && (
<BlueListItem title={loc.settings.default_info} onPress={selectWallet} rightTitle={defaultWalletLabel} chevron />

View file

@ -10,7 +10,7 @@ import {
BlueCard,
BlueListItem,
BlueHeaderDefaultSubHooks,
BlueTextHooks,
BlueText,
BlueNavigationStyle,
} from '../../BlueComponents';
import Biometric from '../../class/biometrics';
@ -163,7 +163,7 @@ const EncryptStorage = () => {
switch={{ value: biometrics.isBiometricsEnabled, onValueChange: onUseBiometricSwitch }}
/>
<BlueCard>
<BlueTextHooks>{loc.formatString(loc.settings.encrypt_use_expl, { type: biometrics.biometricsType })}</BlueTextHooks>
<BlueText>{loc.formatString(loc.settings.encrypt_use_expl, { type: biometrics.biometricsType })}</BlueText>
</BlueCard>
<BlueSpacing20 />
</>

View file

@ -1,6 +1,6 @@
import React, { useState, useEffect, useCallback } from 'react';
import { FlatList, StyleSheet } from 'react-native';
import { SafeBlueArea, BlueListItem, BlueCard, BlueLoadingHook, BlueNavigationStyle, BlueTextHooks } from '../../BlueComponents';
import { SafeBlueArea, BlueListItem, BlueCard, BlueLoadingHook, BlueNavigationStyle, BlueText } from '../../BlueComponents';
import { AvailableLanguages } from '../../loc/languages';
import loc from '../../loc';
@ -45,7 +45,7 @@ const Language = () => {
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.flex}>
<FlatList style={styles.flex} keyExtractor={(_item, index) => `${index}`} data={AvailableLanguages} renderItem={renderItem} />
<BlueCard>
<BlueTextHooks>{loc.settings.language_restart}</BlueTextHooks>
<BlueText>{loc.settings.language_restart}</BlueText>
</BlueCard>
</SafeBlueArea>
);

View file

@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import { ScrollView, StyleSheet } from 'react-native';
import { SafeBlueArea, BlueCard, BlueTextHooks, BlueNavigationStyle, BlueSpacing20, BlueLoadingHook } from '../../BlueComponents';
import { SafeBlueArea, BlueCard, BlueText, BlueNavigationStyle, BlueSpacing20, BlueLoadingHook } from '../../BlueComponents';
/** @type {AppStorage} */
const styles = StyleSheet.create({
@ -22,29 +22,29 @@ const Licensing = () => {
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.root}>
<ScrollView>
<BlueCard>
<BlueTextHooks>MIT License</BlueTextHooks>
<BlueText>MIT License</BlueText>
<BlueSpacing20 />
<BlueTextHooks>Copyright (c) 2018-2020 BlueWallet Services</BlueTextHooks>
<BlueText>Copyright (c) 2018-2020 BlueWallet Services</BlueText>
<BlueSpacing20 />
<BlueTextHooks>
<BlueText>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
</BlueTextHooks>
</BlueText>
<BlueSpacing20 />
<BlueTextHooks>
<BlueText>
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
</BlueTextHooks>
</BlueText>
<BlueSpacing20 />
<BlueTextHooks>
<BlueText>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</BlueTextHooks>
</BlueText>
</BlueCard>
</ScrollView>
</SafeBlueArea>

View file

@ -12,7 +12,7 @@ import {
BlueCard,
BlueNavigationStyle,
BlueLoadingHook,
BlueTextHooks,
BlueText,
BlueButtonLink,
} from '../../BlueComponents';
import { LightningCustodianWallet } from '../../class/wallets/lightning-custodian-wallet';
@ -95,7 +95,7 @@ const LightningSettings = () => {
return (
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.root}>
<BlueCard>
<BlueTextHooks>{loc.settings.lightning_settings_explain}</BlueTextHooks>
<BlueText>{loc.settings.lightning_settings_explain}</BlueText>
</BlueCard>
<Button

View file

@ -3,7 +3,7 @@ import React, { useCallback, useEffect, useState } from 'react';
import { ScrollView, TouchableWithoutFeedback, StyleSheet, Linking, View, TextInput } from 'react-native';
import {
BlueLoading,
BlueTextHooks,
BlueText,
BlueSpacing20,
BlueListItem,
BlueNavigationStyle,
@ -110,7 +110,7 @@ const NotificationSettings = () => {
<BlueSpacing20 />
<BlueCard>
<BlueTextHooks>{loc.settings.groundcontrol_explanation}</BlueTextHooks>
<BlueText>{loc.settings.groundcontrol_explanation}</BlueText>
</BlueCard>
<Button
@ -143,12 +143,12 @@ const NotificationSettings = () => {
</View>
<BlueSpacing20 />
<BlueTextHooks style={styles.centered} onPress={() => setShowTokenInfo(isShowTokenInfo + 1)}>
<BlueText style={styles.centered} onPress={() => setShowTokenInfo(isShowTokenInfo + 1)}>
Ground Control to Major Tom
</BlueTextHooks>
<BlueTextHooks style={styles.centered} onPress={() => setShowTokenInfo(isShowTokenInfo + 1)}>
</BlueText>
<BlueText style={styles.centered} onPress={() => setShowTokenInfo(isShowTokenInfo + 1)}>
Commencing countdown, engines on
</BlueTextHooks>
</BlueText>
{isShowTokenInfo >= 9 && (
<View>

View file

@ -1,6 +1,6 @@
import React from 'react';
import { ScrollView, StyleSheet } from 'react-native';
import { SafeBlueArea, BlueCard, BlueNavigationStyle, BlueTextHooks } from '../../BlueComponents';
import { SafeBlueArea, BlueCard, BlueNavigationStyle, BlueText } from '../../BlueComponents';
import { useTheme } from '@react-navigation/native';
import loc from '../../loc';
@ -18,7 +18,7 @@ const ReleaseNotes = () => {
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.root}>
<ScrollView>
<BlueCard>
<BlueTextHooks>{notes}</BlueTextHooks>
<BlueText>{notes}</BlueText>
</BlueCard>
</ScrollView>
</SafeBlueArea>

View file

@ -14,7 +14,7 @@ import {
} from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
import {
BlueTextHooks,
BlueText,
BlueListItem,
LightningButton,
BitcoinButton,
@ -288,7 +288,7 @@ const WalletsAdd = () => {
<BlueSpacing20 />
<Text style={[styles.advancedText, stylesHook.advancedText]}>{loc.settings.advanced_options}</Text>
<BlueSpacing20 />
<BlueTextHooks>Connect to your LNDHub</BlueTextHooks>
<BlueText>Connect to your LNDHub</BlueText>
<View style={[styles.lndUri, stylesHook.lndUri]}>
<TextInput
value={walletBaseURI}

View file

@ -22,7 +22,7 @@ import {
BlueSpacing10,
BlueSpacing20,
BlueSpacing40,
BlueTextCenteredHooks,
BlueTextCentered,
} from '../../BlueComponents';
import { Icon } from 'react-native-elements';
import { HDSegwitBech32Wallet, MultisigCosigner, MultisigHDWallet } from '../../class';
@ -534,7 +534,7 @@ const WalletsAddMultisigStep2 = () => {
<BottomModal isVisible={isProvideMnemonicsModalVisible} onClose={hideProvideMnemonicsModal}>
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'position' : null}>
<View style={[styles.modalContent, stylesHook.modalContent]}>
<BlueTextCenteredHooks>{loc.multisig.type_your_mnemonics}</BlueTextCenteredHooks>
<BlueTextCentered>{loc.multisig.type_your_mnemonics}</BlueTextCentered>
<BlueSpacing20 />
<BlueFormMultiInput value={importText} onChangeText={setImportText} />
<BlueSpacing40 />

View file

@ -21,7 +21,7 @@ import {
BlueNavigationStyle,
BlueSpacing10,
BlueSpacing20,
BlueTextHooks,
BlueText,
} from '../../BlueComponents';
import { HodlHodlApi } from '../../class/hodl-hodl-api';
import * as NavigationService from '../../NavigationService';
@ -452,7 +452,7 @@ HodlHodlMyContracts.navigationOptions = ({ navigation }) => ({
);
}}
>
<BlueTextHooks>logout</BlueTextHooks>
<BlueText>logout</BlueText>
</TouchableOpacity>
),
});