@@ -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