From c0b525de8a54066d439dca4503c59ca3747dcfaa Mon Sep 17 00:00:00 2001 From: marcosrdz Date: Sun, 22 Nov 2020 03:04:04 -0500 Subject: [PATCH] REF: Plausible deniability uses Hooks --- BlueComponents.js | 23 +---- loc/en.json | 4 +- screen/plausibledeniability.js | 130 ++++++++++++------------ screen/send/ScanQRCode.js | 10 +- screen/settings/GeneralSettings.js | 6 +- screen/settings/SettingsPrivacy.js | 6 +- screen/settings/currency.js | 4 +- screen/settings/defaultView.js | 4 +- screen/settings/encryptStorage.js | 4 +- screen/settings/language.js | 4 +- screen/settings/licensing.js | 18 ++-- screen/settings/lightningSettings.js | 4 +- screen/settings/notificationSettings.js | 12 +-- screen/settings/releasenotes.js | 4 +- screen/wallets/add.js | 4 +- screen/wallets/addMultisigStep2.js | 4 +- screen/wallets/hodlHodlMyContracts.js | 4 +- 17 files changed, 112 insertions(+), 133 deletions(-) diff --git a/BlueComponents.js b/BlueComponents.js index 3d6d57306..fe91e8cff 100644 --- a/BlueComponents.js +++ b/BlueComponents.js @@ -736,21 +736,7 @@ export class BlueCard extends Component { } } -export class BlueText extends Component { - render() { - return ( - - ); - } -} - -export const BlueTextHooks = props => { +export const BlueText = props => { const { colors } = useTheme(); return ( { /> ); }; -export class BlueTextCentered extends Component { - render() { - return ; - } -} -export const BlueTextCenteredHooks = props => { +export const BlueTextCentered = props => { const { colors } = useTheme(); return ; }; diff --git a/loc/en.json b/loc/en.json index 298eabee8..163021465 100644 --- a/loc/en.json +++ b/loc/en.json @@ -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" diff --git a/screen/plausibledeniability.js b/screen/plausibledeniability.js index 5a9ca1ba8..6db5cbc73 100644 --- a/screen/plausibledeniability.js +++ b/screen/plausibledeniability.js @@ -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 ; + await createFakeStorage(p1); + await resetWallets(); + ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false }); + alert(loc.plausibledeniability.success); + popToTop(); + } catch { + setIsLoading(false); } + }; - return ( - - - - {loc.plausibledeniability.help} + return isLoading ? ( + + + + ) : ( + + + + {loc.plausibledeniability.help} - + - {loc.plausibledeniability.help2} + {loc.plausibledeniability.help2} - + - { - 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(); - }} - /> - - - - ); - } -} - -PlausibleDeniability.propTypes = { - navigation: PropTypes.shape({ - navigate: PropTypes.func, - popToTop: PropTypes.func, - }), + + + + + ); }; -PlausibleDeniability.navigationOptions = ({ navigation, route }) => ({ +export default PlausibleDeniability; + +PlausibleDeniability.navigationOptions = () => ({ ...BlueNavigationStyle(), title: loc.plausibledeniability.title, }); diff --git a/screen/send/ScanQRCode.js b/screen/send/ScanQRCode.js index d6e01522f..89c5fb1de 100644 --- a/screen/send/ScanQRCode.js +++ b/screen/send/ScanQRCode.js @@ -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 && ( - {loc.send.permission_camera_message} + {loc.send.permission_camera_message} @@ -271,15 +271,15 @@ const ScanQRCode = () => { )} {urTotal > 0 && ( - + {urHave} / {urTotal} - + )} {backdoorVisible && ( - Provide QR code contents manually: + Provide QR code contents manually: { switch={{ onValueChange: onHandOffEnabledSwitch, value: isHandoffUseEnabled }} /> - {loc.settings.general_continuity_e} + {loc.settings.general_continuity_e} @@ -81,7 +81,7 @@ const GeneralSettings = () => { switch={{ onValueChange: onAdvancedModeSwitch, value: isAdancedModeSwitchEnabled }} /> - {loc.settings.general_adv_mode_e} + {loc.settings.general_adv_mode_e} diff --git a/screen/settings/SettingsPrivacy.js b/screen/settings/SettingsPrivacy.js index 807245a85..3e77df4f8 100644 --- a/screen/settings/SettingsPrivacy.js +++ b/screen/settings/SettingsPrivacy.js @@ -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 }} /> - {loc.settings.privacy_clipboard_explanation} + {loc.settings.privacy_clipboard_explanation} {!storageIsEncrypted && ( @@ -83,7 +83,7 @@ const SettingsPrivacy = () => { switch={{ onValueChange: onQuickActionsValueChange, value: isQuickActionsEnabled, disabled: isLoading === sections.ALL }} /> - {loc.settings.privacy_quickactions_explanation} + {loc.settings.privacy_quickactions_explanation} )} diff --git a/screen/settings/currency.js b/screen/settings/currency.js index b84d02f87..cdb51736a 100644 --- a/screen/settings/currency.js +++ b/screen/settings/currency.js @@ -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 = () => { }} /> - {loc.settings.currency_source} + {loc.settings.currency_source} ); diff --git a/screen/settings/defaultView.js b/screen/settings/defaultView.js index 4a7916bc7..e94eee341 100644 --- a/screen/settings/defaultView.js +++ b/screen/settings/defaultView.js @@ -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 = () => { }} /> - {loc.settings.default_desc} + {loc.settings.default_desc} {!viewAllWalletsEnabled && ( diff --git a/screen/settings/encryptStorage.js b/screen/settings/encryptStorage.js index 0108980fb..d7f2a2c1b 100644 --- a/screen/settings/encryptStorage.js +++ b/screen/settings/encryptStorage.js @@ -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 }} /> - {loc.formatString(loc.settings.encrypt_use_expl, { type: biometrics.biometricsType })} + {loc.formatString(loc.settings.encrypt_use_expl, { type: biometrics.biometricsType })} diff --git a/screen/settings/language.js b/screen/settings/language.js index c9dab5c04..9558e5d2f 100644 --- a/screen/settings/language.js +++ b/screen/settings/language.js @@ -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 = () => { `${index}`} data={AvailableLanguages} renderItem={renderItem} /> - {loc.settings.language_restart} + {loc.settings.language_restart} ); diff --git a/screen/settings/licensing.js b/screen/settings/licensing.js index bd6dc5053..d1fd9753c 100644 --- a/screen/settings/licensing.js +++ b/screen/settings/licensing.js @@ -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 = () => { - MIT License + MIT License - Copyright (c) 2018-2020 BlueWallet Services + Copyright (c) 2018-2020 BlueWallet Services - + 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: - + - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + - + 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. - + diff --git a/screen/settings/lightningSettings.js b/screen/settings/lightningSettings.js index f73ce8647..d64614704 100644 --- a/screen/settings/lightningSettings.js +++ b/screen/settings/lightningSettings.js @@ -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 ( - {loc.settings.lightning_settings_explain} + {loc.settings.lightning_settings_explain}