From 66acb7a0c8e3220b26c69fa58edaad427e794d83 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Jun 2016 19:57:39 +0100 Subject: [PATCH 1/8] Standard: mark globals --- background.js | 2 ++ src/app.js | 2 ++ src/app/editor.js | 2 ++ src/app/execution-context.js | 2 ++ src/app/gist-handler.js | 2 ++ src/app/storage-handler.js | 2 ++ src/universal-dapp.js | 2 ++ 7 files changed, 14 insertions(+) diff --git a/background.js b/background.js index 332bd20c27..c8adcda9c7 100644 --- a/background.js +++ b/background.js @@ -1,3 +1,5 @@ +/* global chrome */ + chrome.browserAction.onClicked.addListener(function (tab) { chrome.storage.sync.set({ 'chrome-app-sync' : true }); diff --git a/src/app.js b/src/app.js index 15c5b1c247..ba9e650f89 100644 --- a/src/app.js +++ b/src/app.js @@ -1,3 +1,5 @@ +/* global alert, confirm, prompt, Option, Worker, soljsonSources */ + var $ = require('jquery'); var utils = require('./app/utils'); diff --git a/src/app/editor.js b/src/app/editor.js index b8fe36d184..4592525d75 100644 --- a/src/app/editor.js +++ b/src/app/editor.js @@ -1,3 +1,5 @@ +/* global BALLOT_EXAMPLE, FileReader */ + var utils = require('./utils'); var ace = require('brace'); diff --git a/src/app/execution-context.js b/src/app/execution-context.js index db2c1cde8f..033f91ffdc 100644 --- a/src/app/execution-context.js +++ b/src/app/execution-context.js @@ -1,3 +1,5 @@ +/* global confirm */ + var $ = require('jquery'); var Web3 = require('web3'); diff --git a/src/app/gist-handler.js b/src/app/gist-handler.js index fe21092e73..7d07651512 100644 --- a/src/app/gist-handler.js +++ b/src/app/gist-handler.js @@ -1,3 +1,5 @@ +/* global prompt */ + var queryParams = require('./query-params'); function handleLoad (cb) { diff --git a/src/app/storage-handler.js b/src/app/storage-handler.js index 783dce1778..1c9a8b7633 100644 --- a/src/app/storage-handler.js +++ b/src/app/storage-handler.js @@ -1,3 +1,5 @@ +/* global chrome, confirm, localStorage */ + var utils = require('./utils'); function StorageHandler (updateFiles) { diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 867ac65194..838fdd4f66 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -1,3 +1,5 @@ +/* global prompt */ + var $ = require('jquery'); var EthJSVM = require('ethereumjs-vm'); var ethJSUtil = require('ethereumjs-util'); From 18f094d70ef515b32468866e027312c7d66c5929 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Jun 2016 19:58:43 +0100 Subject: [PATCH 2/8] Standard: fix undefined/redefined variables --- src/app/compiler-worker.js | 2 +- src/universal-dapp.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/compiler-worker.js b/src/app/compiler-worker.js index ca1cb890f3..81867b197e 100644 --- a/src/app/compiler-worker.js +++ b/src/app/compiler-worker.js @@ -15,7 +15,7 @@ module.exports = function (self) { version = Module.cwrap("version", "string", []); if ('_compileJSONCallback' in Module) { - compileJSONInternal = Module.cwrap("compileJSONCallback", "string", ["string", "number", "number"]); + var compileJSONInternal = Module.cwrap("compileJSONCallback", "string", ["string", "number", "number"]); var missingInputCallback = Module.Runtime.addFunction(function(path) { missingInputs.push(Module.Pointer_stringify(path)); }); diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 838fdd4f66..0e6770f88b 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -345,13 +345,14 @@ UniversalDApp.prototype.getCallButton = function (args) { var getGasUsedOutput = function (result, vmResult) { var $gasUsed = $('
'); var caveat = lookupOnly ? '(caveat)' : ''; + var gas; if (result.gasUsed) { - var gas = result.gasUsed.toString(10); + gas = result.gasUsed.toString(10); $gasUsed.html('Transaction cost: ' + gas + ' gas. ' + caveat); } if (vmResult.gasUsed) { var $callGasUsed = $('
'); - var gas = vmResult.gasUsed.toString(10); + gas = vmResult.gasUsed.toString(10); $callGasUsed.append('Execution cost: ' + gas + ' gas.'); $gasUsed.append($callGasUsed); } @@ -456,8 +457,10 @@ UniversalDApp.prototype.getCallButton = function (args) { // Only decode if there supposed to be fields if (args.abi.outputs.length > 0) { try { + var i; + var outputTypes = []; - for (var i = 0; i < args.abi.outputs.length; i++) { + for (i = 0; i < args.abi.outputs.length; i++) { outputTypes.push(args.abi.outputs[i].type); } @@ -466,7 +469,7 @@ UniversalDApp.prototype.getCallButton = function (args) { // format decoded data decodedObj = ethJSABI.stringify(outputTypes, decodedObj); - for (var i = 0; i < outputTypes.length; i++) { + for (i = 0; i < outputTypes.length; i++) { var name = args.abi.outputs[i].name; if (name.length > 0) { decodedObj[i] = outputTypes[i] + ' ' + name + ': ' + decodedObj[i]; From c66af27eb28d8fad6ed60d9bd94e6679db616676 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Jun 2016 20:27:21 +0100 Subject: [PATCH 3/8] Standard: format whitespace (using semistandard-format) --- assets/js/ballot.sol.js | 4 +- background.js | 9 +- src/app.js | 868 ++++++++++++++-------------- src/app/compiler-worker.js | 76 +-- src/app/compiler.js | 24 +- src/app/query-params.js | 4 +- src/app/renderer.js | 30 +- src/app/storage-handler.js | 8 +- src/index.js | 2 +- src/universal-dapp.js | 1117 ++++++++++++++++++------------------ 10 files changed, 1059 insertions(+), 1083 deletions(-) diff --git a/assets/js/ballot.sol.js b/assets/js/ballot.sol.js index c415131fd2..3ce12967c3 100644 --- a/assets/js/ballot.sol.js +++ b/assets/js/ballot.sol.js @@ -22,9 +22,9 @@ * THE SOFTWARE. */ -var multi = function(func) { return func.toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1]; } +var multi = function (func) { return func.toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1]; }; -var BALLOT_EXAMPLE = multi(function(){/*contract Ballot { +var BALLOT_EXAMPLE = multi(function () { /*contract Ballot { struct Voter { uint weight; diff --git a/background.js b/background.js index c8adcda9c7..21df85f296 100644 --- a/background.js +++ b/background.js @@ -1,12 +1,9 @@ /* global chrome */ chrome.browserAction.onClicked.addListener(function (tab) { + chrome.storage.sync.set({ 'chrome-app-sync': true }); - chrome.storage.sync.set({ 'chrome-app-sync' : true }); - - - chrome.tabs.create({ 'url': chrome.extension.getURL('index.html') }, function (tab) { + chrome.tabs.create({ 'url': chrome.extension.getURL('index.html') }, function (tab) { // tab opened - }); - + }); }); diff --git a/src/app.js b/src/app.js index ba9e650f89..decf1ae7cc 100644 --- a/src/app.js +++ b/src/app.js @@ -15,452 +15,442 @@ var Compiler = require('./app/compiler'); var filesToLoad = null; var loadFilesCallback = function (files) { filesToLoad = files; }; // will be replaced later window.addEventListener('message', function (ev) { - if (typeof ev.data === typeof [] && ev.data[0] === 'loadFiles') { - loadFilesCallback(ev.data[1]); - } + if (typeof ev.data === typeof [] && ev.data[0] === 'loadFiles') { + loadFilesCallback(ev.data[1]); + } }, false); var run = function () { - - function loadFiles (files) { - for (var f in files) { - var key = utils.fileKey(f); - var content = files[f].content; - if (key in window.localStorage && window.localStorage[key] !== content) { - var count = ''; - var otherKey = key + count; - while ((key + count) in window.localStorage) count = count - 1; - window.localStorage[key + count] = window.localStorage[key]; - } - window.localStorage[key] = content; - } - editor.setCacheFile(Object.keys(files)[0]); - updateFiles(); - } - - loadFilesCallback = function (files) { - loadFiles(files); - }; - - if (filesToLoad !== null) { - loadFiles(filesToLoad); + function loadFiles (files) { + for (var f in files) { + var key = utils.fileKey(f); + var content = files[f].content; + if (key in window.localStorage && window.localStorage[key] !== content) { + var count = ''; + var otherKey = key + count; + while ((key + count) in window.localStorage) count = count - 1; + window.localStorage[key + count] = window.localStorage[key]; + } + window.localStorage[key] = content; + } + editor.setCacheFile(Object.keys(files)[0]); + updateFiles(); + } + + loadFilesCallback = function (files) { + loadFiles(files); + }; + + if (filesToLoad !== null) { + loadFiles(filesToLoad); + } + + // ------------------ query params (hash) ---------------- + + function syncQueryParams () { + $('#optimize').attr('checked', (queryParams.get().optimize === 'true')); + } + + window.onhashchange = syncQueryParams; + syncQueryParams(); + + // -------- check file upload capabilities ------- + + if (!(window.File || window.FileReader || window.FileList || window.Blob)) { + $(".uploadFile").remove(); + } + + // ------------------ gist load ---------------- + + var loadingFromGist = gistHandler.handleLoad(function (gistId) { + $.ajax({ + url: 'https://api.github.com/gists/' + gistId, + jsonp: 'callback', + dataType: 'jsonp', + success: function (response) { + if (response.data) { + if (!response.data.files) { + alert('Gist load error: ' + response.data.message); + return; + } + loadFiles(response.data.files); } - - - // ------------------ query params (hash) ---------------- - - function syncQueryParams () { - $('#optimize').attr('checked', (queryParams.get().optimize === 'true')); - } - - window.onhashchange = syncQueryParams; - syncQueryParams(); - - // -------- check file upload capabilities ------- - if (!(window.File || window.FileReader || window.FileList || window.Blob)) { - $(".uploadFile").remove(); - } - - // ------------------ gist load ---------------- - - var loadingFromGist = gistHandler.handleLoad(function (gistId) { - $.ajax({ - url: 'https://api.github.com/gists/' + gistId, - jsonp: 'callback', - dataType: 'jsonp', - success: function (response) { - if (response.data) { - if (!response.data.files) { - alert('Gist load error: ' + response.data.message); - return; - } - loadFiles(response.data.files); - } - } + } + }); + }); + + // ----------------- storage -------------------- + + var storageHandler = new StorageHandler(updateFiles); + window.syncStorage = storageHandler.sync; + storageHandler.sync(); + + // ----------------- editor ---------------------- + + var editor = new Editor(loadingFromGist); + + // ----------------- tabbed menu ------------------- + + $('#options li').click(function (ev) { + var $el = $(this); + var match = /[a-z]+View/.exec($el.get(0).className); + if (!match) return; + var cls = match[0]; + if (!$el.hasClass('active')) { + $el.parent().find('li').removeClass('active'); + $('#optionViews').attr('class', '').addClass(cls); + $el.addClass('active'); + } else { + $el.removeClass('active'); + $('#optionViews').removeClass(cls); + } + }); + + // ------------------ gist publish -------------- + + $('#gist').click(function () { + if (confirm('Are you sure you want to publish all your files anonymously as a public gist on github.com?')) { + var files = editor.packageFiles(); + var description = 'Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. \n Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=' + queryParams.get().version + '&optimize=' + queryParams.get().optimize + '&gist='; + + $.ajax({ + url: 'https://api.github.com/gists', + type: 'POST', + data: JSON.stringify({ + description: description, + public: true, + files: files + }) + }).done(function (response) { + if (response.html_url && confirm('Created a gist at ' + response.html_url + ' Would you like to open it in a new window?')) { + window.open(response.html_url, '_blank'); + } + }); + } + }); + + $('#copyOver').click(function () { + var target = prompt( + 'To which other browser-solidity instance do you want to copy over all files?', + 'https://ethereum.github.io/browser-solidity/' + ); + if (target === null) { + return; + } + var files = editor.packageFiles(); + var iframe = $('