From d9e615453c9d21e7835c0ce6c94b616e39aa5073 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 27 Jun 2017 16:01:54 -0400 Subject: [PATCH] update demo and test app; warn about whisper version --- demo/app/js/index.js | 6 +++- test_app/app/css/main.css | 24 ++++++++++++++ test_app/app/index.html | 16 +++++---- test_app/app/js/index.js | 70 +++++++++++++++++++++++++++++++++------ 4 files changed, 97 insertions(+), 19 deletions(-) diff --git a/demo/app/js/index.js b/demo/app/js/index.js index 2db14830..7799a2f1 100644 --- a/demo/app/js/index.js +++ b/demo/app/js/index.js @@ -114,11 +114,15 @@ $(document).ready(function() { $(document).ready(function() { $("#communication .error").hide(); - web3.version.getWhisper(function(err, res) { + web3.version.getWhisper(function(err, version) { if (err) { $("#communication .error").show(); $("#communication-controls").hide(); $("#status-communication").addClass('status-offline'); + } else if (version >= 5) { + $("#communication .errorVersion").show(); + $("#communication-controls").hide(); + $("#status-communication").addClass('status-offline'); } else { EmbarkJS.Messages.setProvider('whisper'); $("#status-communication").addClass('status-online'); diff --git a/test_app/app/css/main.css b/test_app/app/css/main.css index abfcd67f..bdec3790 100644 --- a/test_app/app/css/main.css +++ b/test_app/app/css/main.css @@ -24,3 +24,27 @@ div { margin-bottom: 0; } +.status-offline { + vertical-align: middle; + margin-left: 5px; + margin-top: 4px; + width: 12px; + height: 12px; + background: red; + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + border-radius: 10px; +} + +.status-online { + vertical-align: middle; + margin-left: 5px; + margin-top: 4px; + width: 12px; + height: 12px; + background: mediumseagreen; + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + border-radius: 10px; +} + diff --git a/test_app/app/index.html b/test_app/app/index.html index 417f6096..10b27f23 100644 --- a/test_app/app/index.html +++ b/test_app/app/index.html @@ -9,8 +9,8 @@
@@ -37,7 +37,8 @@
- note: You need to have an IPFS node running + +

Save text to IPFS

@@ -72,11 +73,12 @@

EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'})
- +
- The node you are using does not support whisper - + + +

Listen To channel

@@ -97,7 +99,7 @@

EmbarkJS.Messages.setProvider('whisper')
- +
diff --git a/test_app/app/js/index.js b/test_app/app/js/index.js index 27416e49..72e335b3 100644 --- a/test_app/app/js/index.js +++ b/test_app/app/js/index.js @@ -28,23 +28,59 @@ $(document).ready(function() { // 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.setProvider('ipfs') + .then(function(){ + console.log('Provider set to IPFS'); + EmbarkJS.Storage.ipfsConnection.ping() + .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){ + console.log('Failed to set IPFS as Provider:', 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); + } }); - addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })"); }); $("#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); + } }); - addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })"); }); $("#storage button.uploadFile").click(function() { @@ -52,8 +88,13 @@ $(document).ready(function() { 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); + } }); - addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })"); }); $("#storage button.loadIpfsFile").click(function() { @@ -73,13 +114,21 @@ $(document).ready(function() { $(document).ready(function() { $("#communication .error").hide(); - //web3.version.getWhisper(function(err, res) { - // if (err) { - // $("#communication .error").show(); - // } else { - // EmbarkJS.Messages.setProvider('whisper'); - // } - //}); + $("#communication .errorVersion").hide(); + web3.version.getWhisper(function(err, version) { + if (err) { + $("#communication .error").show(); + $("#communication-controls").hide(); + $("#status-communication").addClass('status-offline'); + } else if (version >= 5) { + $("#communication .errorVersion").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(); @@ -98,4 +147,3 @@ $(document).ready(function() { }); }); -