From 865e7dbe40fefdc60e878c5c5e5bebbe8bac25ac Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Date: Sat, 14 Sep 2019 00:34:24 -0400 Subject: [PATCH] FIX: Decouple RNSecureKeyStore from encryptStorage component. --- BlueComponents.js | 1 + class/app-storage.js | 17 ++++++++++++++++- ios/Podfile | 4 ++-- ios/Podfile.lock | 4 ++-- screen/settings/encryptStorage.js | 24 ++++++------------------ 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/BlueComponents.js b/BlueComponents.js index f75f9e7f0..8e540f3a4 100644 --- a/BlueComponents.js +++ b/BlueComponents.js @@ -522,6 +522,7 @@ export class BlueListItem extends Component { }} subtitleStyle={{ color: BlueApp.settings.alternativeTextColor }} subtitleNumberOfLines={1} + titleNumberOfLines={0} {...this.props} /> ); diff --git a/class/app-storage.js b/class/app-storage.js index cacad2bad..235b6fe73 100644 --- a/class/app-storage.js +++ b/class/app-storage.js @@ -23,7 +23,7 @@ export class AppStorage { static ELECTRUM_TCP_PORT = 'electrum_tcp_port'; static PREFERRED_CURRENCY = 'preferredCurrency'; static ADVANCED_MODE_ENABLED = 'advancedmodeenabled'; - + static DELETEWALLETAFTERUNINSTALLKEY = 'deleteWalletAfterUninstall'; constructor() { /** {Array.} */ this.wallets = []; @@ -88,6 +88,11 @@ export class AppStorage { } } + async setResetOnAppUninstallTo(value) { + await this.setItem('deleteWalletAfterUninstall', value === true ? '1' : ''); + await RNSecureKeyStore.setResetOnAppUninstallTo(value); + } + async storageIsEncrypted() { let data; try { @@ -164,6 +169,16 @@ export class AppStorage { } } + async isDeleteWalletAfterUninstallEnabled() { + let deleteWalletsAfterUninstall; + try { + deleteWalletsAfterUninstall = await this.getItem('deleteWalletAfterUninstall'); + } catch (_e) { + deleteWalletsAfterUninstall = true; + } + return !!deleteWalletsAfterUninstall; + } + async encryptStorage(password) { // assuming the storage is not yet encrypted await this.saveToDisk(); diff --git a/ios/Podfile b/ios/Podfile index cffa2a968..dd697b8cd 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -14,7 +14,7 @@ end def sharedPods - pod 'React', :path => '../node_modules/react-native/' + pod 'React', :path => '../node_modules/react-native/' pod 'React-Core', :path => '../node_modules/react-native/React' pod 'React-DevSupport', :path => '../node_modules/react-native/React' pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS' @@ -72,7 +72,7 @@ target 'BlueWalletWatch Extension' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks # use_frameworks! platform :watchos, '5.1' - pod 'EFQRCode', '~> 5.0.0' + pod 'EFQRCode', '5.0.0' # Pods for BlueWalletWatch Extension end diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 1bc1c99c4..b6fa67ecf 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -21,7 +21,7 @@ PODS: - BVLinearGradient (2.5.4): - React - DoubleConversion (1.1.6) - - EFQRCode (5.0.0): + - EFQRCode (5.0.1): - swift_qrcodejs (~> 1.1.1) - Folly (2018.10.22.00): - boost-for-react-native @@ -317,7 +317,7 @@ SPEC CHECKSUMS: boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c BVLinearGradient: 8cbc5155c978f2e43098818c91d206d07aae6d30 DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2 - EFQRCode: 07437cfbce3a1e497397a4f3d766c980d8972608 + EFQRCode: 239efec4dd406d9c635dd937525fc40960ce2e9f Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51 glog: 1f3da668190260b06b429bb211bfbee5cd790c28 RCTSystemSetting: 9279ff44c49bb4fb0a5d335a0851852c8f3eda99 diff --git a/screen/settings/encryptStorage.js b/screen/settings/encryptStorage.js index f68d4248a..205d73527 100644 --- a/screen/settings/encryptStorage.js +++ b/screen/settings/encryptStorage.js @@ -3,7 +3,6 @@ import React, { Component } from 'react'; import { View, Alert, Platform, TouchableOpacity } from 'react-native'; import { BlueLoading, BlueHeaderDefaultSub, BlueListItem, SafeBlueArea, BlueNavigationStyle } from '../../BlueComponents'; import PropTypes from 'prop-types'; -import RNSecureKeyStore, { ACCESSIBLE } from 'react-native-secure-key-store'; import AsyncStorage from '@react-native-community/async-storage'; import { AppStorage } from '../../class'; import ReactNativeHapticFeedback from 'react-native-haptic-feedback'; @@ -18,30 +17,21 @@ export default class EncryptStorage extends Component { title: loc.settings.security, }); - static deleteWalletAfterUninstall = 'deleteWalletAfterUninstall'; - constructor(props) { super(props); this.state = { isLoading: true, language: loc.getLanguage(), + deleteWalletsAfterUninstall: false, }; } async componentDidMount() { - let deleteWalletsAfterUninstall = true; - try { - deleteWalletsAfterUninstall = await RNSecureKeyStore.get(EncryptStorage.deleteWalletAfterUninstall); - deleteWalletsAfterUninstall = - deleteWalletsAfterUninstall === true || deleteWalletsAfterUninstall === '1' || deleteWalletsAfterUninstall === 1; - } catch (_e) { - deleteWalletsAfterUninstall = true; - } this.setState({ isLoading: false, advancedModeEnabled: (await AsyncStorage.getItem(AppStorage.ADVANCED_MODE_ENABLED)) || false, storageIsEncrypted: await BlueApp.storageIsEncrypted(), - deleteWalletsAfterUninstall, + deleteWalletsAfterUninstall: await BlueApp.isDeleteWalletAfterUninstallEnabled(), }); } @@ -54,25 +44,23 @@ export default class EncryptStorage extends Component { this.setState({ isLoading: false, storageIsEncrypted: await BlueApp.storageIsEncrypted(), - deleteWalletAfterUninstall: await RNSecureKeyStore.get(EncryptStorage.deleteWalletAfterUninstall), + deleteWalletAfterUninstall: await BlueApp.isDeleteWalletAfterUninstallEnabled(), }); } catch (e) { - console.log(e); if (password) { alert(loc._.bad_password); - ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false }); + ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false }); } this.setState({ isLoading: false, storageIsEncrypted: await BlueApp.storageIsEncrypted(), - deleteWalletAfterUninstall: await RNSecureKeyStore.get(EncryptStorage.deleteWalletAfterUninstall), + deleteWalletAfterUninstall: await BlueApp.isDeleteWalletAfterUninstallEnabled(), }); } }; onDeleteWalletsAfterUninstallSwitch = async value => { - await RNSecureKeyStore.setResetOnAppUninstallTo(value); - await RNSecureKeyStore.set(EncryptStorage.deleteWalletAfterUninstall, value, { accessible: ACCESSIBLE.WHEN_UNLOCKED }); + await BlueApp.setResetOnAppUninstallTo(value); this.setState({ deleteWalletsAfterUninstall: value }); };