diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index ac39c4dc2..9fe28c75c 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -1273,10 +1273,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r go.walletHome(); }); - $rootScope.$on('Local/EnableNotifications', function(event) { + $rootScope.$on('Local/SubscribeNotifications', function(event) { pushNotificationsService.enableNotifications(); }); + $rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId) { + pushNotificationsService.unsubscribe(walletId); + }); + self.debouncedUpdate = lodash.throttle(function() { self.updateAll({ quiet: true diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 9f50e9260..816598c08 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -326,6 +326,8 @@ angular.module('copayApp.services') if (err) $log.warn(err); }); + $rootScope.$emit('Local/UnsubscribeNotifications', walletId); + $timeout(function() { root.setWalletClients(); root.setAndStoreFocus(null, function() { @@ -397,7 +399,7 @@ angular.module('copayApp.services') handleImport(function() { root.setAndStoreFocus(walletId, function() { storageService.storeProfile(root.profile, function(err) { - $rootScope.$emit('Local/EnableNotifications'); + $rootScope.$emit('Local/SubscribeNotifications'); return cb(err, walletId); }); }); diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js index ea0f20d11..20040d3e4 100644 --- a/src/js/services/pushNotificationsService.js +++ b/src/js/services/pushNotificationsService.js @@ -42,7 +42,7 @@ angular.module('copayApp.services') root.enableNotifications = function() { storageService.getDeviceToken(function(err, token) { - lodash.forEach(profileService.getWallets('livenet'), function(wallets) { + lodash.forEach(profileService.getWallets('testnet'), function(wallets) { var opts = {}; opts.user = wallets.id; opts.type = (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? "ios" : (navigator.userAgent.match(/Android/i)) == "Android" ? "android" : null; @@ -60,7 +60,7 @@ angular.module('copayApp.services') root.disableNotifications = function() { storageService.getDeviceToken(function(err, token) { - root.unsubscribe(token).then(function(response) { + root.unsubscribeAll(token).then(function(response) { $log.debug('Unsubscribed: ' + response.status); }, function(err) { @@ -70,11 +70,17 @@ angular.module('copayApp.services') } root.subscribe = function(opts) { - return $http.post('http://192.168.1.128:8000/subscribe', opts); + return $http.post('http://192.168.1.121:8000/subscribe', opts); } - root.unsubscribe = function(token) { - return $http.post('http://192.168.1.128:8000/unsubscribe', { + root.unsubscribe = function(user) { + return $http.post('http://192.168.1.121:8000/unsubscribe', { + user: user + }); + } + + root.unsubscribeAll = function(token) { + return $http.post('http://192.168.1.121:8000/unsubscribe', { token: token }); }