From 4245d63bbba5fe3e0978ad8430f18b42420b3ef3 Mon Sep 17 00:00:00 2001 From: Andy Nogueira Date: Fri, 17 Mar 2017 10:10:05 -0400 Subject: [PATCH] Improved demo app code to better handle the IPFS storage connection based on the new EmbarkJS refactoring. The old code is stillcompatible with the refactored EmbarkJS code --- demo/app/js/index.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/demo/app/js/index.js b/demo/app/js/index.js index fe7ac8cf..2db14830 100644 --- a/demo/app/js/index.js +++ b/demo/app/js/index.js @@ -32,18 +32,28 @@ $(document).ready(function() { //EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'}); $("#storage .error").hide(); - EmbarkJS.Storage.ipfsConnection.ping() + EmbarkJS.Storage.setProvider('ipfs') .then(function(){ - $("#status-storage").addClass('status-online'); - $("#storage-controls").show(); + 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) { - 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() {