Browse Source

FIX: Current storage will be the selected one for decrypt

settingsui
Marcos Rodriguez 5 years ago
parent
commit
38048b2068
  1. 38
      class/app-storage.js
  2. 2
      screen/settings/encryptStorage.js

38
class/app-storage.js

@ -143,32 +143,16 @@ export class AppStorage {
} }
async decryptStorage(password) { async decryptStorage(password) {
try { if (password === this.cachedPassword) {
let storage = await this.getItem('data'); this.cachedPassword = undefined;
if (password) { await this.setItem(AppStorage.FLAG_ENCRYPTED, '');
let parsedStorage = JSON.parse(storage); await this.setItem('deleteWalletAfterUninstall', '1');
let mainStorage = parsedStorage[0]; await this.saveToDisk();
mainStorage = JSON.stringify([mainStorage]); this.wallets = [];
const decrypted = this.decryptData(mainStorage, password); this.tx_metadata = [];
if (!decrypted) { return this.loadFromDisk();
throw new Error('Wrong password for main storage.'); } else {
} throw new Error('Wrong password. Please, try again.');
const decryptedParsed = JSON.parse(decrypted);
if (decrypted.wallets !== null) {
this.wallets = decryptedParsed.wallets;
this.tx_metadata = decryptedParsed.tx_metadata;
this.cachedPassword = undefined;
await this.setItem(AppStorage.FLAG_ENCRYPTED, '', { accessible: ACCESSIBLE.WHEN_UNLOCKED });
await this.setItem('deleteWalletAfterUninstall', '1', { accessible: ACCESSIBLE.WHEN_UNLOCKED });
await this.saveToDisk();
this.wallets = [];
this.tx_metadata = [];
return this.loadFromDisk();
}
}
} catch (e) {
console.log(e);
throw new Error(e);
} }
} }
@ -514,4 +498,4 @@ export class AppStorage {
async sleep(ms) { async sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms));
} }
} }

2
screen/settings/encryptStorage.js

@ -102,7 +102,7 @@ export default class EncryptStorage extends Component {
} else { } else {
Alert.alert( Alert.alert(
'Decrypt Storage', 'Decrypt Storage',
'Are you sure you want to decrypt your storage? This will allow your wallets to be accessed without a password, and remove your plausible deniability wallets.', 'Are you sure you want to decrypt your storage? This will allow your wallets to be accessed without a password.',
[ [
{ {
text: loc.send.details.cancel, text: loc.send.details.cancel,

Loading…
Cancel
Save