diff --git a/src/app.js b/src/app.js index 77890695d6..5e49e305cd 100644 --- a/src/app.js +++ b/src/app.js @@ -255,6 +255,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 } @@ -623,6 +626,9 @@ function run () { }, getCompilationResult: () => { return compiler.lastCompilationResult + }, + newAccount: (pass, cb) => { + udapp.newAccount(pass, cb) } } var rhpEvents = { diff --git a/src/app/execution/txRunner.js b/src/app/execution/txRunner.js index 3a3ac11429..0d48c8e485 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,10 @@ 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 +44,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 @@ -107,8 +104,8 @@ TxRunner.prototype.execute = function (args, callback) { tx.gas = gasEstimation - if (!self.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) { - self.detectNetwork((err, network) => { + if (!self._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) { + self._api.detectNetwork((err, network) => { if (err) { console.log(err) } else { @@ -117,7 +114,7 @@ TxRunner.prototype.execute = function (args, callback) { modalDialog('Confirm transaction', content, { label: 'Confirm', fn: () => { - self.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked) + self._api.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked) if (!content.gasPriceStatus) { callback('Given gas grice is not correct') } else { @@ -206,6 +203,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 }) @@ -234,7 +246,7 @@ function confirmDialog (tx, gasEstimation, self) {
${tx.data}diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index ee2837f0e9..c0d62140ae 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -10,6 +10,7 @@ var executionContext = require('../../execution-context') var copyToClipboard = require('../ui/copy-to-clipboard') var Recorder = require('../../recorder') var EventManager = require('remix-lib').EventManager +var addTooltip = require('../ui/tooltip') // -------------- styling ---------------------- var csjs = require('csjs-inject') @@ -191,6 +192,14 @@ var css = csjs` } .transactionActions { float: right; + } + .createAccount { + margin-left: 5px; + cursor: pointer; + } + .createAccount:hover { + color: ${styles.colors.orange}; + } ` module.exports = runTab @@ -282,7 +291,7 @@ function fillAccountsList (appAPI, container) { var $txOrigin = $(container.querySelector('#txorigin')) $txOrigin.empty() appAPI.udapp().getAccounts((err, accounts) => { - if (err) { console.log(err) } + if (err) { addTooltip(`Cannot get account list: ${err}`) } if (accounts && accounts[0]) { for (var a in accounts) { $txOrigin.append($('').val(accounts[a]).text(accounts[a])) } $txOrigin.val(accounts[0]) @@ -543,6 +552,16 @@ function settings (container, appAPI, appEvents) { }) } setInterval(updateNetwork, 5000) + function newAccount () { + appAPI.newAccount('', (error, address) => { + if (!error) { + container.querySelector('#txorigin').appendChild(yo``) + addTooltip(`account ${address} created`) + } else { + addTooltip('Cannot create an account: ' + error) + } + }) + } var el = yo`