refactor
This commit is contained in:
parent
426d8d29b0
commit
9f0a1ae537
3 changed files with 23 additions and 21 deletions
|
|
@ -13,14 +13,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
self.updatingTxHistory = {};
|
self.updatingTxHistory = {};
|
||||||
self.prevState = 'walletHome';
|
self.prevState = 'walletHome';
|
||||||
|
|
||||||
if (self.usePushNotifications) {
|
|
||||||
storageService.getDeviceToken(function(err, token) {
|
|
||||||
$timeout(function() {
|
|
||||||
if (!token) pushNotificationsService.pushNotificationsInit();
|
|
||||||
}, 5000);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function strip(number) {
|
function strip(number) {
|
||||||
return (parseFloat(number.toPrecision(12)));
|
return (parseFloat(number.toPrecision(12)));
|
||||||
};
|
};
|
||||||
|
|
@ -1233,7 +1225,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
self.updateRemotePreferences({
|
self.updateRemotePreferences({
|
||||||
saveAll: true
|
saveAll: true
|
||||||
}, function() {
|
}, function() {
|
||||||
$log.debug('Remote preferences saved')
|
$log.debug('Remote preferences saved');
|
||||||
storageService.setRemotePrefsStoredFlag(function() {});
|
storageService.setRemotePrefsStoredFlag(function() {});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -1293,10 +1285,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/pushNotificationsRegistration', function(event) {
|
$rootScope.$on('Local/pushNotificationsReady', function(event) {
|
||||||
var config = configService.getSync();
|
pushNotificationsService.enableNotifications(profileService.walletClients);
|
||||||
if (self.usePushNotifications && config.pushNotifications.enabled)
|
|
||||||
pushNotificationsService.enableNotifications(profileService.walletClients);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.debouncedUpdate = lodash.throttle(function() {
|
self.debouncedUpdate = lodash.throttle(function() {
|
||||||
|
|
|
||||||
|
|
@ -132,12 +132,15 @@ angular.module('copayApp.services')
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
root._setFocus(focusedWalletId, function() {
|
root._setFocus(focusedWalletId, function() {
|
||||||
$rootScope.$emit('Local/ProfileBound');
|
$rootScope.$emit('Local/ProfileBound');
|
||||||
root.isDisclaimerAccepted(function(val) {
|
storageService.getDeviceToken(function(err, token) {
|
||||||
if (!val) {
|
if (!token) pushNotificationsService.pushNotificationsInit();
|
||||||
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
|
root.isDisclaimerAccepted(function(val) {
|
||||||
} else {
|
if (!val) {
|
||||||
return cb();
|
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
|
||||||
}
|
} else {
|
||||||
|
return cb();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('pushNotificationsService', function($http, $log, isMobile, storageService, configService, lodash, isCordova) {
|
.factory('pushNotificationsService', function($http, $rootScope, $log, isMobile, storageService, configService, lodash, isCordova) {
|
||||||
var root = {};
|
var root = {};
|
||||||
var defaults = configService.getDefaults();
|
var defaults = configService.getDefaults();
|
||||||
var usePushNotifications = isCordova && !isMobile.Windows();
|
var usePushNotifications = isCordova && !isMobile.Windows();
|
||||||
|
|
@ -8,12 +8,15 @@ angular.module('copayApp.services')
|
||||||
root.pushNotificationsInit = function() {
|
root.pushNotificationsInit = function() {
|
||||||
if (!usePushNotifications) return;
|
if (!usePushNotifications) return;
|
||||||
|
|
||||||
|
var config = configService.getSync();
|
||||||
|
if (!config.pushNotifications.enabled) return;
|
||||||
|
|
||||||
var push = PushNotification.init(defaults.pushNotifications.config);
|
var push = PushNotification.init(defaults.pushNotifications.config);
|
||||||
|
|
||||||
push.on('registration', function(data) {
|
push.on('registration', function(data) {
|
||||||
$log.debug('Starting push notification registration');
|
$log.debug('Starting push notification registration');
|
||||||
storageService.setDeviceToken(data.registrationId, function() {
|
storageService.setDeviceToken(data.registrationId, function() {
|
||||||
$rootScope.$emit('Local/pushNotificationsRegistration');
|
$rootScope.$emit('Local/pushNotificationsReady');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -36,6 +39,9 @@ angular.module('copayApp.services')
|
||||||
root.enableNotifications = function(walletsClients) {
|
root.enableNotifications = function(walletsClients) {
|
||||||
if (!usePushNotifications) return;
|
if (!usePushNotifications) return;
|
||||||
|
|
||||||
|
var config = configService.getSync();
|
||||||
|
if (!config.pushNotifications.enabled) return;
|
||||||
|
|
||||||
storageService.getDeviceToken(function(err, token) {
|
storageService.getDeviceToken(function(err, token) {
|
||||||
lodash.forEach(walletsClients, function(walletClient) {
|
lodash.forEach(walletsClients, function(walletClient) {
|
||||||
var opts = {};
|
var opts = {};
|
||||||
|
|
@ -63,6 +69,9 @@ angular.module('copayApp.services')
|
||||||
root.subscribe = function(opts, walletClient, cb) {
|
root.subscribe = function(opts, walletClient, cb) {
|
||||||
if (!usePushNotifications) return;
|
if (!usePushNotifications) return;
|
||||||
|
|
||||||
|
var config = configService.getSync();
|
||||||
|
if (!config.pushNotifications.enabled) return;
|
||||||
|
|
||||||
walletClient.pushNotificationsSubscribe(opts, function(err, resp) {
|
walletClient.pushNotificationsSubscribe(opts, function(err, resp) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
return cb(null, resp);
|
return cb(null, resp);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue