From f6a3efc7401416638f941799646fb45621e514f3 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 22 Jan 2018 11:34:30 +0100 Subject: [PATCH] account creation for personla mode and VM mode --- src/app.js | 3 +++ src/app/execution/txRunner.js | 7 +++--- src/app/tabs/run-tab.js | 15 +++++++++++ src/app/tabs/settings-tab.js | 41 ++++++++----------------------- src/app/ui/modal-dialog-custom.js | 27 ++++++++++++++++++++ src/universal-dapp.js | 13 +++++++--- 6 files changed, 68 insertions(+), 38 deletions(-) diff --git a/src/app.js b/src/app.js index 40fd887493..ff9c8c175e 100644 --- a/src/app.js +++ b/src/app.js @@ -622,6 +622,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 3f4863869f..0d040fae8b 100644 --- a/src/app/execution/txRunner.js +++ b/src/app/execution/txRunner.js @@ -26,7 +26,6 @@ var css = csjs` } ` - function TxRunner (vmaccounts, api) { this._api = api this.blockNumber = 0 @@ -105,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 { @@ -115,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 { diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index 02df26e3d1..0e5f14fe3f 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -191,6 +191,11 @@ var css = csjs` } .transactionActions { float: right; + } + .createAccount { + margin-left: 5px; + cursor: pointer; + } ` module.exports = runTab @@ -526,6 +531,15 @@ function settings (container, appAPI, appEvents) { }) } setInterval(updateNetwork, 5000) + function newAccount () { + appAPI.newAccount('', (error, address) => { + if (!error) { + container.querySelector('#txorigin').appendChild(yo``) + } else { + modalDialogCustom.alert('Cannot create an account: ' + error) + } + }) + } var el = yo`
@@ -562,6 +576,7 @@ function settings (container, appAPI, appEvents) {
Account
${copyToClipboard(() => document.querySelector('#runTabView #txorigin').value)} +
Gas limit
diff --git a/src/app/tabs/settings-tab.js b/src/app/tabs/settings-tab.js index b3ddcbd4c2..1cfab7b5c2 100644 --- a/src/app/tabs/settings-tab.js +++ b/src/app/tabs/settings-tab.js @@ -100,37 +100,6 @@ function SettingsTab (container, appAPI, appEvents, opts) {
-
- -
-
-
- Text Wrap -
-
-
${optionVM}
- Always use VM at Load -
-
-
- Enable Optimization -
-
-
${personal}>
- Enable Personal Mode (transaction sent over Web3 will use the web3.personal API - be sure the endpoint is opened before enabling it -). -
- This mode allows to provide the passphrase in the Remix interface without having to unlock the account.
- Although this is very convenient, you should completely trust the backend you are connected to (Geth, Parity, ...).
- It is not recommended (and also most likely not relevant) to use this mode with an injected provider (Mist, Metamask, ...) or with JavaScript VM
- Remix never persist any passphrase. -
-
-
-

Themes ( Selecting a theme will trigger a page reload )

-
- - -
General settings
@@ -145,6 +114,16 @@ function SettingsTab (container, appAPI, appEvents, opts) {
Enable Optimization
+
+
${personal}>
+ Enable Personal Mode (transaction sent over Web3 will use the web3.personal API - be sure the endpoint is opened before enabling it -). +
+ This mode allows to provide the passphrase in the Remix interface without having to unlock the account.
+ Although this is very convenient, you should completely trust the backend you are connected to (Geth, Parity, ...).
+ It is not recommended (and also most likely not relevant) to use this mode with an injected provider (Mist, Metamask, ...) or with JavaScript VM
+ Remix never persist any passphrase. +
+
Themes
diff --git a/src/app/ui/modal-dialog-custom.js b/src/app/ui/modal-dialog-custom.js index f8658b2418..192dae5a97 100644 --- a/src/app/ui/modal-dialog-custom.js +++ b/src/app/ui/modal-dialog-custom.js @@ -17,6 +17,33 @@ module.exports = { promptPassphrase: function (title, text, inputValue, ok, cancel) { prompt(title, text, true, inputValue, ok, cancel) }, + promptPassphraseCreation: function (ok, cancel) { + var text = 'Please provide a Passphrase for the account creation' + var input = yo`
+ +
+
+ +
` + modal(null, yo`
${text}
${input}
`, + { + fn: () => { + if (typeof ok === 'function') { + if (input.querySelector('#prompt1').value === input.querySelector('#prompt2').value) { + ok(null, input.querySelector('#prompt1').value) + } else { + ok('Passphase does not match') + } + } + } + }, + { + fn: () => { + if (typeof cancel === 'function') cancel() + } + } + ) + }, promptMulti: function ({ title, text, inputValue }, ok, cancel) { if (!inputValue) inputValue = '' var input = yo`` diff --git a/src/universal-dapp.js b/src/universal-dapp.js index fc669be700..bf28945711 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -15,6 +15,7 @@ var txExecution = require('./app/execution/txExecution') var helper = require('./lib/helper') var executionContext = require('./execution-context') var copyToClipboard = require('./app/ui/copy-to-clipboard') +var modalCustom = require('./app/ui/modal-dialog-custom') // -------------- styling ---------------------- var csjs = require('csjs-inject') @@ -190,14 +191,20 @@ UniversalDApp.prototype.newAccount = function (password, cb) { if (!this._api.personalMode()) { return cb('Not running in personal mode') } - executionContext.web3().personal.newAccount(password, cb) + modalCustom.promptPassphraseCreation((error, passphrase) => { + if (error) { + modalCustom.alert(error) + } else { + executionContext.web3().personal.newAccount(passphrase, cb) + } + }, () => {}) } else { var privateKey do { privateKey = crypto.randomBytes(32) } while (!ethJSUtil.isValidPrivate(privateKey)) - this._addAccount(privateKey) - cb(null, '0x' + ethJSUtil.privateToAddress(privateKey)) + this._addAccount(privateKey, '0x56BC75E2D63100000') + cb(null, '0x' + ethJSUtil.privateToAddress(privateKey).toString('hex')) } }