diff --git a/src/app/execution/confirmDialog.js b/src/app/execution/confirmDialog.js index c05f8ff150..60654b8092 100644 --- a/src/app/execution/confirmDialog.js +++ b/src/app/execution/confirmDialog.js @@ -1,5 +1,3 @@ -var executionContext = require('../../execution-context') -var typeConversion = require('../../lib/typeConversion') var yo = require('yo-yo') var csjs = require('csjs-inject') var remixLib = require('remix-lib') @@ -19,9 +17,15 @@ var css = csjs` } ` -function confirmDialog (tx, gasEstimation, self) { - var amount = executionContext.web3().fromWei(typeConversion.toInt(tx.value), 'ether') - var input = yo`` +function confirmDialog (tx, amount, gasEstimation, self, newGasPriceCb, initialParamsCb) { + var onGasPriceChange = function () { + var gasPrice = el.querySelector('#gasprice').value + newGasPriceCb(gasPrice, (priceStatus, txFeeText) => { + el.querySelector('#txfee').innerHTML = txFeeText + el.gasPriceStatus = priceStatus + }) + } + var el = yo`
You are creating a transaction on the main network. Click confirm if you are sure to continue.
@@ -31,44 +35,31 @@ function confirmDialog (tx, gasEstimation, self) {
Amount: ${amount} Ether
Gas estimation: ${gasEstimation}
Gas limit: ${tx.gas}
-
Gas price: Gwei (visit ethgasstation.info to get more info about gas price)
+
Gas price: Gwei (visit ethgasstation.info to get more info about gas price)
Max transaction fee:
Data:
${tx.data}
- ${input} + Do not ask for confirmation again. (the setting will not be persisted for the next page reload)
` - var warnMessage = ' Please fix this issue before sending any transaction. ' - function gasPriceChanged () { - try { - var gasPrice = el.querySelector('#gasprice').value - var fee = executionContext.web3().toBigNumber(tx.gas).mul(executionContext.web3().toBigNumber(executionContext.web3().toWei(gasPrice.toString(10), 'gwei'))) - el.querySelector('#txfee').innerHTML = ' ' + executionContext.web3().fromWei(fee.toString(10), 'ether') + ' Ether' - el.gasPriceStatus = true - } catch (e) { - el.querySelector('#txfee').innerHTML = warnMessage + e.message - el.gasPriceStatus = false + initialParamsCb((txFeeText, gasPriceValue, gasPriceStatus) => { + if (txFeeText) { + el.querySelector('#txfee').innerHTML = txFeeText } - } - - executionContext.web3().eth.getGasPrice((error, gasPrice) => { - if (error) { - el.querySelector('#txfee').innerHTML = 'Unable to retrieve the current network gas price.' + warnMessage + error - } else { - try { - el.querySelector('#gasprice').value = executionContext.web3().fromWei(gasPrice.toString(10), 'gwei') - gasPriceChanged() - } catch (e) { - el.querySelector('#txfee').innerHTML = warnMessage + e.message - el.gasPriceStatus = false - } + if (gasPriceValue) { + el.querySelector('#gasprice').value = gasPriceValue + onGasPriceChange() + } + if (gasPriceStatus !== undefined) { + el.gasPriceStatus = gasPriceStatus } }) + return el } diff --git a/src/app/execution/txRunner.js b/src/app/execution/txRunner.js index 9729c4c201..b6ec966aa2 100644 --- a/src/app/execution/txRunner.js +++ b/src/app/execution/txRunner.js @@ -6,6 +6,7 @@ var BN = ethJSUtil.BN var executionContext = require('../../execution-context') var modalDialog = require('../ui/modaldialog') var modal = require('../ui/modal-dialog-custom') +var typeConversion = require('../../lib/typeConversion') var confirmDialog = require('./confirmDialog') @@ -149,7 +150,39 @@ TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCal if (network.name !== 'Main') { return executeTx(tx, null, self._api, callback) } - var content = confirmDialog(tx, gasEstimation, self) + + var amount = executionContext.web3().fromWei(typeConversion.toInt(tx.value), 'ether') + var content = confirmDialog(tx, amount, gasEstimation, self, + (gasPrice, cb) => { + let txFeeText, priceStatus + // TODO: this try catch feels like an anti pattern, can/should be + // removed, but for now keeping the original logic + try { + var fee = executionContext.web3().toBigNumber(tx.gas).mul(executionContext.web3().toBigNumber(executionContext.web3().toWei(gasPrice.toString(10), 'gwei'))) + txFeeText = ' ' + executionContext.web3().fromWei(fee.toString(10), 'ether') + ' Ether' + priceStatus = true + } catch (e) { + txFeeText = ' Please fix this issue before sending any transaction. ' + e.message + priceStatus = false + } + cb(txFeeText, priceStatus) + }, + (cb) => { + executionContext.web3().eth.getGasPrice((error, gasPrice) => { + var warnMessage = ' Please fix this issue before sending any transaction. ' + if (error) { + return cb('Unable to retrieve the current network gas price.' + warnMessage + error) + } + try { + var gasPriceValue = executionContext.web3().fromWei(gasPrice.toString(10), 'gwei') + cb(null, gasPriceValue) + } catch (e) { + cb(warnMessage + e.message, null, false) + } + }) + } + ) + modalDialog('Confirm transaction', content, { label: 'Confirm', fn: () => {