Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

Commit

Permalink
fixHighLvlTryCatch (#206)
Browse files Browse the repository at this point in the history
* fixHighLvlTryCatch
* upversion to 1.4.6
* remove version number from package.json bc we are setting version in manifest.json
  • Loading branch information
soshochang committed Nov 14, 2018
1 parent ffe38e7 commit 37706d0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "qrypto",
"version": "1.4.2-beta",
"private": true,
"scripts": {
"clean": "rm -rf dist",
Expand Down
12 changes: 8 additions & 4 deletions src/background/controllers/accountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,23 +436,27 @@ export default class AccountController extends IController {
});
}

private handleMessage = (request: any, _: chrome.runtime.MessageSender, sendResponse: (response: any) => void) => {
private handleMessage = async (
request: any,
_: chrome.runtime.MessageSender,
sendResponse: (response: any) => void,
) => {
try {
switch (request.type) {
case MESSAGE_TYPE.LOGIN:
this.login(request.password);
break;
case MESSAGE_TYPE.IMPORT_MNEMONIC:
this.importMnemonic(request.accountName, request.mnemonicPrivateKey);
await this.importMnemonic(request.accountName, request.mnemonicPrivateKey);
break;
case MESSAGE_TYPE.IMPORT_PRIVATE_KEY:
this.importPrivateKey(request.accountName, request.mnemonicPrivateKey);
await this.importPrivateKey(request.accountName, request.mnemonicPrivateKey);
break;
case MESSAGE_TYPE.SAVE_TO_FILE:
this.saveToFile(request.accountName, request.mnemonicPrivateKey);
break;
case MESSAGE_TYPE.ACCOUNT_LOGIN:
this.loginAccount(request.selectedWalletName);
await this.loginAccount(request.selectedWalletName);
break;
case MESSAGE_TYPE.SEND_TOKENS:
this.sendTokens(request.receiverAddress, request.amount, request.transactionSpeed);
Expand Down
31 changes: 26 additions & 5 deletions src/models/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,33 @@ export default class Wallet implements ISigner {
if (!this.qjsWallet) {
console.error('Cannot updateInfo without qjsWallet instance.');
}
const newInfo = await this.qjsWallet!.getInfo();

// if they are not equal, then the balance has changed
if (!deepEqual(this.info, newInfo)) {
this.info = newInfo;
return true;
/**
* We add a timeout promise to handle if qjsWallet hangs when executing getInfo.
* (This happens if the insight api is down)
*/
let timedOut = false;
const timeoutPromise = new Promise((_, reject) => {
const wait = setTimeout(() => {
clearTimeout(wait);
timedOut = true;
reject(Error('wallet.getInfo failed, insight api may be down'));
}, 30000);
});

const getInfoPromise = this.qjsWallet!.getInfo();
const promises = [timeoutPromise, getInfoPromise];
let newInfo: any;
try {
newInfo = await Promise.race(promises);

// if they are not equal, then the balance has changed
if (!timedOut && !deepEqual(this.info, newInfo)) {
this.info = newInfo;
return true;
}
} catch (e) {
throw(Error(e));
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Qrypto",
"description": "Qtum light wallet and transaction signing client.",
"version": "1.4.5",
"version": "1.4.6",
"manifest_version": 2,
"icons": {
"16": "images/logo-main-16.png",
Expand Down

0 comments on commit 37706d0

Please sign in to comment.