1
0
Fork 0
mirror of https://github.com/BlueWallet/BlueWallet.git synced 2025-03-26 08:55:56 +01:00

REF: load from disk

This commit is contained in:
Overtorment 2021-02-12 23:38:29 +00:00
parent 6c47651d63
commit ade43b3eb2
2 changed files with 112 additions and 132 deletions

View file

@ -21,42 +21,32 @@ const startAndDecrypt = async retry => {
password = await prompt((retry && loc._.bad_password) || loc._.enter_password, loc._.storage_is_encrypted, false);
} while (!password);
}
const success = await BlueApp.loadFromDisk(password);
if (success) {
console.log('loaded from disk');
// now, lets try to fetch balance and txs for first wallet if it is time for it
/* let hadToRefresh = false;
let noErr = true;
let success = false;
let wasException = false;
try {
let wallets = BlueApp.getWallets();
if (wallets && wallets[0] && wallets[0].timeToRefreshBalance()) {
console.log('time to refresh wallet #0');
let oldBalance = wallets[0].getBalance();
await wallets[0].fetchBalance();
if (oldBalance !== wallets[0].getBalance() || wallets[0].getUnconfirmedBalance() !== 0 || wallets[0].timeToRefreshTransaction()) {
// balance changed, thus txs too
// or wallet thinks its time to reload TX list
await wallets[0].fetchTransactions();
hadToRefresh = true;
EV(EV.enum.WALLETS_COUNT_CHANGED);
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED);
} else {
console.log('balance not changed');
}
} // end of timeToRefresh
} catch (Err) {
noErr = false;
console.warn(Err);
success = await BlueApp.loadFromDisk(password);
} catch (error) {
// in case of exception reading from keystore, lets retry instead of assuming there is no storage and
// proceeding with no wallets
console.warn(error);
wasException = true;
}
if (hadToRefresh && noErr) {
await BlueApp.saveToDisk(); // caching
} */
if (wasException) {
// retrying, but only once
try {
await new Promise(resolve => setTimeout(resolve, 3000)); // sleep
success = await BlueApp.loadFromDisk(password);
} catch (_) {}
}
if (success) {
console.log('loaded from disk');
// We want to return true to let the UnlockWith screen that its ok to proceed.
return true;
}
if (!success && password) {
if (password) {
// we had password and yet could not load/decrypt
unlockAttempt++;
if (unlockAttempt < 10 || Platform.OS !== 'ios') {

View file

@ -76,7 +76,6 @@ export class AppStorage {
}
};
storageIsEncrypted = async () => {
let data;
try {
@ -111,11 +110,7 @@ export class AppStorage {
let decrypted;
let num = 0;
for (const value of data) {
try {
decrypted = encryption.decrypt(value, password);
} catch (e) {
console.log(e.message);
}
if (decrypted) {
usedBucketNum = num;
@ -221,7 +216,6 @@ export class AppStorage {
* @returns {Promise.<boolean>}
*/
async loadFromDisk(password) {
try {
let data = await this.getItem('data');
if (password) {
data = this.decryptData(data, password);
@ -321,10 +315,6 @@ export class AppStorage {
} else {
return false; // failed loading data or loading/decryptin data
}
} catch (error) {
console.warn(error.message);
return false;
}
}
/**