From 35fc682abe64e9a6c2945cec9b0791a14b1d997b Mon Sep 17 00:00:00 2001 From: Chris Dukakis Date: Sun, 26 Nov 2017 00:54:11 +0200 Subject: [PATCH] prevent crash if ccurl is not supported --- app/js/ccurl-interface.js | 8 +++++--- ui/js/ui.init.js | 13 ++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/js/ccurl-interface.js b/app/js/ccurl-interface.js index 22cfc3c8..f7e3bef6 100644 --- a/app/js/ccurl-interface.js +++ b/app/js/ccurl-interface.js @@ -69,8 +69,10 @@ var ccurlInterruptAndFinalize = function(libccurl) { } var ccurlHashing = function(libccurl, trunkTransaction, branchTransaction, minWeightMagnitude, trytes, callback) { - if (!libccurl.hasOwnProperty("ccurl_pow")) { - return callback(new Error("Hashing not available")); + var ccurlPoW = connection.ccurl + + if (!libccurl || !libccurl.hasOwnProperty("ccurl_pow")) { + ccurlPoW = 0 } var iotaObj = iota; @@ -165,7 +167,7 @@ var ccurlHashing = function(libccurl, trunkTransaction, branchTransaction, minWe var newTrytes = iotaObj.utils.transactionTrytes(txObject); - switch (connection.ccurl) { + switch (ccurlPoW) { case 0: { libcurl.pow({trytes: newTrytes, minWeight: minWeightMagnitude}).then(function(nonce) { var returnedTrytes = newTrytes.substr(0, 2673-81).concat(nonce); diff --git a/ui/js/ui.init.js b/ui/js/ui.init.js index 86bbace4..2d0909c3 100644 --- a/ui/js/ui.init.js +++ b/ui/js/ui.init.js @@ -122,12 +122,15 @@ var UI = (function(UI, $, undefined) { console.log("..."); } showLightWalletErrorMessage(); - return; + connection.ccurlProvider = null } else { - connection.ccurlProvider = ccurl.ccurlProvider(connection.ccurlPath); - if (!connection.ccurlProvider) { - console.log("Did not get ccurlProvider from " + connection.ccurlPath); - return; + try { + connection.ccurlProvider = ccurl.ccurlProvider(connection.ccurlPath); + if (!connection.ccurlProvider) { + console.log("Did not get ccurlProvider from " + connection.ccurlPath); + } + } catch (err) { + connection.ccurlProvider = null } } // Overwrite iota lib with light wallet functionality