Merge pull request #3988 from JDonadio/fix/tap-on-notification-03
Fix tap on notification
This commit is contained in:
commit
9a10394cd9
6 changed files with 66 additions and 64 deletions
|
|
@ -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,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, bwcService, pushNotificationsService, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, nodeWebkit, addonManager, isChromeApp, bwsError, txFormatService, uxLanguage, $state, glideraService, isMobile, addressbookService) {
|
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, bwcService, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, nodeWebkit, addonManager, isChromeApp, bwsError, txFormatService, uxLanguage, $state, glideraService, isMobile, addressbookService) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var SOFT_CONFIRMATION_LIMIT = 12;
|
var SOFT_CONFIRMATION_LIMIT = 12;
|
||||||
var errors = bwcService.getErrors();
|
var errors = bwcService.getErrors();
|
||||||
|
|
@ -11,7 +11,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
ret.isChromeApp = isChromeApp;
|
ret.isChromeApp = isChromeApp;
|
||||||
ret.isSafari = isMobile.Safari();
|
ret.isSafari = isMobile.Safari();
|
||||||
ret.isWindowsPhoneApp = isMobile.Windows() && isCordova;
|
ret.isWindowsPhoneApp = isMobile.Windows() && isCordova;
|
||||||
ret.usePushNotifications = ret.isCordova && !isMobile.Windows();
|
|
||||||
ret.onGoingProcess = {};
|
ret.onGoingProcess = {};
|
||||||
ret.historyShowLimit = 10;
|
ret.historyShowLimit = 10;
|
||||||
ret.historyShowMoreLimit = 100;
|
ret.historyShowMoreLimit = 100;
|
||||||
|
|
@ -49,7 +48,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
ret.tab = 'walletHome';
|
ret.tab = 'walletHome';
|
||||||
var vanillaScope = ret;
|
var vanillaScope = ret;
|
||||||
|
|
||||||
|
|
||||||
function strip(number) {
|
function strip(number) {
|
||||||
return (parseFloat(number.toPrecision(12)));
|
return (parseFloat(number.toPrecision(12)));
|
||||||
};
|
};
|
||||||
|
|
@ -1379,10 +1377,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/pushNotificationsReady', function(event) {
|
|
||||||
pushNotificationsService.enableNotifications(profileService.walletClients);
|
|
||||||
});
|
|
||||||
|
|
||||||
self.debouncedUpdate = lodash.throttle(function() {
|
self.debouncedUpdate = lodash.throttle(function() {
|
||||||
self.updateAll({
|
self.updateAll({
|
||||||
quiet: true
|
quiet: true
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, storageService, bwcService, configService, notificationService, pushNotificationsService, isChromeApp, isCordova, gettext, gettextCatalog, nodeWebkit, bwsError, uxLanguage, bitcore) {
|
.factory('profileService', function profileServiceFactory($rootScope, $timeout, $filter, $log, sjcl, lodash, storageService, bwcService, configService, notificationService, pushNotificationsService, isChromeApp, isCordova, isMobile, gettext, gettextCatalog, nodeWebkit, bwsError, uxLanguage, bitcore) {
|
||||||
|
|
||||||
var root = {};
|
var root = {};
|
||||||
var errors = bwcService.getErrors();
|
var errors = bwcService.getErrors();
|
||||||
|
var usePushNotifications = isCordova && !isMobile.Windows();
|
||||||
|
|
||||||
var FOREGROUND_UPDATE_PERIOD = 5;
|
var FOREGROUND_UPDATE_PERIOD = 5;
|
||||||
var BACKGROUND_UPDATE_PERIOD = 30;
|
var BACKGROUND_UPDATE_PERIOD = 30;
|
||||||
|
|
@ -133,22 +134,42 @@ 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');
|
||||||
storageService.getDeviceToken(function(err, token) {
|
if (usePushNotifications)
|
||||||
if (!token)
|
root.pushNotificationsInit();
|
||||||
pushNotificationsService.pushNotificationsInit();
|
root.isDisclaimerAccepted(function(val) {
|
||||||
|
if (!val) {
|
||||||
root.isDisclaimerAccepted(function(val) {
|
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
|
||||||
if (!val) {
|
} else {
|
||||||
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
|
return cb();
|
||||||
} else {
|
}
|
||||||
return cb();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
root.pushNotificationsInit = function() {
|
||||||
|
var defaults = configService.getDefaults();
|
||||||
|
var push = pushNotificationsService.init(root.walletClients);
|
||||||
|
|
||||||
|
push.on('notification', function(data) {
|
||||||
|
if (!data.additionalData.foreground) {
|
||||||
|
window.ignoreMobilePause = true;
|
||||||
|
$log.debug('Push notification event: ', data.message);
|
||||||
|
|
||||||
|
$timeout(function() {
|
||||||
|
var wallets = root.getWallets();
|
||||||
|
var walletToFind = data.additionalData.walletId;
|
||||||
|
|
||||||
|
var walletFound = lodash.find(wallets, function(w) {
|
||||||
|
return (lodash.isEqual(walletToFind, sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(w.id))));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!walletFound) return $log.debug('Wallet not found');
|
||||||
|
root.setAndStoreFocus(walletFound.id, function() {});
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,23 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('pushNotificationsService', function($http, $rootScope, $log, isMobile, storageService, configService, lodash, isCordova) {
|
.factory('pushNotificationsService', function($log, isMobile, storageService, configService, lodash, isCordova) {
|
||||||
var root = {};
|
var root = {};
|
||||||
var defaults = configService.getDefaults();
|
|
||||||
var usePushNotifications = isCordova && !isMobile.Windows();
|
var usePushNotifications = isCordova && !isMobile.Windows();
|
||||||
|
|
||||||
root.pushNotificationsInit = function() {
|
root.init = function(walletsClients) {
|
||||||
if (!usePushNotifications) return;
|
var defaults = configService.getDefaults();
|
||||||
|
|
||||||
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) {
|
||||||
|
if (root.token) return;
|
||||||
$log.debug('Starting push notification registration');
|
$log.debug('Starting push notification registration');
|
||||||
storageService.setDeviceToken(data.registrationId, function() {
|
root.token = data.registrationId;
|
||||||
$rootScope.$emit('Local/pushNotificationsReady');
|
var config = configService.getSync();
|
||||||
});
|
if (config.pushNotifications.enabled) root.enableNotifications(walletsClients);
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
return push;
|
||||||
|
}
|
||||||
|
|
||||||
root.enableNotifications = function(walletsClients) {
|
root.enableNotifications = function(walletsClients) {
|
||||||
if (!usePushNotifications) return;
|
if (!usePushNotifications) return;
|
||||||
|
|
@ -27,22 +25,18 @@ angular.module('copayApp.services')
|
||||||
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) {
|
||||||
|
$log.warn('No token available for this device. Cannot set push notifications');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (err || !token) {
|
lodash.forEach(walletsClients, function(walletClient) {
|
||||||
$log.warn('No token available for this device. Cannot set push notifications');
|
var opts = {};
|
||||||
return;
|
opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null;
|
||||||
}
|
opts.token = root.token;
|
||||||
|
root.subscribe(opts, walletClient, function(err, response) {
|
||||||
|
if (err) $log.warn('Subscription error: ' + err.message + ': ' + JSON.stringify(opts));
|
||||||
lodash.forEach(walletsClients, function(walletClient) {
|
else $log.debug('Subscribed to push notifications service: ' + JSON.stringify(response));
|
||||||
var opts = {};
|
|
||||||
opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null;
|
|
||||||
opts.token = token;
|
|
||||||
root.subscribe(opts, walletClient, function(err, response) {
|
|
||||||
if (err) $log.warn('Subscription error: ' + err.message + ': ' + JSON.stringify(opts));
|
|
||||||
else $log.debug('Subscribed to push notifications service: ' + JSON.stringify(response));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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…
Add table
Add a link
Reference in a new issue