FIX: Decouple RNSecureKeyStore from encryptStorage component.

This commit is contained in:
Marcos Rodriguez 2019-09-14 00:34:24 -04:00
parent 78a6f1f525
commit 865e7dbe40
5 changed files with 27 additions and 23 deletions

View file

@ -522,6 +522,7 @@ export class BlueListItem extends Component {
}}
subtitleStyle={{ color: BlueApp.settings.alternativeTextColor }}
subtitleNumberOfLines={1}
titleNumberOfLines={0}
{...this.props}
/>
);

View file

@ -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.<AbstractWallet>} */
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();

View file

@ -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

View file

@ -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

View file

@ -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,10 +44,9 @@ 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 });
@ -65,14 +54,13 @@ export default class EncryptStorage extends Component {
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 });
};