diff --git a/bower.json b/bower.json index 977836dc4..fbb7cb541 100644 --- a/bower.json +++ b/bower.json @@ -19,6 +19,7 @@ "file-saver": "*", "qrcode-decoder-js": "*", "bitcore": "~0.1.19", - "angular-moment": "~0.7.1" + "angular-moment": "~0.7.1", + "socket.io-client": ">=1.0.0" } } diff --git a/index.html b/index.html index fc5d3ecb9..18c0a0585 100644 --- a/index.html +++ b/index.html @@ -82,6 +82,16 @@ +
+
+
+ Error connecting to Insight server. Check + you settings and Internet connection. + Trying to reconnect... +
+
+
+
@@ -782,7 +792,7 @@ on supported browsers please check http://www.w - + diff --git a/js/controllers/header.js b/js/controllers/header.js index c33362952..a93b344ce 100644 --- a/js/controllers/header.js +++ b/js/controllers/header.js @@ -33,14 +33,28 @@ angular.module('copayApp.controllers').controller('HeaderController', } }); + // Initialize alert notification (not show when init wallet) $rootScope.txAlertCount = 0; - $rootScope.$watch('txAlertCount', function(txAlertCount) { - if (txAlertCount && txAlertCount > 0) { - $notification.info('New Transaction', ($rootScope.txAlertCount == 1) ? 'You have a pending transaction proposal' : 'You have ' + $rootScope.txAlertCount + ' pending transaction proposals', txAlertCount); - } + + $rootScope.$watch('blockChainStatus', function(status) { + var h = config.blockchain.host + ':' + config.blockchain.port; + if (status === 'error') + $rootScope.insightError = 1; + else + if (status === 'restored') { + $rootScope.insightError = 0; + $rootScope.$flashMessage = { + type: 'success', + message: 'Networking Restored', + }; + } }); + + // Init socket handlers (with no wallet yet) + controllerUtils.setSocketHandlers(); + $rootScope.$watch('receivedFund', function(receivedFund) { if (receivedFund) { var currentAddr; @@ -59,6 +73,14 @@ angular.module('copayApp.controllers').controller('HeaderController', } }); + $rootScope.$watch('txAlertCount', function(txAlertCount) { + if (txAlertCount && txAlertCount > 0) { + $notification.info('New Transaction', ($rootScope.txAlertCount == 1) ? 'You have a pending transaction proposal' : 'You have ' + $rootScope.txAlertCount + ' pending transaction proposals', txAlertCount); + } + }); + + + $scope.isActive = function(item) { if (item.link && item.link.replace('#','') == $location.path()) { return true; diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index e65e8c62a..013ede6b1 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -174,12 +174,30 @@ angular.module('copayApp.services') $rootScope.pendingTxCount = pendingForUs; }; + root._setCommError = function(e) { + $rootScope.blockChainStatus='error'; + }; + + + root._clearCommError = function(e) { + if ($rootScope.blockChainStatus==='error') + $rootScope.blockChainStatus='restored'; + }; + root.setSocketHandlers = function() { + if (!Socket.sysEventsSet) { + Socket.sysOn('error', root._setCommError); + Socket.sysOn('reconnect_error', root._setCommError); + Socket.sysOn('reconnect_failed', root._setCommError); + Socket.sysOn('connect', root._clearCommError); + Socket.sysOn('reconnect', root._clearCommError); + Socket.sysEventsSet=true; + } if (!$rootScope.wallet) return; var currentAddrs= Socket.getListeners(); var addrs = $rootScope.wallet.getAddressesStr(); - + var newAddrs=[]; for(var i in addrs){ var a=addrs[i]; diff --git a/js/services/notifications.js b/js/services/notifications.js index f38a370e6..c37aee391 100644 --- a/js/services/notifications.js +++ b/js/services/notifications.js @@ -10,7 +10,7 @@ angular.module('notifications', []). info: { duration: 5000, enabled: true }, funds: { duration: 5000, enabled: true }, warning: { duration: 5000, enabled: true }, - error: { duration: 5000, enabled: true }, + error: { duration: 1e10, enabled: true }, success: { duration: 5000, enabled: true }, progress: { duration: 0, enabled: true }, custom: { duration: 35000, enabled: true }, diff --git a/js/services/socket.js b/js/services/socket.js index 1642309c2..54609a3c9 100644 --- a/js/services/socket.js +++ b/js/services/socket.js @@ -4,9 +4,9 @@ angular.module('copayApp.services').factory('Socket', function($rootScope) { var listeners = []; var url = 'http://' + config.socket.host + ':' + config.socket.port; - var socket = io.connect(url, { - 'reconnect': true, - 'reconnection delay': 500, + var socket = io(url, { + 'reconnection': true, + 'reconnectionDelay': 500, }); return { @@ -17,7 +17,6 @@ angular.module('copayApp.services').factory('Socket', callback.apply(socket, args); }); }; - socket.on(event, wrappedCallback); if (event !== 'connect') { listeners.push({ @@ -26,9 +25,21 @@ angular.module('copayApp.services').factory('Socket', }); } }, + sysOn: function(event, callback) { + var wrappedCallback = function() { + var args = arguments; + $rootScope.$apply(function() { + callback.apply(socket, args); + }); + }; + socket.io.on(event, wrappedCallback); + }, getListeners: function() { var ret = {}; - var addrList = listeners.map(function(i) {return i.event;}); + + var addrList = listeners + .map(function(i) {return i.event;}); + for (var i in addrList) { ret[addrList[i]] = 1; }