From f2cd335d1a4d51feaaa30ea6dc8b02aaebab57ad Mon Sep 17 00:00:00 2001 From: ninabreznik Date: Fri, 12 Jan 2018 05:00:25 +0800 Subject: [PATCH] Display modal when Ropsten is selected --- src/app.js | 5 ++- src/app/execution/txRunner.js | 58 ++++++++++++++++++++++++++++------- src/universal-dapp.js | 6 ++-- 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/app.js b/src/app.js index 157a6fee62..67b4056662 100644 --- a/src/app.js +++ b/src/app.js @@ -248,7 +248,10 @@ function run () { logMessage: (msg) => { self._components.editorpanel.log({ type: 'log', value: msg }) }, - config: self._api.config + config: self._api.config, + detectNetwork: (cb) => { + executionContext.detectNetwork(cb) + } }, opt: { removable: false, removable_instances: true } }) diff --git a/src/app/execution/txRunner.js b/src/app/execution/txRunner.js index 89a0360c0c..8b1f33cd5a 100644 --- a/src/app/execution/txRunner.js +++ b/src/app/execution/txRunner.js @@ -27,6 +27,7 @@ function TxRunner (vmaccounts, opts) { 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. @@ -42,7 +43,6 @@ TxRunner.prototype.rawRun = function (args, cb) { TxRunner.prototype.execute = function (args, callback) { var self = this - var from = args.from var to = args.to var data = args.data @@ -62,11 +62,28 @@ TxRunner.prototype.execute = function (args, callback) { } if (args.useCall) { tx.gas = gasLimit - modalDialog('Confirm transaction', remixdDialog(tx, self), - { label: 'Confirm', - fn: () => { - execute() - }}) + + if (true) { + self.detectNetwork((err,network) => { + if (err) { + console.log(err) + } else { + console.log(network.name) + if (network.name === 'Ropsten') { + modalDialog('Confirm transaction', remixdDialog(tx, self), + { label: 'Confirm', + fn: () => { + execute() + }}) + } else { + execute() + } + } + }) + } else { + execute() + } + function execute () { executionContext.web3().eth.call(tx, function (error, result) { callback(error, { @@ -93,11 +110,29 @@ TxRunner.prototype.execute = function (args, callback) { } tx.gas = gasEstimation - modalDialog('Confirm transaction', remixdDialog(tx, self), - { label: 'Confirm', - fn: () => { - execute() - }}) + + if (true) { + + self.detectNetwork((err,network) => { + if (err) { + console.log(err) + } else { + console.log(network.name) + if (network.name === 'Ropsten') { + modalDialog('Confirm transaction', remixdDialog(tx, self), + { label: 'Confirm', + fn: () => { + execute() + }}) + } else { + execute() + } + } + }) + } else { + execute() + } + }) function execute () { var sendTransaction = self.personalMode ? executionContext.web3().personal.sendTransaction : executionContext.web3().eth.sendTransaction @@ -114,6 +149,7 @@ TxRunner.prototype.execute = function (args, callback) { } } } + } else { try { var account = self.vmaccounts[from] diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 96a10ec644..ca8f31c0ec 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -168,7 +168,8 @@ function UniversalDApp (opts = {}) { }) self.txRunner = new TxRunner({}, { personalMode: this.personalMode, - config: self._api.config + config: self._api.config, + detectNetwork: self._api.detectNetwork }) } @@ -189,7 +190,8 @@ UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) { } this.txRunner = new TxRunner(this.accounts, { personalMode: this.personalMode, - config: this._api.config + config: this._api.config, + detectNetwork: this._api.detectNetwork }) }