From daf41954da3fc06c2fb286c7197590fab4150051 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 23 May 2019 14:42:40 -0400 Subject: [PATCH] fix displaying menu when tx is still ongoing --- src/actions.js | 8 ++++---- src/provider.js | 1 - src/trx-utils.js | 27 +++++++++++++++------------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/actions.js b/src/actions.js index 59ea00d..45b56f8 100644 --- a/src/actions.js +++ b/src/actions.js @@ -39,15 +39,15 @@ class Actions { connect(url, cb) { console.dir("connecting to: " + url); - this.provider = new Provider(); + this.provider = new Provider(); const accounts = [{mnemonic: ""}] - this.provider.initAccounts(accounts); - this.provider.startWeb3Provider("ws", url) + this.provider.initAccounts(accounts); + this.provider.startWeb3Provider("ws", url) //web3.setProvider(url); setTimeout(async () => { - this.web3 = this.provider.web3; + this.web3 = this.provider.web3; let accounts = await this.web3.eth.getAccounts(); console.dir("== accounts"); diff --git a/src/provider.js b/src/provider.js index 6817e7d..b947645 100644 --- a/src/provider.js +++ b/src/provider.js @@ -30,7 +30,6 @@ class Provider { //} else { this.accounts.push(this.web3.eth.accounts.privateKeyToAccount('0x' + wallet.getPrivateKey().toString('hex'))); //} - } } } diff --git a/src/trx-utils.js b/src/trx-utils.js index f337d00..c439224 100644 --- a/src/trx-utils.js +++ b/src/trx-utils.js @@ -1,20 +1,23 @@ const Spinner = require('cli-spinner').Spinner; const executeAndWait = async (toSend, account) => { - const spinner = new Spinner('%s'); - spinner.setSpinnerString(18); - spinner.start(); + return new Promise(async (resolve, reject) => { + const spinner = new Spinner('%s'); + spinner.setSpinnerString(18); + spinner.start(); - try { - const estimatedGas = await toSend.estimateGas({from: account}); - const receipt = await toSend.send({from: account, gas: estimatedGas + 10000}); + try { + const estimatedGas = await toSend.estimateGas({from: account}); + const receipt = await toSend.send({from: account, gas: estimatedGas + 10000}); - spinner.stop(true); - return receipt; - } catch(error) { - console.log("Error: ", error.message); - spinner.stop(true); - } + spinner.stop(true); + return resolve(receipt); + } catch(error) { + console.log("Error: ", error.message); + spinner.stop(true); + } + resolve(); + }); } module.exports = {