Unverified Commit 06b70683 authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #1149 from ethereum/extract_tx_runner

extract modal dialog from txRunner
parents 84d81001 8c7f3db8
...@@ -4,7 +4,6 @@ var EthJSBlock = require('ethereumjs-block') ...@@ -4,7 +4,6 @@ var EthJSBlock = require('ethereumjs-block')
var ethJSUtil = require('ethereumjs-util') var ethJSUtil = require('ethereumjs-util')
var BN = ethJSUtil.BN var BN = ethJSUtil.BN
var executionContext = require('../../execution-context') var executionContext = require('../../execution-context')
var modal = require('../ui/modal-dialog-custom')
function TxRunner (vmaccounts, api) { function TxRunner (vmaccounts, api) {
this._api = api this._api = api
...@@ -19,25 +18,27 @@ function TxRunner (vmaccounts, api) { ...@@ -19,25 +18,27 @@ function TxRunner (vmaccounts, api) {
this.queusTxs = [] this.queusTxs = []
} }
TxRunner.prototype.rawRun = function (args, confirmationCb, gasEstimationForceSend, cb) { TxRunner.prototype.rawRun = function (args, confirmationCb, gasEstimationForceSend, promptCb, cb) {
run(this, args, Date.now(), confirmationCb, gasEstimationForceSend, cb) run(this, args, Date.now(), confirmationCb, gasEstimationForceSend, promptCb, cb)
} }
function executeTx (tx, gasPrice, api, callback) { function executeTx (tx, gasPrice, api, promptCb, callback) {
if (gasPrice) tx.gasPrice = executionContext.web3().toHex(gasPrice) if (gasPrice) tx.gasPrice = executionContext.web3().toHex(gasPrice)
if (api.personalMode()) { if (api.personalMode()) {
modal.promptPassphrase(null, 'Personal mode is enabled. Please provide passphrase of account ' + tx.from, '', (value) => { promptCb(
(value) => {
sendTransaction(executionContext.web3().personal.sendTransaction, tx, value, callback) sendTransaction(executionContext.web3().personal.sendTransaction, tx, value, callback)
}, () => { },
() => {
return callback('Canceled by user.') return callback('Canceled by user.')
}) }
)
} else { } else {
sendTransaction(executionContext.web3().eth.sendTransaction, tx, null, callback) sendTransaction(executionContext.web3().eth.sendTransaction, tx, null, callback)
} }
} }
TxRunner.prototype.execute = function (args, confirmationCb, gasEstimationForceSend, callback) { TxRunner.prototype.execute = function (args, confirmationCb, gasEstimationForceSend, promptCb, callback) {
var self = this var self = this
var data = args.data var data = args.data
...@@ -46,7 +47,7 @@ TxRunner.prototype.execute = function (args, confirmationCb, gasEstimationForceS ...@@ -46,7 +47,7 @@ TxRunner.prototype.execute = function (args, confirmationCb, gasEstimationForceS
} }
if (!executionContext.isVM()) { if (!executionContext.isVM()) {
self.runInNode(args.from, args.to, data, args.value, args.gasLimit, args.useCall, confirmationCb, gasEstimationForceSend, callback) self.runInNode(args.from, args.to, data, args.value, args.gasLimit, args.useCall, confirmationCb, gasEstimationForceSend, promptCb, callback)
} else { } else {
try { try {
self.runInVm(args.from, args.to, data, args.value, args.gasLimit, args.useCall, callback) self.runInVm(args.from, args.to, data, args.value, args.gasLimit, args.useCall, callback)
...@@ -104,7 +105,7 @@ TxRunner.prototype.runInVm = function (from, to, data, value, gasLimit, useCall, ...@@ -104,7 +105,7 @@ TxRunner.prototype.runInVm = function (from, to, data, value, gasLimit, useCall,
}) })
} }
TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCall, confirmCb, gasEstimationForceSend, callback) { TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCall, confirmCb, gasEstimationForceSend, promptCb, callback) {
const self = this const self = this
var tx = { from: from, to: to, data: data, value: value } var tx = { from: from, to: to, data: data, value: value }
...@@ -123,7 +124,7 @@ TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCal ...@@ -123,7 +124,7 @@ TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCal
tx.gas = !gasEstimation ? gasLimit : gasEstimation tx.gas = !gasEstimation ? gasLimit : gasEstimation
if (self._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) { if (self._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) {
return executeTx(tx, null, self._api, callback) return executeTx(tx, null, self._api, promptCb, callback)
} }
self._api.detectNetwork((err, network) => { self._api.detectNetwork((err, network) => {
...@@ -133,7 +134,7 @@ TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCal ...@@ -133,7 +134,7 @@ TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCal
} }
confirmCb(network, tx, tx.gas, (gasPrice) => { confirmCb(network, tx, tx.gas, (gasPrice) => {
return executeTx(tx, gasPrice, self._api, callback) return executeTx(tx, gasPrice, self._api, promptCb, callback)
}, (error) => { }, (error) => {
callback(error) callback(error)
}) })
...@@ -186,12 +187,12 @@ function sendTransaction (sendTx, tx, pass, callback) { ...@@ -186,12 +187,12 @@ function sendTransaction (sendTx, tx, pass, callback) {
} }
} }
function run (self, tx, stamp, confirmationCb, gasEstimationForceSend, callback) { function run (self, tx, stamp, confirmationCb, gasEstimationForceSend, promptCb, callback) {
if (!self.runAsync && Object.keys(self.pendingTxs).length) { if (!self.runAsync && Object.keys(self.pendingTxs).length) {
self.queusTxs.push({ tx, stamp, callback }) self.queusTxs.push({ tx, stamp, callback })
} else { } else {
self.pendingTxs[stamp] = tx self.pendingTxs[stamp] = tx
self.execute(tx, confirmationCb, gasEstimationForceSend, (error, result) => { self.execute(tx, confirmationCb, gasEstimationForceSend, promptCb, (error, result) => {
delete self.pendingTxs[stamp] delete self.pendingTxs[stamp]
callback(error, result) callback(error, result)
if (self.queusTxs.length) { if (self.queusTxs.length) {
......
...@@ -330,6 +330,9 @@ UniversalDApp.prototype.runTx = function (args, cb) { ...@@ -330,6 +330,9 @@ UniversalDApp.prototype.runTx = function (args, cb) {
continueTxExecution() continueTxExecution()
} }
}, },
function (okCb, cancelCb) {
modalCustom.promptPassphrase(null, 'Personal mode is enabled. Please provide passphrase of account ' + tx.from, '', okCb, cancelCb)
},
function (error, result) { function (error, result) {
let eventName = (tx.useCall ? 'callExecuted' : 'transactionExecuted') let eventName = (tx.useCall ? 'callExecuted' : 'transactionExecuted')
self.event.trigger(eventName, [error, tx.from, tx.to, tx.data, tx.useCall, result, timestamp, payLoad]) self.event.trigger(eventName, [error, tx.from, tx.to, tx.data, tx.useCall, result, timestamp, payLoad])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment