Skip to content

Commit d9e6154

Browse files
committed
update demo and test app; warn about whisper version
1 parent cbf6f6e commit d9e6154

File tree

4 files changed

+97
-19
lines changed

4 files changed

+97
-19
lines changed

demo/app/js/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,15 @@ $(document).ready(function() {
114114
$(document).ready(function() {
115115

116116
$("#communication .error").hide();
117-
web3.version.getWhisper(function(err, res) {
117+
web3.version.getWhisper(function(err, version) {
118118
if (err) {
119119
$("#communication .error").show();
120120
$("#communication-controls").hide();
121121
$("#status-communication").addClass('status-offline');
122+
} else if (version >= 5) {
123+
$("#communication .errorVersion").show();
124+
$("#communication-controls").hide();
125+
$("#status-communication").addClass('status-offline');
122126
} else {
123127
EmbarkJS.Messages.setProvider('whisper');
124128
$("#status-communication").addClass('status-online');

test_app/app/css/main.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,27 @@ div {
2424
margin-bottom: 0;
2525
}
2626

27+
.status-offline {
28+
vertical-align: middle;
29+
margin-left: 5px;
30+
margin-top: 4px;
31+
width: 12px;
32+
height: 12px;
33+
background: red;
34+
-moz-border-radius: 10px;
35+
-webkit-border-radius: 10px;
36+
border-radius: 10px;
37+
}
38+
39+
.status-online {
40+
vertical-align: middle;
41+
margin-left: 5px;
42+
margin-top: 4px;
43+
width: 12px;
44+
height: 12px;
45+
background: mediumseagreen;
46+
-moz-border-radius: 10px;
47+
-webkit-border-radius: 10px;
48+
border-radius: 10px;
49+
}
50+

test_app/app/index.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ <h3>Embark - Usage Example</h3>
99

1010
<ul class="nav nav-tabs" role="tablist" id="myTabs">
1111
<li role="presentation" class="active"><a href="#blockchain" aria-controls="blockchain" role="tab" data-toggle="tab">Blockchain</a></li>
12-
<li role="presentation"><a href="#storage" aria-controls="storage" role="tab" data-toggle="tab">Decentralized Storage (IPFS)</a></li>
13-
<li role="presentation"><a href="#communication" aria-controls="communication" role="tab" data-toggle="tab">P2P communication (whisper/orbit)</a></li>
12+
<li role="presentation"><a href="#storage" aria-controls="storage" role="tab" data-toggle="tab">Decentralized Storage (IPFS)<span class="pull-right" id="status-storage"></a></li>
13+
<li role="presentation"><a href="#communication" aria-controls="communication" role="tab" data-toggle="tab">P2P communication (Whisper/Orbit)<span class="pull-right" id="status-communication"></span></a></li>
1414
</ul>
1515

1616
<div class="tab-content">
@@ -37,7 +37,8 @@ <h3> 3. Contract Calls </h3>
3737
</div>
3838
</div>
3939
<div role="tabpanel" class="tab-pane" id="storage">
40-
note: You need to have an IPFS node running
40+
<div class="error alert alert-danger" role="alert">The node you are using does not support IPFS. Please ensure <a href="https://github.com/ipfs/js-ipfs-api#cors" target="_blank">CORS</a> is setup for the IPFS node.</div>
41+
<div id="storage-controls">
4142

4243
<h3>Save text to IPFS</h3>
4344
<div class="form-group form-inline">
@@ -72,11 +73,12 @@ <h3>Get file or image from ipfs</h3>
7273
<div class="logs">
7374
<br> EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'})
7475
</div>
75-
76+
</div>
7677
</div>
7778
<div role="tabpanel" class="tab-pane" id="communication">
78-
<span class="error">The node you are using does not support whisper</span>
79-
79+
<div class="error alert alert-danger" role="alert">The node you are using does not support Whisper</div>
80+
<div class="errorVersion alert alert-danger" role="alert">The node uses an unsupported version of Whisper</div>
81+
<div id="communication-controls">
8082
<h3>Listen To channel</h3>
8183
<div class="form-group form-inline listen">
8284
<input type="text" class="channel text form-control" placeholder="channel">
@@ -97,7 +99,7 @@ <h3>Send Message</h3>
9799
<div class="logs">
98100
<br> EmbarkJS.Messages.setProvider('whisper')
99101
</div>
100-
102+
</div>
101103
</div>
102104
</div>
103105

test_app/app/js/index.js

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,73 @@ $(document).ready(function() {
2828
// Storage (IPFS) example
2929
// ===========================
3030
$(document).ready(function() {
31+
// automatic set if config/storage.json has "enabled": true and "provider": "ipfs"
3132
//EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
3233

34+
$("#storage .error").hide();
35+
EmbarkJS.Storage.setProvider('ipfs')
36+
.then(function(){
37+
console.log('Provider set to IPFS');
38+
EmbarkJS.Storage.ipfsConnection.ping()
39+
.then(function(){
40+
$("#status-storage").addClass('status-online');
41+
$("#storage-controls").show();
42+
})
43+
.catch(function(err) {
44+
if(err){
45+
console.log("IPFS Connection Error => " + err.message);
46+
$("#storage .error").show();
47+
$("#status-storage").addClass('status-offline');
48+
$("#storage-controls").hide();
49+
}
50+
});
51+
})
52+
.catch(function(err){
53+
console.log('Failed to set IPFS as Provider:', err.message);
54+
$("#storage .error").show();
55+
$("#status-storage").addClass('status-offline');
56+
$("#storage-controls").hide();
57+
});
58+
3359
$("#storage button.setIpfsText").click(function() {
3460
var value = $("#storage input.ipfsText").val();
3561
EmbarkJS.Storage.saveText(value).then(function(hash) {
3662
$("span.textHash").html(hash);
3763
$("input.textHash").val(hash);
64+
addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })");
65+
})
66+
.catch(function(err) {
67+
if(err){
68+
console.log("IPFS saveText Error => " + err.message);
69+
}
3870
});
39-
addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })");
4071
});
4172

4273
$("#storage button.loadIpfsHash").click(function() {
4374
var value = $("#storage input.textHash").val();
4475
EmbarkJS.Storage.get(value).then(function(content) {
4576
$("span.ipfsText").html(content);
77+
addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })");
78+
})
79+
.catch(function(err) {
80+
if(err){
81+
console.log("IPFS get Error => " + err.message);
82+
}
4683
});
47-
addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })");
4884
});
4985

5086
$("#storage button.uploadFile").click(function() {
5187
var input = $("#storage input[type=file]");
5288
EmbarkJS.Storage.uploadFile(input).then(function(hash) {
5389
$("span.fileIpfsHash").html(hash);
5490
$("input.fileIpfsHash").val(hash);
91+
addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })");
92+
})
93+
.catch(function(err) {
94+
if(err){
95+
console.log("IPFS uploadFile Error => " + err.message);
96+
}
5597
});
56-
addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })");
5798
});
5899

59100
$("#storage button.loadIpfsFile").click(function() {
@@ -73,13 +114,21 @@ $(document).ready(function() {
73114
$(document).ready(function() {
74115

75116
$("#communication .error").hide();
76-
//web3.version.getWhisper(function(err, res) {
77-
// if (err) {
78-
// $("#communication .error").show();
79-
// } else {
80-
// EmbarkJS.Messages.setProvider('whisper');
81-
// }
82-
//});
117+
$("#communication .errorVersion").hide();
118+
web3.version.getWhisper(function(err, version) {
119+
if (err) {
120+
$("#communication .error").show();
121+
$("#communication-controls").hide();
122+
$("#status-communication").addClass('status-offline');
123+
} else if (version >= 5) {
124+
$("#communication .errorVersion").show();
125+
$("#communication-controls").hide();
126+
$("#status-communication").addClass('status-offline');
127+
} else {
128+
EmbarkJS.Messages.setProvider('whisper');
129+
$("#status-communication").addClass('status-online');
130+
}
131+
});
83132

84133
$("#communication button.listenToChannel").click(function() {
85134
var channel = $("#communication .listen input.channel").val();
@@ -98,4 +147,3 @@ $(document).ready(function() {
98147
});
99148

100149
});
101-

0 commit comments

Comments
 (0)