From e7fe06c8f3be9521200c4171f9b6ef2a35f51afa Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 8 Oct 2015 00:36:03 +0200 Subject: [PATCH 1/3] All contracts in a single Universal DApp. --- index.html | 40 ++++++++++++++++++++------------ libs/universal-dapp.js | 3 ++- stylesheets/browser-solidity.css | 12 ++++------ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/index.html b/index.html index 4d35a995ac..5ba6e7f740 100644 --- a/index.html +++ b/index.html @@ -500,34 +500,44 @@ THE SOFTWARE. }; var renderContracts = function(data, source) { + var udappContracts = []; for (var contractName in data.contracts) { var contract = data.contracts[contractName]; - var dapp = new UniversalDApp([{ + udappContracts.push({ name: contractName, - interface: contract['interface'], + interface: contract['interface'], bytecode: contract.bytecode - }], { - vm: executionContext === 'vm', - removable: false, - removable_instances: true }); - var $contractOutput = dapp.render(); - $contractOutput + } + var dapp = new UniversalDApp(udappContracts, { + vm: executionContext === 'vm', + removable: false, + removable_instances: true, + renderOutputModifier: function(contractName, $contractOutput) { + var contract = data.contracts[contractName]; + return $contractOutput .append(textRow('Bytecode', contract.bytecode)) .append(textRow('Interface', contract['interface'])) .append(textRow('Web3 deploy', gethDeploy(contractName.toLowerCase(),contract['interface'],contract.bytecode), 'deploy')) .append(textRow('uDApp', combined(contractName,contract['interface'],contract.bytecode), 'deploy')) .append(getDetails(contract, source, contractName)); - - if (executionContext === 'vm') $('#txorigin').text('0x' + dapp.address.toString('hex')); - else web3.eth.getAccounts( function(err,accounts) { - if (err) renderError(err.message); + }}); + var $contractOutput = dapp.render(); + + if (executionContext === 'vm') + $('#txorigin').text('0x' + dapp.address.toString('hex')); + else + web3.eth.getAccounts(function(err, accounts) { + if (err) + renderError(err.message); $('#txorigin').text(accounts[0]); }); - $contractOutput.find('.title').click(function(ev){ $(this).closest('.udapp').toggleClass('hide') }); - $('#output').append( $contractOutput ); - } + $contractOutput.find('.title').click(function(ev){ + console.log($(this)); + $(this).closest('.contract').toggleClass('hide'); + }); + $('#output').append( $contractOutput ); $('.col2 input,textarea').click(function() { this.select(); }); }; var tableRowItems = function(first, second, cls) { diff --git a/libs/universal-dapp.js b/libs/universal-dapp.js index 63c1fe69e7..0f03553a72 100644 --- a/libs/universal-dapp.js +++ b/libs/universal-dapp.js @@ -2,6 +2,7 @@ function UniversalDApp (contracts, options) { this.options = options || {}; this.$el = $('
'); this.contracts = contracts; + this.renderOutputModifier = options.renderOutputModifier || function(name, content) { return content; }; if (!options.vm && web3.currentProvider) { @@ -44,7 +45,7 @@ UniversalDApp.prototype.render = function () { } $contractEl.append( $title ).append( this.getCreateInterface( $contractEl, this.contracts[c]) ); } - this.$el.append( $contractEl ); + this.$el.append(this.renderOutputModifier(this.contracts[c].name, $contractEl)); } } $legend = $('
') diff --git a/stylesheets/browser-solidity.css b/stylesheets/browser-solidity.css index 1040eaf84c..6a67373938 100644 --- a/stylesheets/browser-solidity.css +++ b/stylesheets/browser-solidity.css @@ -126,19 +126,15 @@ body { float: left; } -.udapp.hide { +.contract.hide { padding-bottom: 0; } -.udapp.hide > *:not(.contract) { - display: none; -} - -.udapp.hide .contract { +.contract.hide { margin: 0; } -.udapp.hide .contract > *:not(.title) { +.contract.hide > *:not(.title) { display: none; } @@ -153,7 +149,7 @@ body { font-size: 10px; } -.udapp.hide > .contract > .title:before { +.contract.hide > .title:before { content: "\25B6"; } From c6062c5355e3daec6cc9730c675d2f424c4ebf4e Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 8 Oct 2015 13:20:31 +0200 Subject: [PATCH 2/3] Automatically deploy and link required libraries. --- index.html | 5 +-- libs/universal-dapp.js | 78 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 5ba6e7f740..2b5064a3e1 100644 --- a/index.html +++ b/index.html @@ -533,10 +533,7 @@ THE SOFTWARE. $('#txorigin').text(accounts[0]); }); - $contractOutput.find('.title').click(function(ev){ - console.log($(this)); - $(this).closest('.contract').toggleClass('hide'); - }); + $contractOutput.find('.title').click(function(ev){ $(this).closest('.contract').toggleClass('hide'); }); $('#output').append( $contractOutput ); $('.col2 input,textarea').click(function() { this.select(); }); }; diff --git a/libs/universal-dapp.js b/libs/universal-dapp.js index 0f03553a72..68a3dda8b9 100644 --- a/libs/universal-dapp.js +++ b/libs/universal-dapp.js @@ -60,10 +60,17 @@ UniversalDApp.prototype.render = function () { return this.$el; } +UniversalDApp.prototype.getContractByName = function(contractName) { + for (var c in this.contracts) + if (this.contracts[c].name == contractName) + return this.contracts[c]; + return null; +}; + UniversalDApp.prototype.getABIInputForm = function (cb){ var self = this; var $el = $('
'); - var $jsonInput = $('