add gas estimation, use unpersisted property

pull/1/head
yann300 7 years ago
parent 3285767cdc
commit 92e955c53e
  1. 50
      src/app/execution/txRunner.js

@ -5,7 +5,6 @@ var ethJSUtil = require('ethereumjs-util')
var BN = ethJSUtil.BN var BN = ethJSUtil.BN
var executionContext = require('../../execution-context') var executionContext = require('../../execution-context')
var modalDialog = require('../ui/modaldialog') var modalDialog = require('../ui/modaldialog')
var helper = require('../../lib/helper')
var yo = require('yo-yo') var yo = require('yo-yo')
var csjs = require('csjs-inject') var csjs = require('csjs-inject')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
@ -16,9 +15,12 @@ var css = csjs`
.txInfoBox { .txInfoBox {
${styles.rightPanel.compileTab.box_CompileContainer}; // add askToConfirmTXContainer to Remix and then replace this styling ${styles.rightPanel.compileTab.box_CompileContainer}; // add askToConfirmTXContainer to Remix and then replace this styling
} }
.checkbox { .wrapword {
display: flex; white-space: pre-wrap; /* Since CSS 2.1 */
margin: 1em 0; white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
} }
` `
@ -63,12 +65,12 @@ TxRunner.prototype.execute = function (args, callback) {
if (args.useCall) { if (args.useCall) {
tx.gas = gasLimit tx.gas = gasLimit
executionContext.web3().eth.call(tx, function (error, result) { executionContext.web3().eth.call(tx, function (error, result) {
callback(error, { callback(error, {
result: result, result: result,
transactionHash: result.transactionHash transactionHash: result.transactionHash
})
}) })
})
} else { } else {
function execute () { function execute () {
var sendTransaction = self.personalMode ? executionContext.web3().personal.sendTransaction : executionContext.web3().eth.sendTransaction var sendTransaction = self.personalMode ? executionContext.web3().personal.sendTransaction : executionContext.web3().eth.sendTransaction
@ -102,13 +104,13 @@ TxRunner.prototype.execute = function (args, callback) {
tx.gas = gasEstimation tx.gas = gasEstimation
if (!self.config.get('doNotShowAgain')) { if (!self.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) {
self.detectNetwork((err, network) => { self.detectNetwork((err, network) => {
if (err) { if (err) {
console.log(err) console.log(err)
} else { } else {
if (network.name === 'Main') { if (network.name === 'Main') {
modalDialog('Confirm transaction', remixdDialog(tx, self), modalDialog('Confirm transaction', remixdDialog(tx, gasEstimation, self),
{ label: 'Confirm', { label: 'Confirm',
fn: () => { fn: () => {
execute() execute()
@ -210,28 +212,26 @@ function run (self, tx, stamp, callback) {
} }
} }
function remixdDialog (tx, self) { function remixdDialog (tx, gasEstimation, self) {
var input = yo`<input type="checkbox" onchange=${() => { self.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', this.checked) }}>`
return yo` return yo`
<div> <div>
<div>You are trying to execute transaction on the main network. Click confirm if you want to continue!</div> <div>You are creating a transaction on the main network. Click confirm if you are sure to continue.</div>
<div class=${css.txInfoBox}> <div class=${css.txInfoBox}>
<div>from: ${tx.from}</div> <div>From: ${tx.from}</div>
<div>to: ${tx.from}</div> <div>To: ${tx.to ? tx.to : '(Contract Creation)'}</div>
<div>tx value: ${tx.value}</div> <div>Amount: ${tx.value}</div>
<div>gas limit: ${tx.gas}</div> <div>Gas estimation: ${gasEstimation}</div>
<div>data: ${helper.shortenHexData(tx.data)}</div> <div>Gas limit: ${tx.gas}</div>
<div>Data:</div>
<pre class=${css.wrapword}>${tx.data}</pre>
</div> </div>
<div class=${css.checkbox}> <div class=${css.checkbox}>
<div><input type="checkbox" onchange=${() => updateConfig(self)}></div> ${input}
<span class="${css.checkboxText}">Don't ask me to confirm again</span> <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Do not ask for confirmation again. (the setting will not be persisted for the next page reload)
</div> </div>
</div> </div>
` `
} }
function updateConfig (self) {
self.config.set('doNotShowAgain', !self.config.get('doNotShowAgain'))
document.querySelector('#askToConfirm').setAttribute('checked', true)
}
module.exports = TxRunner module.exports = TxRunner

Loading…
Cancel
Save