1
0
Fork 0
mirror of https://github.com/BlueWallet/BlueWallet.git synced 2025-03-16 20:21:35 +01:00
BlueWallet/BlueApp.js

38 lines
875 B
JavaScript
Raw Normal View History

2018-01-30 22:42:38 +00:00
/**
* @exports {AppStorage}
*/
2018-03-17 22:39:21 +02:00
import { AppStorage } from './class';
2018-03-31 01:03:58 +01:00
let prompt = require('./prompt');
2018-03-17 22:39:21 +02:00
let EV = require('./events');
2018-05-30 00:17:44 +01:00
let loc = require('./loc');
2018-01-30 22:42:38 +00:00
2018-03-31 01:03:58 +01:00
/** @type {AppStorage} */
2018-03-17 22:39:21 +02:00
let BlueApp = new AppStorage();
2018-03-31 01:03:58 +01:00
2018-03-31 14:43:08 +01:00
async function startAndDecrypt(retry) {
2018-03-31 01:03:58 +01:00
let password = false;
if (await BlueApp.storageIsEncrypted()) {
2018-04-01 00:16:42 +01:00
do {
password = await prompt(
2018-05-30 00:17:44 +01:00
(retry && loc._.bad_password) || loc._.enter_password,
loc._.storage_is_encrypted,
2018-04-01 00:16:42 +01:00
);
} while (!password);
2018-03-31 01:03:58 +01:00
}
let success = await BlueApp.loadFromDisk(password);
if (success) {
console.log('loaded from disk');
EV(EV.enum.WALLETS_COUNT_CHANGED);
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED);
}
if (!success && password) {
// we had password and yet could not load/decrypt
2018-04-01 00:16:42 +01:00
return startAndDecrypt(true);
2018-03-31 01:03:58 +01:00
}
2018-03-31 14:43:08 +01:00
}
startAndDecrypt();
2018-01-30 22:42:38 +00:00
2018-03-17 22:39:21 +02:00
module.exports = BlueApp;