Ask To Confirm Transaction - first draft

pull/1/head
ninabreznik 7 years ago
parent defb1c8f1f
commit 0c7e1844da
  1. 99
      src/app/execution/txRunner.js

@ -46,46 +46,52 @@ 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) { modalDialog('Confirm transaction', remixdDialog(tx),
callback(error, { { label: 'Confirm',
result: result, fn: () => {
transactionHash: result.transactionHash executionContext.web3().eth.call(tx, function (error, result) {
}) callback(error, {
}) result: result,
askToConfirmTx(tx) transactionHash: result.transactionHash
})
})
}})
} else { } else {
executionContext.web3().eth.estimateGas(tx, function (err, gasEstimation) { modalDialog('Confirm transaction', remixdDialog(tx),
if (err) { { label: 'Confirm',
return callback(err, gasEstimation) fn: () => {
} executionContext.web3().eth.estimateGas(tx, function (err, gasEstimation) {
var blockGasLimit = executionContext.currentblockGasLimit() if (err) {
// NOTE: estimateGas very likely will return a large limit if execution of the code failed return callback(err, gasEstimation)
// we want to be able to run the code in order to debug and find the cause for the failure }
var blockGasLimit = executionContext.currentblockGasLimit()
// NOTE: estimateGas very likely will return a large limit if execution of the code failed
// we want to be able to run the code in order to debug and find the cause for the failure
var warnEstimation = ' An important gas estimation might also be the sign of a problem in the contract code. Please check loops and be sure you did not sent value to a non payable function (that\'s also the reason of strong gas estimation).' var warnEstimation = ' An important gas estimation might also be the sign of a problem in the contract code. Please check loops and be sure you did not sent value to a non payable function (that\'s also the reason of strong gas estimation).'
if (gasEstimation > gasLimit) { if (gasEstimation > gasLimit) {
return callback('Gas required exceeds limit: ' + gasLimit + '. ' + warnEstimation) return callback('Gas required exceeds limit: ' + gasLimit + '. ' + warnEstimation)
} }
if (gasEstimation > blockGasLimit) { if (gasEstimation > blockGasLimit) {
return callback('Gas required exceeds block gas limit: ' + gasLimit + '. ' + warnEstimation) return callback('Gas required exceeds block gas limit: ' + gasLimit + '. ' + warnEstimation)
} }
tx.gas = gasEstimation tx.gas = gasEstimation
var sendTransaction = self.personalMode ? executionContext.web3().personal.sendTransaction : executionContext.web3().eth.sendTransaction var sendTransaction = self.personalMode ? executionContext.web3().personal.sendTransaction : executionContext.web3().eth.sendTransaction
try { try {
sendTransaction(tx, function (err, resp) { sendTransaction(tx, function (err, resp) {
if (err) { if (err) {
return callback(err, resp) return callback(err, resp)
} }
tryTillResponse(resp, callback) tryTillResponse(resp, callback)
}) })
} catch (e) { } catch (e) {
return callback(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `) return callback(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `)
} }
}) })
}})
} }
askToConfirmTx(tx)
} else { } else {
try { try {
var account = self.vmaccounts[from] var account = self.vmaccounts[from]
@ -168,27 +174,24 @@ function run (self, tx, stamp, callback) {
} }
} }
function askToConfirmTx (tx) {
var title = `Executing transaction on the main network` function remixdDialog (tx) {
var el = yo` return yo`
<div>
<div>You are trying to execute transaction on the main network. Please, click confirm to continue!</div>
<div> <div>
<div>
You are connected to the main network, which means your transaction will
be performed using real currency. Check out the details of the transaction you want
to run and click confirm if you are sure you want to continue with its
exectution on the main network.
</div>
<div>
<div>from: ${tx.from}</div> <div>from: ${tx.from}</div>
<div>to: ${tx.from}</div> <div>to: ${tx.from}</div>
<div>tx value: ${tx.value}</div> <div>tx value: ${tx.value}</div>
<div>gas limit: ${tx.gasLimit}</div> <div>gas limit: ${tx.gasLimit}</div>
<div>gas price: ${tx.gasEstimation}</div> <div>gas price: ${tx.gasEstimation}</div>
<div>data: ${tx.data}</div> <div>data: ${tx.data}</div>
</div>
</div> </div>
</div>
` `
modalDialog(title, el, {label: ''}, {label: 'Confirm'}) // PROMPT!
} }
module.exports = TxRunner module.exports = TxRunner

Loading…
Cancel
Save