diff --git a/js/controllers/setup.js b/js/controllers/setup.js index 4f49dcb96..bdc9d8a49 100644 --- a/js/controllers/setup.js +++ b/js/controllers/setup.js @@ -84,7 +84,7 @@ angular.module('copayApp.controllers').controller('SetupController', passphrase: passphrase, }; var w = walletFactory.create(opts); - controllerUtils.startNetwork(w); + controllerUtils.startNetwork(w, $scope); }); }; diff --git a/js/controllers/signin.js b/js/controllers/signin.js index 86468b1f1..2c522efba 100644 --- a/js/controllers/signin.js +++ b/js/controllers/signin.js @@ -34,8 +34,7 @@ angular.module('copayApp.controllers').controller('SigninController', $rootScope.$digest(); return; } - installStartupHandlers(w); - controllerUtils.startNetwork(w); + controllerUtils.startNetwork(w, $scope); }); }; @@ -65,25 +64,9 @@ angular.module('copayApp.controllers').controller('SigninController', $rootScope.$flashMessage = { message: 'Unknown error', type: 'error'}; controllerUtils.onErrorDigest(); } else { - controllerUtils.startNetwork(w); - installStartupHandlers(w); + controllerUtils.startNetwork(w, $scope); } }); }); - }; - - function installStartupHandlers(wallet) { - wallet.on('serverError', function(msg) { - $rootScope.$flashMessage = { - message: 'There was an error connecting to the PeerJS server.' - +(msg||'Check you settings and Internet connection.'), - type: 'error', - }; - controllerUtils.onErrorDigest($scope); - }); - wallet.on('ready', function() { - $scope.loading = false; - }); } - }); diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index d0ce6bfbf..1c75d32d3 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -39,9 +39,37 @@ angular.module('copayApp.services') message: msg }; $rootScope.$digest(); - } + }; + + root.installStartupHandlers = function(wallet, $scope) { + wallet.on('serverError', function(msg) { + $rootScope.$flashMessage = { + message: 'There was an error connecting to the PeerJS server.' + +(msg||'Check you settings and Internet connection.'), + type: 'error', + }; + root.onErrorDigest($scope); + $location.path('addresses'); + }); + wallet.on('connectionError', function() { + var message = "Looks like you are already connected to this wallet, please logout from it and try importing it again."; + $rootScope.$flashMessage = { message: message, type: 'error'}; + root.onErrorDigest($scope); + }); + wallet.on('serverError', function() { + $rootScope.$flashMessage = { message: 'The PeerJS server is not responding, please try again', type: 'error'}; + root.onErrorDigest($scope); + }); + wallet.on('ready', function() { + $scope.loading = false; + }); + }; + + + root.startNetwork = function(w, $scope) { + + root.installStartupHandlers(w, $scope); - root.startNetwork = function(w) { var handlePeerVideo = function(err, peerID, url) { if (err) { delete $rootScope.videoInfo[peerID];