mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #19 from gabrielbazan7/fix/tapOnNot
remove token from localstorage and general refactor
This commit is contained in:
commit
4e96d0c036
|
@ -48,7 +48,7 @@
|
||||||
<div translate>Use Unconfirmed Funds</div>
|
<div translate>Use Unconfirmed Funds</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div ng-show="index.usePushNotifications">
|
<div ng-show="prefGlobal.usePushNotifications">
|
||||||
<h4></h4>
|
<h4></h4>
|
||||||
<ul class="no-bullet m0">
|
<ul class="no-bullet m0">
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesGlobalController',
|
angular.module('copayApp.controllers').controller('preferencesGlobalController',
|
||||||
function($scope, $rootScope, $log, configService, uxLanguage, pushNotificationsService, profileService, feeService) {
|
function($scope, $rootScope, $log, configService, uxLanguage, isCordova, isMobile, pushNotificationsService, profileService, feeService) {
|
||||||
|
|
||||||
this.init = function() {
|
this.init = function() {
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
|
@ -13,6 +13,7 @@ angular.module('copayApp.controllers').controller('preferencesGlobalController',
|
||||||
};
|
};
|
||||||
this.feeOpts = feeService.feeOpts;
|
this.feeOpts = feeService.feeOpts;
|
||||||
this.currentFeeLevel = feeService.getCurrentFeeLevel();
|
this.currentFeeLevel = feeService.getCurrentFeeLevel();
|
||||||
|
this.usePushNotifications = isCordova && !isMobile.Windows();
|
||||||
$scope.spendUnconfirmed = config.wallet.spendUnconfirmed;
|
$scope.spendUnconfirmed = config.wallet.spendUnconfirmed;
|
||||||
$scope.glideraEnabled = config.glidera.enabled;
|
$scope.glideraEnabled = config.glidera.enabled;
|
||||||
$scope.glideraTestnet = config.glidera.testnet;
|
$scope.glideraTestnet = config.glidera.testnet;
|
||||||
|
|
|
@ -150,17 +150,7 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
root.pushNotificationsInit = function() {
|
root.pushNotificationsInit = function() {
|
||||||
var defaults = configService.getDefaults();
|
var defaults = configService.getDefaults();
|
||||||
var push = PushNotification.init(defaults.pushNotifications.config);
|
var push = pushNotificationsService.init(root.walletClients);
|
||||||
|
|
||||||
push.on('registration', function(data) {
|
|
||||||
storageService.getDeviceToken(function(err, token) {
|
|
||||||
if (token) return;
|
|
||||||
$log.debug('Starting push notification registration');
|
|
||||||
storageService.setDeviceToken(data.registrationId, function() {
|
|
||||||
pushNotificationsService.enableNotifications(root.walletClients);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
push.on('notification', function(data) {
|
push.on('notification', function(data) {
|
||||||
if (!data.additionalData.foreground) {
|
if (!data.additionalData.foreground) {
|
||||||
|
@ -172,7 +162,7 @@ angular.module('copayApp.services')
|
||||||
var walletToFind = data.additionalData.walletId;
|
var walletToFind = data.additionalData.walletId;
|
||||||
|
|
||||||
var walletFound = lodash.find(wallets, function(w) {
|
var walletFound = lodash.find(wallets, function(w) {
|
||||||
return (lodash.isEqual(walletToFind, sjcl.hash.sha256.hash(w.id)));
|
return (lodash.isEqual(walletToFind, sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(w.id))));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!walletFound) return $log.debug('Wallet not found');
|
if (!walletFound) return $log.debug('Wallet not found');
|
||||||
|
|
|
@ -4,14 +4,27 @@ angular.module('copayApp.services')
|
||||||
var root = {};
|
var root = {};
|
||||||
var usePushNotifications = isCordova && !isMobile.Windows();
|
var usePushNotifications = isCordova && !isMobile.Windows();
|
||||||
|
|
||||||
|
root.init = function(walletsClients) {
|
||||||
|
var defaults = configService.getDefaults();
|
||||||
|
var push = PushNotification.init(defaults.pushNotifications.config);
|
||||||
|
|
||||||
|
push.on('registration', function(data) {
|
||||||
|
if (root.token) return;
|
||||||
|
$log.debug('Starting push notification registration');
|
||||||
|
root.token = data.registrationId;
|
||||||
|
root.enableNotifications(walletsClients);
|
||||||
|
});
|
||||||
|
|
||||||
|
return push;
|
||||||
|
}
|
||||||
|
|
||||||
root.enableNotifications = function(walletsClients) {
|
root.enableNotifications = function(walletsClients) {
|
||||||
if (!usePushNotifications) return;
|
if (!usePushNotifications) return;
|
||||||
|
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
if (!config.pushNotifications.enabled) return;
|
if (!config.pushNotifications.enabled) return;
|
||||||
|
|
||||||
storageService.getDeviceToken(function(err, token) {
|
if (!root.token) {
|
||||||
if (err || !token) {
|
|
||||||
$log.warn('No token available for this device. Cannot set push notifications');
|
$log.warn('No token available for this device. Cannot set push notifications');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -19,13 +32,12 @@ angular.module('copayApp.services')
|
||||||
lodash.forEach(walletsClients, function(walletClient) {
|
lodash.forEach(walletsClients, function(walletClient) {
|
||||||
var opts = {};
|
var opts = {};
|
||||||
opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null;
|
opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null;
|
||||||
opts.token = token;
|
opts.token = root.token;
|
||||||
root.subscribe(opts, walletClient, function(err, response) {
|
root.subscribe(opts, walletClient, function(err, response) {
|
||||||
if (err) $log.warn('Subscription error: ' + err.message + ': ' + JSON.stringify(opts));
|
if (err) $log.warn('Subscription error: ' + err.message + ': ' + JSON.stringify(opts));
|
||||||
else $log.debug('Subscribed to push notifications service: ' + JSON.stringify(response));
|
else $log.debug('Subscribed to push notifications service: ' + JSON.stringify(response));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
root.disableNotifications = function(walletsClients) {
|
root.disableNotifications = function(walletsClients) {
|
||||||
|
|
|
@ -231,14 +231,6 @@ angular.module('copayApp.services')
|
||||||
storage.get('addressbook-' + network, cb);
|
storage.get('addressbook-' + network, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setDeviceToken = function(token, cb) {
|
|
||||||
storage.set('pushToken', token, cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
root.getDeviceToken = function(cb) {
|
|
||||||
storage.get('pushToken', cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
root.removeAddressbook = function(network, cb) {
|
root.removeAddressbook = function(network, cb) {
|
||||||
storage.remove('addressbook-' + network, cb);
|
storage.remove('addressbook-' + network, cb);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue