From 48a5fccbf95c665b0b96f6ca8e1f9c5746b3e99c Mon Sep 17 00:00:00 2001 From: d11e9 Date: Mon, 26 Oct 2015 12:01:40 +0000 Subject: [PATCH 1/5] custom web3 endpoint --- assets/js/universal-dapp.js | 2 +- index.html | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/assets/js/universal-dapp.js b/assets/js/universal-dapp.js index e8fdcab6f4..9917399a46 100644 --- a/assets/js/universal-dapp.js +++ b/assets/js/universal-dapp.js @@ -22,7 +22,7 @@ function UniversalDApp (contracts, options) { } else { var host = options.host || "localhost"; var port = options.port || "8545"; - var rpc_url = 'http://' + host + ':' + port; + var rpc_url = options.web3endpoint || ('http://' + host + ':' + port); web3.setProvider( new web3.providers.HttpProvider( rpc_url ) ); } diff --git a/index.html b/index.html index 37b09eab94..bf1215e7ff 100644 --- a/index.html +++ b/index.html @@ -97,13 +97,18 @@
-
@@ -222,12 +227,14 @@ var $vmToggle = $('#vm'); var $web3Toggle = $('#web3'); + var $web3endpoint = $('#web3Endpoint'); var executionContext = 'vm'; $vmToggle.get(0).checked = true; $vmToggle.on('change', executionContextChange ); $web3Toggle.on('change', executionContextChange ); + $web3endpoint.on('change', compile ); function executionContextChange (ev) { if (ev.target.value == 'web3' && !confirm("Are you sure you want to connect to a local ethereum node?") ) { @@ -752,6 +759,7 @@ removable: false, getAddress: function(){ return $('#txorigin').val(); }, removable_instances: true, + web3endpoint: $('#web3Endpoint').val(), renderOutputModifier: function(contractName, $contractOutput) { var contract = data.contracts[contractName]; return $contractOutput From 3290e6fc18b6194f5f12983a5642f6717c01dc96 Mon Sep 17 00:00:00 2001 From: d11e9 Date: Tue, 27 Oct 2015 13:42:39 +0000 Subject: [PATCH 2/5] handle endpoint updating and errors --- assets/js/universal-dapp.js | 5 +++-- index.html | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/assets/js/universal-dapp.js b/assets/js/universal-dapp.js index 9917399a46..dcd05d38a2 100644 --- a/assets/js/universal-dapp.js +++ b/assets/js/universal-dapp.js @@ -22,7 +22,7 @@ function UniversalDApp (contracts, options) { } else { var host = options.host || "localhost"; var port = options.port || "8545"; - var rpc_url = options.web3endpoint || ('http://' + host + ':' + port); + var rpc_url = options.getWeb3endpoint ? options.getWeb3endpoint() : ('http://' + host + ':' + port); web3.setProvider( new web3.providers.HttpProvider( rpc_url ) ); } @@ -296,7 +296,8 @@ UniversalDApp.prototype.getCallButton = function(args) { } tryTillResponse( result, function(err, result) { - if (isConstructor) { + if (err) replaceOutput($result, $('').text(err).addClass('error')); + else if (isConstructor) { $result.html(''); args.appendFunctions(result.contractAddress); } else { diff --git a/index.html b/index.html index bf1215e7ff..9c7faaa5ec 100644 --- a/index.html +++ b/index.html @@ -234,7 +234,11 @@ $vmToggle.on('change', executionContextChange ); $web3Toggle.on('change', executionContextChange ); - $web3endpoint.on('change', compile ); + $web3endpoint.on('change', function(){ + var endpoint = $('#web3Endpoint').val(); + web3.setProvider( new web3.providers.HttpProvider( endpoint ) ); + compile(); + } ); function executionContextChange (ev) { if (ev.target.value == 'web3' && !confirm("Are you sure you want to connect to a local ethereum node?") ) { @@ -759,7 +763,6 @@ removable: false, getAddress: function(){ return $('#txorigin').val(); }, removable_instances: true, - web3endpoint: $('#web3Endpoint').val(), renderOutputModifier: function(contractName, $contractOutput) { var contract = data.contracts[contractName]; return $contractOutput From d56f79d484ba4b7d1b536863408e4f7c9437bd85 Mon Sep 17 00:00:00 2001 From: d11e9 Date: Tue, 27 Oct 2015 13:53:13 +0000 Subject: [PATCH 3/5] only render contract interfaces if RHP is visible --- assets/js/universal-dapp.js | 2 +- index.html | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/assets/js/universal-dapp.js b/assets/js/universal-dapp.js index dcd05d38a2..8c3f1da277 100644 --- a/assets/js/universal-dapp.js +++ b/assets/js/universal-dapp.js @@ -5,7 +5,7 @@ function UniversalDApp (contracts, options) { this.renderOutputModifier = options.renderOutputModifier || function(name, content) { return content; }; if (!options.vm && web3.currentProvider) { - + console.log("Provider already set") } else if (options.vm) { this.vm = new EthVm(); //@todo this does not calculate the gas costs correctly but gets the job done. diff --git a/index.html b/index.html index 9c7faaa5ec..9307e1870b 100644 --- a/index.html +++ b/index.html @@ -238,7 +238,7 @@ var endpoint = $('#web3Endpoint').val(); web3.setProvider( new web3.providers.HttpProvider( endpoint ) ); compile(); - } ); + }); function executionContextChange (ev) { if (ev.target.value == 'web3' && !confirm("Are you sure you want to connect to a local ethereum node?") ) { @@ -467,7 +467,8 @@ $('.toggleRHP').click(function(){ toggledRHP = !toggledRHP; setEditorSize( toggledRHP ? 0 : window.localStorage[EDITOR_SIZE_CACHE_KEY] ); - $('.toggleRHP').toggleClass('toggled', toggledRHP) + $('.toggleRHP').toggleClass('toggled', toggledRHP); + if (!toggledRHP) compile(); }); @@ -499,7 +500,6 @@ var previousInput = ''; var sourceAnnotations = []; var compile = function() { - editor.getSession().clearAnnotations(); sourceAnnotations = []; editor.getSession().removeMarker(errMarkerId); @@ -530,7 +530,7 @@ }); } - if (noFatalErrors) renderContracts(data, editor.getValue()); + if (noFatalErrors && !toggledRHP) renderContracts(data, editor.getValue()); }; var compileTimeout = null; From 292d87d4d86b97899bd49aea8ce41f0b4c21be6a Mon Sep 17 00:00:00 2001 From: d11e9 Date: Tue, 27 Oct 2015 13:55:08 +0000 Subject: [PATCH 4/5] remove console log --- assets/js/universal-dapp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/universal-dapp.js b/assets/js/universal-dapp.js index 8c3f1da277..dcd05d38a2 100644 --- a/assets/js/universal-dapp.js +++ b/assets/js/universal-dapp.js @@ -5,7 +5,7 @@ function UniversalDApp (contracts, options) { this.renderOutputModifier = options.renderOutputModifier || function(name, content) { return content; }; if (!options.vm && web3.currentProvider) { - console.log("Provider already set") + } else if (options.vm) { this.vm = new EthVm(); //@todo this does not calculate the gas costs correctly but gets the job done. From 16f3648b2a45185e1e9a45ab6ed2b5aa4429ca0f Mon Sep 17 00:00:00 2001 From: d11e9 Date: Tue, 27 Oct 2015 17:06:28 +0000 Subject: [PATCH 5/5] better naming for RHP toggle --- index.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 9307e1870b..5397d1fc74 100644 --- a/index.html +++ b/index.html @@ -463,12 +463,12 @@ // ----------------- toggle right hand panel ----------------- - var toggledRHP = false; + var hidingRHP = false; $('.toggleRHP').click(function(){ - toggledRHP = !toggledRHP; - setEditorSize( toggledRHP ? 0 : window.localStorage[EDITOR_SIZE_CACHE_KEY] ); - $('.toggleRHP').toggleClass('toggled', toggledRHP); - if (!toggledRHP) compile(); + hidingRHP = !hidingRHP; + setEditorSize( hidingRHP ? 0 : window.localStorage[EDITOR_SIZE_CACHE_KEY] ); + $('.toggleRHP').toggleClass('hiding', hidingRHP); + if (!hidingRHP) compile(); }); @@ -530,7 +530,7 @@ }); } - if (noFatalErrors && !toggledRHP) renderContracts(data, editor.getValue()); + if (noFatalErrors && !hidingRHP) renderContracts(data, editor.getValue()); }; var compileTimeout = null;