From 18d6aafd601d13558aa3d86ba3eac058bf38c2d9 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 13 Dec 2017 17:36:24 -0500 Subject: [PATCH] update test_app files --- test_app/app/index.html | 2 + test_app/app/js/index.js | 32 ++++--- test_app/app/js/new_index.js | 164 ----------------------------------- test_app/app/new_index.html | 109 ----------------------- test_app/embark.json | 5 +- 5 files changed, 24 insertions(+), 288 deletions(-) delete mode 100644 test_app/app/js/new_index.js delete mode 100644 test_app/app/new_index.html diff --git a/test_app/app/index.html b/test_app/app/index.html index 10b27f231..bcd23a083 100644 --- a/test_app/app/index.html +++ b/test_app/app/index.html @@ -2,6 +2,8 @@ Embark - SimpleStorage Demo + + diff --git a/test_app/app/js/index.js b/test_app/app/js/index.js index cbf160911..1ba8d4e2d 100644 --- a/test_app/app/js/index.js +++ b/test_app/app/js/index.js @@ -1,5 +1,14 @@ /*globals $, SimpleStorage, document*/ +import $ from './_vendor/jquery.min'; +import EmbarkJS from 'Embark/EmbarkJS'; +import SimpleStorage from 'Embark/contracts/SimpleStorage'; + +window.EmbarkJS = EmbarkJS; +window.SimpleStorage = SimpleStorage; + +import './foo.css'; + var addToLog = function(id, txt) { $(id + " .logs").append("
" + txt); }; @@ -8,6 +17,7 @@ var addToLog = function(id, txt) { // Blockchain example // =========================== $(document).ready(function() { + console.log([1,2,3].map(v => v + 1)); $("#blockchain button.set").click(function() { var value = parseInt($("#blockchain input.text").val(), 10); @@ -48,19 +58,19 @@ $(document).ready(function() { //EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'}); $("#storage .error").hide(); - EmbarkJS.Storage.ipfsConnection.ping() - .then(function(){ + //EmbarkJS.Storage.ipfsConnection.version() + // .then(function(){ $("#status-storage").addClass('status-online'); $("#storage-controls").show(); - }) - .catch(function(err) { - if(err){ - console.log("IPFS Connection Error => " + err.message); - $("#storage .error").show(); - $("#status-storage").addClass('status-offline'); - $("#storage-controls").hide(); - } - }); + // }) + // .catch(function(err) { + // if(err){ + // console.log("IPFS Connection Error => " + err.message); + // $("#storage .error").show(); + // $("#status-storage").addClass('status-offline'); + // $("#storage-controls").hide(); + // } + // }); $("#storage button.setIpfsText").click(function() { var value = $("#storage input.ipfsText").val(); diff --git a/test_app/app/js/new_index.js b/test_app/app/js/new_index.js deleted file mode 100644 index 0cc24eda9..000000000 --- a/test_app/app/js/new_index.js +++ /dev/null @@ -1,164 +0,0 @@ -/*globals $, SimpleStorage, document*/ - -import $ from './_vendor/jquery.min'; -//import web3 from 'Embark/web3'; -import EmbarkJS from 'Embark/EmbarkJS'; -window.EmbarkJS = EmbarkJS; -import SimpleStorage from 'Embark/contracts/SimpleStorage'; - -import test3 from './foo'; -import './foo.css'; - -var addToLog = function(id, txt) { - $(id + " .logs").append("
" + txt); -}; - -// =========================== -// Blockchain example -// =========================== -$(document).ready(function() { - console.log([1,2,3].map(v => v + 1)); - //alert('hello'); - - $("#blockchain button.set").click(function() { - var value = parseInt($("#blockchain input.text").val(), 10); - - // If web3.js 1.0 is being used - if (EmbarkJS.isNewWeb3()) { - SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount}); - addToLog("#blockchain", "SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount})"); - } else { - SimpleStorage.set(value); - addToLog("#blockchain", "SimpleStorage.set(" + value + ")"); - } - - }); - - $("#blockchain button.get").click(function() { - // If web3.js 1.0 is being used - if (EmbarkJS.isNewWeb3()) { - SimpleStorage.methods.get().call(function(err, value) { - $("#blockchain .value").html(value); - }); - addToLog("#blockchain", "SimpleStorage.methods.get(console.log)"); - } else { - SimpleStorage.get().then(function(value) { - $("#blockchain .value").html(value.toNumber()); - }); - addToLog("#blockchain", "SimpleStorage.get()"); - } - }); - -}); - -// =========================== -// Storage (IPFS) example -// =========================== -$(document).ready(function() { - // automatic set if config/storage.json has "enabled": true and "provider": "ipfs" - //EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'}); - - $("#storage .error").hide(); - //EmbarkJS.Storage.ipfsConnection.version() - // .then(function(){ - $("#status-storage").addClass('status-online'); - $("#storage-controls").show(); - // }) - // .catch(function(err) { - // if(err){ - // console.log("IPFS Connection Error => " + err.message); - // $("#storage .error").show(); - // $("#status-storage").addClass('status-offline'); - // $("#storage-controls").hide(); - // } - // }); - - $("#storage button.setIpfsText").click(function() { - var value = $("#storage input.ipfsText").val(); - EmbarkJS.Storage.saveText(value).then(function(hash) { - $("span.textHash").html(hash); - $("input.textHash").val(hash); - addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })"); - }) - .catch(function(err) { - if(err){ - console.log("IPFS saveText Error => " + err.message); - } - }); - }); - - $("#storage button.loadIpfsHash").click(function() { - var value = $("#storage input.textHash").val(); - EmbarkJS.Storage.get(value).then(function(content) { - $("span.ipfsText").html(content); - addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })"); - }) - .catch(function(err) { - if(err){ - console.log("IPFS get Error => " + err.message); - } - }); - }); - - $("#storage button.uploadFile").click(function() { - var input = $("#storage input[type=file]"); - EmbarkJS.Storage.uploadFile(input).then(function(hash) { - $("span.fileIpfsHash").html(hash); - $("input.fileIpfsHash").val(hash); - addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })"); - }) - .catch(function(err) { - if(err){ - console.log("IPFS uploadFile Error => " + err.message); - } - }); - }); - - $("#storage button.loadIpfsFile").click(function() { - var hash = $("#storage input.fileIpfsHash").val(); - var url = EmbarkJS.Storage.getUrl(hash); - var link = '' + url + ''; - $("span.ipfsFileUrl").html(link); - $(".ipfsImage").attr('src', url); - addToLog("#storage", "EmbarkJS.Storage.getUrl('" + hash + "')"); - }); - -}); - -// =========================== -// Communication (Whisper) example -// =========================== -$(document).ready(function() { - - $("#communication .error").hide(); - $("#communication .errorVersion").hide(); - if (EmbarkJS.Messages.providerName === 'whisper') { - EmbarkJS.Messages.getWhisperVersion(function(err, version) { - if (err) { - $("#communication .error").show(); - $("#communication-controls").hide(); - $("#status-communication").addClass('status-offline'); - } else { - EmbarkJS.Messages.setProvider('whisper'); - $("#status-communication").addClass('status-online'); - } - }); - } - - $("#communication button.listenToChannel").click(function() { - var channel = $("#communication .listen input.channel").val(); - $("#communication #subscribeList").append("
subscribed to " + channel + " now try sending a message"); - EmbarkJS.Messages.listenTo({topic: [channel]}).then(function(message) { - $("#communication #messagesList").append("
channel: " + channel + " message: " + message); - }); - addToLog("#communication", "EmbarkJS.Messages.listenTo({topic: ['" + channel + "']}).then(function(message) {})"); - }); - - $("#communication button.sendMessage").click(function() { - var channel = $("#communication .send input.channel").val(); - var message = $("#communication .send input.message").val(); - EmbarkJS.Messages.sendMessage({topic: channel, data: message}); - addToLog("#communication", "EmbarkJS.Messages.sendMessage({topic: '" + channel + "', data: '" + message + "'})"); - }); - -}); diff --git a/test_app/app/new_index.html b/test_app/app/new_index.html deleted file mode 100644 index 8d672cef1..000000000 --- a/test_app/app/new_index.html +++ /dev/null @@ -1,109 +0,0 @@ - - - Embark - SimpleStorage Demo - - - - - - -

Embark - Usage Example

- - - -
-
-

1. Set the value in the blockchain

-
- - -

Once you set the value, the transaction will need to be mined and then the value will be updated on the blockchain.

-
- -

2. Get the current value

-
-
- current value is -
- -

Click the button to get the current value. The initial value is 100.

-
- -

3. Contract Calls

-

Javascript calls being made:

-
-
-
-
- -
- -

Save text to IPFS

-
- - -

generated Hash:

-
- -

Load text from IPFS given an hash

-
- - -

result:

-
- -

upload file to ipfs

-
- - -

generated hash:

-
- -

Get file or image from ipfs

-
- - -

file available at:

-

-
- -

Javascript calls being made:

-
-
EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'}) -
-
-
-
- - -
-

Listen To channel

-
- - -
-

messages received:

-

-
- -

Send Message

-
- - - -
- -

Javascript calls being made:

-
-
EmbarkJS.Messages.setProvider('whisper') -
-
-
-
- - - diff --git a/test_app/embark.json b/test_app/embark.json index bc7382414..116e6d6fd 100644 --- a/test_app/embark.json +++ b/test_app/embark.json @@ -1,16 +1,13 @@ { "contracts": ["app/contracts/**"], "app": { - "js/webpack_test.js": "app/js/index.js", "js/jquery.js": "app/js/_vendor/jquery.min.js", "js/bootstrap.js": "app/js/_vendor/bootstrap.min.js", "css/app.css": ["app/css/**"], "images/": ["app/images/**"], - "js/app.js": ["app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**", "!app/js/test.js", "!app/js/foo.js", "!app/js/foo.css", "!app/js/new_index.js"], - "js/new_app.js": ["app/js/new_index.js"], + "js/app.js": ["app/js/index.js"], "js/test.js": ["app/js/_vendor/jquery.min.js", "app/js/_vendor/async.min.js", "app/js/test.js"], "index.html": "app/index.html", - "new_index.html": "app/new_index.html", "test.html": "app/test.html", "test2.html": "app/test2.html" },