diff --git a/src/app.js b/src/app.js index b0841855a9..40fd887493 100644 --- a/src/app.js +++ b/src/app.js @@ -251,6 +251,9 @@ function run () { config: self._api.config, detectNetwork: (cb) => { executionContext.detectNetwork(cb) + }, + personalMode: () => { + return self._api.config.get('settings/personal-mode') } }, opt: { removable: false, removable_instances: true } diff --git a/src/app/execution/txRunner.js b/src/app/execution/txRunner.js index 3a3ac11429..3f4863869f 100644 --- a/src/app/execution/txRunner.js +++ b/src/app/execution/txRunner.js @@ -11,6 +11,7 @@ var csjs = require('csjs-inject') var remixLib = require('remix-lib') var styleGuide = remixLib.ui.styleGuide var styles = styleGuide() +var modal = require('../ui/modal-dialog-custom') var css = csjs` .txInfoBox { @@ -25,12 +26,11 @@ var css = csjs` } ` -function TxRunner (vmaccounts, opts) { - this.personalMode = opts.personalMode + +function TxRunner (vmaccounts, api) { + this._api = api this.blockNumber = 0 this.runAsync = true - this.config = opts.config - this.detectNetwork = opts.detectNetwork if (executionContext.isVM()) { this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block. this.runAsync = false // We have to run like this cause the VM Event Manager does not support running multiple txs at the same time. @@ -45,23 +45,21 @@ TxRunner.prototype.rawRun = function (args, cb) { } TxRunner.prototype.execute = function (args, callback) { + var self = this function execute (gasPrice) { if (gasPrice) tx.gasPrice = executionContext.web3().toHex(gasPrice) - var sendTransaction = self.personalMode ? executionContext.web3().personal.sendTransaction : executionContext.web3().eth.sendTransaction - try { - sendTransaction(tx, function (err, resp) { - if (err) { - return callback(err, resp) - } - - tryTillResponse(resp, callback) + if (self._api.personalMode()) { + modal.promptPassphrase(null, 'Personal mode is enabled. Please provide passphrase of account ' + tx.from, '', (value) => { + sendTransaction(executionContext.web3().personal.sendTransaction, tx, value, callback) + }, () => { + return callback('Canceled by user.') }) - } catch (e) { - return callback(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `) + } else { + sendTransaction(executionContext.web3().eth.sendTransaction, tx, null, callback) } } - var self = this + var from = args.from var to = args.to var data = args.data @@ -206,6 +204,21 @@ function tryTillResponse (txhash, done) { }) } +function sendTransaction (sendTx, tx, pass, callback) { + var cb = function (err, resp) { + if (err) { + return callback(err, resp) + } + tryTillResponse(resp, callback) + } + var args = pass !== null ? [tx, pass, cb] : [tx, cb] + try { + sendTx.apply({}, args) + } catch (e) { + return callback(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `) + } +} + function run (self, tx, stamp, callback) { if (!self.runAsync && Object.keys(self.pendingTxs).length) { self.queusTxs.push({ tx, stamp, callback }) diff --git a/src/app/tabs/settings-tab.js b/src/app/tabs/settings-tab.js index 4553d8fe53..b3ddcbd4c2 100644 --- a/src/app/tabs/settings-tab.js +++ b/src/app/tabs/settings-tab.js @@ -90,6 +90,7 @@ function SettingsTab (container, appAPI, appEvents, opts) { var queryParams = new QueryParams() var optionVM = yo`` + var personal = yo`` var el = yo`