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-07-06 16:40:58 +01:00
|
|
|
let currency = require('./currency');
|
2018-05-30 00:17:44 +01:00
|
|
|
let loc = require('./loc');
|
2019-01-10 15:04:16 +00:00
|
|
|
let A = require('./analytics');
|
2019-01-29 02:27:07 +00:00
|
|
|
let BlueElectrum = require('./BlueElectrum'); // eslint-disable-line
|
2018-01-30 22:42:38 +00:00
|
|
|
|
2018-03-31 01:03:58 +01:00
|
|
|
/** @type {AppStorage} */
|
2019-05-02 16:33:03 -04:00
|
|
|
const BlueApp = new AppStorage();
|
2018-03-31 01:03:58 +01:00
|
|
|
|
2018-03-31 14:43:08 +01:00
|
|
|
async function startAndDecrypt(retry) {
|
2018-12-31 16:20:49 +00:00
|
|
|
console.log('startAndDecrypt');
|
|
|
|
if (BlueApp.getWallets().length > 0) {
|
|
|
|
console.log('App already has some wallets, so we are in already started state, exiting startAndDecrypt');
|
|
|
|
return;
|
|
|
|
}
|
2018-03-31 01:03:58 +01:00
|
|
|
let password = false;
|
|
|
|
if (await BlueApp.storageIsEncrypted()) {
|
2018-04-01 00:16:42 +01:00
|
|
|
do {
|
2018-10-09 00:25:36 -04:00
|
|
|
password = await prompt((retry && loc._.bad_password) || loc._.enter_password, loc._.storage_is_encrypted, false);
|
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);
|
2018-07-02 14:51:24 +01:00
|
|
|
// now, lets try to fetch balance and txs for first wallet if it is time for it
|
2019-02-10 01:08:33 +00:00
|
|
|
/* let hadToRefresh = false;
|
2018-07-02 14:51:24 +01:00
|
|
|
let noErr = true;
|
|
|
|
try {
|
|
|
|
let wallets = BlueApp.getWallets();
|
2018-07-14 21:32:36 +01:00
|
|
|
if (wallets && wallets[0] && wallets[0].timeToRefreshBalance()) {
|
2018-07-02 14:51:24 +01:00
|
|
|
console.log('time to refresh wallet #0');
|
|
|
|
let oldBalance = wallets[0].getBalance();
|
|
|
|
await wallets[0].fetchBalance();
|
2018-09-01 01:09:45 +01:00
|
|
|
if (oldBalance !== wallets[0].getBalance() || wallets[0].getUnconfirmedBalance() !== 0 || wallets[0].timeToRefreshTransaction()) {
|
2018-07-02 14:51:24 +01:00
|
|
|
// balance changed, thus txs too
|
2018-09-01 01:09:45 +01:00
|
|
|
// or wallet thinks its time to reload TX list
|
2018-07-02 14:51:24 +01:00
|
|
|
await wallets[0].fetchTransactions();
|
|
|
|
hadToRefresh = true;
|
|
|
|
EV(EV.enum.WALLETS_COUNT_CHANGED);
|
|
|
|
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED);
|
2018-07-05 01:56:31 +01:00
|
|
|
} else {
|
|
|
|
console.log('balance not changed');
|
2018-07-02 14:51:24 +01:00
|
|
|
}
|
|
|
|
} // end of timeToRefresh
|
|
|
|
} catch (Err) {
|
|
|
|
noErr = false;
|
|
|
|
console.warn(Err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hadToRefresh && noErr) {
|
|
|
|
await BlueApp.saveToDisk(); // caching
|
2019-02-10 01:08:33 +00:00
|
|
|
} */
|
2018-03-31 01:03:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-01-10 15:04:16 +00:00
|
|
|
A(A.ENUM.INIT);
|
2018-12-11 22:52:46 +00:00
|
|
|
BlueApp.startAndDecrypt = startAndDecrypt;
|
2018-07-06 16:40:58 +01:00
|
|
|
currency.startUpdater();
|
2018-01-30 22:42:38 +00:00
|
|
|
|
2018-03-17 22:39:21 +02:00
|
|
|
module.exports = BlueApp;
|