diff --git a/js/controllers/home.js b/js/controllers/home.js index 576cc5f7c..6ca571481 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -1,10 +1,9 @@ 'use strict'; angular.module('copayApp.controllers').controller('HomeController', - function($scope, $rootScope, $location, walletFactory, notification) { - if ($rootScope.wallet) { - $location.path('/addresses'); - } + function($scope, $rootScope, $location, walletFactory, notification, controllerUtils) { + + controllerUtils.redirIfLogged(); $scope.loading = false; if ($rootScope.pendingPayment) { diff --git a/js/controllers/import.js b/js/controllers/import.js index ab6107db9..f978884cd 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -2,9 +2,8 @@ angular.module('copayApp.controllers').controller('ImportController', function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase, notification) { - if ($rootScope.wallet) { - $location.path('/addresses'); - } + + controllerUtils.redirIfLogged(); $scope.title = 'Import a backup'; $scope.importStatus = 'Importing wallet - Reading backup...'; diff --git a/js/controllers/join.js b/js/controllers/join.js index 015be9534..bfc09fb8a 100644 --- a/js/controllers/join.js +++ b/js/controllers/join.js @@ -2,10 +2,8 @@ angular.module('copayApp.controllers').controller('JoinController', function($scope, $rootScope, $timeout, $location, walletFactory, controllerUtils, Passphrase, notification) { - if ($rootScope.wallet) { - $location.path('/addresses'); - } + controllerUtils.redirIfLogged(); $scope.loading = false; // QR code Scanner diff --git a/js/controllers/open.js b/js/controllers/open.js index 124955800..2ca4ae03a 100644 --- a/js/controllers/open.js +++ b/js/controllers/open.js @@ -2,9 +2,7 @@ angular.module('copayApp.controllers').controller('OpenController', function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase, notification) { - if ($rootScope.wallet) { - $location.path('/addresses'); - } + controllerUtils.redirIfLogged(); var cmp = function(o1, o2) { var v1 = o1.show.toLowerCase(), diff --git a/js/controllers/settings.js b/js/controllers/settings.js index dc2b582d9..a3ab1241e 100644 --- a/js/controllers/settings.js +++ b/js/controllers/settings.js @@ -2,10 +2,8 @@ angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $location) { - if ($rootScope.wallet) { - $location.path('/addresses'); - } + controllerUtils.redirIfLogged(); $scope.title = 'Settings'; $scope.networkName = config.networkName; $scope.insightHost = config.blockchain.host; diff --git a/js/controllers/setup.js b/js/controllers/setup.js index 392a01253..f14dafdb7 100644 --- a/js/controllers/setup.js +++ b/js/controllers/setup.js @@ -34,9 +34,7 @@ var valid_pairs = { angular.module('copayApp.controllers').controller('SetupController', function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase, backupService, notification) { - if ($rootScope.wallet) { - $location.path('/addresses'); - } + controllerUtils.redirIfLogged(); $rootScope.videoInfo = {}; $scope.loading = false; diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index 57a5faa13..49c9840e1 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -14,6 +14,13 @@ angular.module('copayApp.services') return vi.muted; }; + root.redirIfLogged = function() { + var w = $rootScope.wallet; + if (w) { + $location.path('addresses'); + } + }; + root.logout = function() { Socket.removeAllListeners();