unsubscribe method refactor
This commit is contained in:
parent
d8cfb9dd5c
commit
58b573ac4e
3 changed files with 42 additions and 35 deletions
|
|
@ -1288,10 +1288,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
pushNotificationsService.enableNotifications();
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/UnsubscribeNotifications', function(event) {
|
||||
pushNotificationsService.unsubscribe(null, function(err, response) {
|
||||
if (err) $log.warn('Error: ' + err.code);
|
||||
$log.debug('Unsubscribed: ' + response);
|
||||
$rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId, cb) {
|
||||
storageService.getDeviceToken(function(err, token) {
|
||||
pushNotificationsService.unsubscribe(token, walletId, function(err, response) {
|
||||
if (err) $log.warn('Error: ' + err.code);
|
||||
$log.debug('Unsubscribed: ' + response);
|
||||
return cb();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -305,35 +305,37 @@ angular.module('copayApp.services')
|
|||
var fc = root.focusedClient;
|
||||
var walletId = fc.credentials.walletId;
|
||||
|
||||
$rootScope.$emit('Local/UnsubscribeNotifications');
|
||||
$log.debug('Deleting Wallet:', fc.credentials.walletName);
|
||||
$rootScope.$emit('Local/UnsubscribeNotifications', walletId, function() {
|
||||
|
||||
fc.removeAllListeners();
|
||||
root.profile.credentials = lodash.reject(root.profile.credentials, {
|
||||
walletId: walletId
|
||||
});
|
||||
$log.debug('Deleting Wallet:', fc.credentials.walletName);
|
||||
|
||||
delete root.walletClients[walletId];
|
||||
root.focusedClient = null;
|
||||
fc.removeAllListeners();
|
||||
root.profile.credentials = lodash.reject(root.profile.credentials, {
|
||||
walletId: walletId
|
||||
});
|
||||
|
||||
storageService.clearLastAddress(walletId, function(err) {
|
||||
if (err) $log.warn(err);
|
||||
});
|
||||
delete root.walletClients[walletId];
|
||||
root.focusedClient = null;
|
||||
|
||||
storageService.removeTxHistory(walletId, function(err) {
|
||||
if (err) $log.warn(err);
|
||||
});
|
||||
storageService.clearLastAddress(walletId, function(err) {
|
||||
if (err) $log.warn(err);
|
||||
});
|
||||
|
||||
storageService.clearBackupFlag(walletId, function(err) {
|
||||
if (err) $log.warn(err);
|
||||
});
|
||||
storageService.removeTxHistory(walletId, function(err) {
|
||||
if (err) $log.warn(err);
|
||||
});
|
||||
|
||||
$timeout(function() {
|
||||
root.setWalletClients();
|
||||
root.setAndStoreFocus(null, function() {
|
||||
storageService.storeProfile(root.profile, function(err) {
|
||||
if (err) return cb(err);
|
||||
return cb();
|
||||
storageService.clearBackupFlag(walletId, function(err) {
|
||||
if (err) $log.warn(err);
|
||||
});
|
||||
|
||||
$timeout(function() {
|
||||
root.setWalletClients();
|
||||
root.setAndStoreFocus(null, function() {
|
||||
storageService.storeProfile(root.profile, function(err) {
|
||||
if (err) return cb(err);
|
||||
return cb();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ angular.module('copayApp.services')
|
|||
|
||||
root.enableNotifications = function() {
|
||||
storageService.getDeviceToken(function(err, token) {
|
||||
lodash.forEach(profileService.getWallets('testnet'), function(wallets) {
|
||||
lodash.forEach(profileService.getWallets('testnet'), function(wallet) {
|
||||
var opts = {};
|
||||
opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null;
|
||||
opts.token = token;
|
||||
root.subscribe(opts, wallets.id, function(err, response) {
|
||||
root.subscribe(opts, wallet.id, function(err, response) {
|
||||
if (err) $log.warn('Error: ' + err.code);
|
||||
$log.debug('Suscribed: ' + JSON.stringify(response));
|
||||
});
|
||||
|
|
@ -46,9 +46,11 @@ angular.module('copayApp.services')
|
|||
|
||||
root.disableNotifications = function() {
|
||||
storageService.getDeviceToken(function(err, token) {
|
||||
root.unsubscribe(token, function(err, response) {
|
||||
if (err) $log.warn('Error: ' + err.code);
|
||||
$log.debug('Unsubscribed: ' + response);
|
||||
lodash.forEach(profileService.getWallets('testnet'), function(wallet) {
|
||||
root.unsubscribe(token, wallet.id, function(err, response) {
|
||||
if (err) $log.warn('Error: ' + err.code);
|
||||
$log.debug('Unsubscribed: ' + response);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -61,9 +63,9 @@ angular.module('copayApp.services')
|
|||
});
|
||||
}
|
||||
|
||||
root.unsubscribe = function(opts, cb) {
|
||||
var walletClient = profileService.focusedClient;
|
||||
walletClient.pushNotificationsUnsubscribe(opts, function(err, resp) {
|
||||
root.unsubscribe = function(token, walletId, cb) {
|
||||
var walletClient = profileService.getClient(walletId);
|
||||
walletClient.pushNotificationsUnsubscribe(token, function(err, resp) {
|
||||
if (err) return cb(err);
|
||||
return cb(null, resp);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue