diff --git a/assets/css/universal-dapp.css b/assets/css/universal-dapp.css index 7ba28043f3..3605f70f13 100644 --- a/assets/css/universal-dapp.css +++ b/assets/css/universal-dapp.css @@ -44,6 +44,7 @@ .udapp .contract { margin-bottom: 1em; + clear: both; } .udapp .create { diff --git a/assets/js/universal-dapp.js b/assets/js/universal-dapp.js index 54c505a923..b052635e81 100644 --- a/assets/js/universal-dapp.js +++ b/assets/js/universal-dapp.js @@ -221,57 +221,65 @@ UniversalDApp.prototype.getCallButton = function(args) { } var getOutput = function() { - var values = Array.prototype.slice.call(arguments); var $result = $('
'); var $close = $('
'); $close.click( function(){ $result.remove(); } ); $result.append( $close ); - for( var v in values ) { $result.append( values[v] ); } return $result; - } - - var handleCallButtonClick = function( ev ) { + }; + var clearOutput = function($result) { + $(':not(.udapp-close)', $result).remove(); + }; + var replaceOutput = function($result, message) { + clearOutput($result); + $result.append(message); + }; + + var handleCallButtonClick = function(ev, $result) { var funArgs = $.parseJSON('[' + inputField.val() + ']'); var data = fun.toPayload(funArgs).data; if (data.slice(0, 2) == '0x') data = data.slice(2); - var $result = getOutput( $('Polling for tx receipt...') ); + if (!$result) { + $result = getOutput(); + if (lookupOnly && !inputs.length) + $outputOverride.empty().append( $result ); + else + outputSpan.append( $result ); + } + replaceOutput($result, $('Waiting for transaction to be mined...')); if (isConstructor) { - if (args.bytecode.indexOf('_') >= 0) { + if (args.bytecode.indexOf('_') >= 0) { + replaceOutput($result, $('Deploying and linking required libraries...')); if (self.options.vm) self.linkBytecode(args.contractName, function(err, bytecode) { if (err) - $result.replaceWith(getOutput($('').text('Error deploying required libraries: ' + err))); + replaceOutput($result, $('').text('Error deploying required libraries: ' + err)); else { args.bytecode = bytecode; - handleCallButtonClick(ev); + handleCallButtonClick(ev, $result); } }); else - $result.replaceWith(getOutput( $('Contract needs to be linked to a library, this is only supported in the JavaScript VM for now.'))); + replaceOutput($result, $('Contract needs to be linked to a library, this is only supported in the JavaScript VM for now.')); return; } else data = args.bytecode + data.slice(8); - } - - if (lookupOnly && !inputs.length) { - $outputOverride.empty().append( $result ); - } else { - outputSpan.append( $result ); } self.runTx(data, args, function(err, result) { if (err) { - $result.replaceWith( getOutput( $('').text(err).addClass('error') ) ); + replaceOutput($result, $('').text(err).addClass('error')); } else if (self.options.vm && isConstructor) { - $result.replaceWith( getOutput( getGasUsedOutput( result ) ) ); + replaceOutput($result, getGasUsedOutput(result)); args.appendFunctions(result.createdAddress); } else if (self.options.vm){ var outputObj = fun.unpackOutput('0x' + result.vm.return.toString('hex')); - $result.replaceWith( getOutput( getReturnOutput( outputObj ), getGasUsedOutput( result.vm ) ) ); + clearOutput($result); + $result.append(getReturnOutput(outputObj)).append(getGasUsedOutput(result.vm)); } else if (args.abi.constant && !isConstructor) { - $result.replaceWith( getOutput( getReturnOutput( result ) ) ); + replaceOutput($result, getReturnOutput(result)); } else { function tryTillResponse (txhash, done) { @@ -288,7 +296,10 @@ UniversalDApp.prototype.getCallButton = function(args) { if (isConstructor) { $result.html(''); args.appendFunctions(result.contractAddress); - } else $result.replaceWith( getOutput( getReturnOutput( result ), getGasUsedOutput( result ) ) ); + } else { + clearOutput($result); + $result.append(getReturnOutput(result)).append(getGasUsedOutput(result)); + } }) } diff --git a/index.html b/index.html index 204aaa923b..8697b83cc9 100644 --- a/index.html +++ b/index.html @@ -602,7 +602,10 @@ THE SOFTWARE. web3.eth.getAccounts(function(err, accounts) { if (err) renderError(err.message); - $('#txorigin').text(accounts[0]); + if (accounts && accounts[0]) + $('#txorigin').text(accounts[0]); + else + $('#txorigin').text('unknown'); }); $contractOutput.find('.title').click(function(ev){ $(this).closest('.contract').toggleClass('hide'); });