forked from BlueWallet/BlueWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlueApp.js
36 lines (31 loc) · 886 Bytes
/
BlueApp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* @exports {AppStorage}
*/
import { AppStorage } from './class';
let prompt = require('./prompt');
let EV = require('./events');
/** @type {AppStorage} */
let BlueApp = new AppStorage();
async function startAndDecrypt(retry) {
let password = false;
if (await BlueApp.storageIsEncrypted()) {
do {
password = await prompt(
(retry && 'Bad pasword, try again') || 'Enter password',
'Your storage is encrypted. Password is required to decrypt it',
);
} while (!password);
}
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
return startAndDecrypt(true);
}
}
startAndDecrypt();
module.exports = BlueApp;