diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index a7fc1c4b4..18f2eee90 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -5,7 +5,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r var SOFT_CONFIRMATION_LIMIT = 12; self.isCordova = isCordova; self.isChromeApp = isChromeApp; - self.pushDeviceType = isMobile.iOS() || isMobile.Android(); + self.usePushNotifications = isMobile.iOS() || isMobile.Android(); self.isSafari = isMobile.Safari(); self.onGoingProcess = {}; self.historyShowLimit = 10; @@ -13,13 +13,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.prevState = 'walletHome'; document.addEventListener('deviceready', function() { - if (self.pushDeviceType) { - storageService.getDeviceToken(function(err, token) { - $timeout(function() { - if (!token) pushNotificationsService.pushNotificationsInit(); - }, 5000); - }); - } + if (!self.usePushNotifications) return; + + storageService.getDeviceToken(function(err, token) { + $timeout(function() { + if (!token) pushNotificationsService.pushNotificationsInit(); + }, 5000); + }); }); function strip(number) { @@ -1286,12 +1286,15 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); $rootScope.$on('Local/SubscribeNotifications', function(event) { - if (self.pushDeviceType) { - pushNotificationsService.enableNotifications(); - } + if (!self.usePushNotifications) return; + + pushNotificationsService.enableNotifications(); + }); $rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId, cb) { + if (self.usePushNotifications) return cb(); + pushNotificationsService.unsubscribe(walletId, function(err, response) { if (err) $log.warn('Error: ' + err.code); $log.debug('Unsubscribed: ' + response); diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js index d53de26fc..7f17b024e 100644 --- a/src/js/services/pushNotificationsService.js +++ b/src/js/services/pushNotificationsService.js @@ -3,8 +3,11 @@ angular.module('copayApp.services') .factory('pushNotificationsService', function($http, $log, isMobile, profileService, storageService, configService, lodash) { var root = {}; var defaults = configService.getDefaults(); + var usePushNotifications = isMobile.iOS() || isMobile.Android(); root.pushNotificationsInit = function() { + if (!usePushNotifications) return; + var push = PushNotification.init(defaults.pushNotifications.config); push.on('registration', function(data) { @@ -31,6 +34,8 @@ angular.module('copayApp.services') }; root.enableNotifications = function() { + if (!usePushNotifications) return; + storageService.getDeviceToken(function(err, token) { lodash.forEach(profileService.getWallets('testnet'), function(wallet) { var opts = {}; @@ -45,6 +50,8 @@ angular.module('copayApp.services') } root.disableNotifications = function() { + if (!usePushNotifications) return; + lodash.forEach(profileService.getWallets('testnet'), function(wallet) { root.unsubscribe(wallet.id, function(err, response) { if (err) $log.warn('Error: ' + err.code); @@ -54,6 +61,8 @@ angular.module('copayApp.services') } root.subscribe = function(opts, walletId, cb) { + if (!usePushNotifications) return; + var walletClient = profileService.getClient(walletId); walletClient.pushNotificationsSubscribe(opts, function(err, resp) { if (err) return cb(err); @@ -62,6 +71,8 @@ angular.module('copayApp.services') } root.unsubscribe = function(walletId, cb) { + if (!usePushNotifications) return; + var walletClient = profileService.getClient(walletId); walletClient.pushNotificationsUnsubscribe(function(err, resp) { if (err) return cb(err);