From 3290e6fc18b6194f5f12983a5642f6717c01dc96 Mon Sep 17 00:00:00 2001 From: d11e9 Date: Tue, 27 Oct 2015 13:42:39 +0000 Subject: [PATCH] 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