Merge pull request #19 from gabrielbazan7/fix/tapOnNot

remove token from localstorage and general refactor
This commit is contained in:
Javier Donadío 2016-04-07 14:40:17 -03:00
commit 4e96d0c036
5 changed files with 37 additions and 42 deletions

View File

@ -1,6 +1,6 @@
<div
class="topbar-container"
<div
class="topbar-container"
ng-include="'views/includes/topbar.html'"
ng-init="titleSection='Global preferences'; closeToHome = true; noColor = true">
</div>
@ -16,7 +16,7 @@
</div>
<div translate>Language</div>
</li>
</ul>
</ul>
<h4></h4>
<ul class="no-bullet m0 ">
<li ng-click="$root.go('preferencesUnit')">
@ -42,13 +42,13 @@
<i class="icon-arrow-right3 size-24"></i>
</div>
<div translate>Bitcoin Network Fee Policy</div>
</li>
</li>
<li>
<switch id="spend-unconfirmed" name="spendUnconfirmed" ng-model="spendUnconfirmed" class="green right"></switch>
<div translate>Use Unconfirmed Funds</div>
</li>
</ul>
<div ng-show="index.usePushNotifications">
<div ng-show="prefGlobal.usePushNotifications">
<h4></h4>
<ul class="no-bullet m0">
<li>
@ -63,8 +63,8 @@
<switch id="glidera-enabled" name="glideraEnabled" ng-model="glideraEnabled" class="green right"></switch>
<div>Enable Glidera Service</div>
</li>
<!-- Disabled for testnet
<!-- Disabled for testnet
<li ng-show="glideraEnabled">
<span>Glidera Sandbox</span>
<switch id="glidera-testnet" name="glideraTestnet" ng-model="glideraTestnet" class="green right"></switch>
@ -74,7 +74,7 @@
<h4></h4>
<ul class="no-bullet m0">
<li ng-click="$root.go('about')">
<i class="icon-arrow-right3 size-24 right text-gray"></i>
<i class="icon-arrow-right3 size-24 right text-gray"></i>
<div translate>About Copay</div>
</li>
</ul>

View File

@ -1,7 +1,7 @@
'use strict';
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() {
var config = configService.getSync();
@ -13,6 +13,7 @@ angular.module('copayApp.controllers').controller('preferencesGlobalController',
};
this.feeOpts = feeService.feeOpts;
this.currentFeeLevel = feeService.getCurrentFeeLevel();
this.usePushNotifications = isCordova && !isMobile.Windows();
$scope.spendUnconfirmed = config.wallet.spendUnconfirmed;
$scope.glideraEnabled = config.glidera.enabled;
$scope.glideraTestnet = config.glidera.testnet;

View File

@ -150,17 +150,7 @@ angular.module('copayApp.services')
root.pushNotificationsInit = function() {
var defaults = configService.getDefaults();
var push = PushNotification.init(defaults.pushNotifications.config);
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);
});
});
});
var push = pushNotificationsService.init(root.walletClients);
push.on('notification', function(data) {
if (!data.additionalData.foreground) {
@ -172,7 +162,7 @@ angular.module('copayApp.services')
var walletToFind = data.additionalData.walletId;
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');

View File

@ -4,26 +4,38 @@ angular.module('copayApp.services')
var root = {};
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) {
if (!usePushNotifications) return;
var config = configService.getSync();
if (!config.pushNotifications.enabled) return;
storageService.getDeviceToken(function(err, token) {
if (err || !token) {
$log.warn('No token available for this device. Cannot set push notifications');
return;
}
if (!root.token) {
$log.warn('No token available for this device. Cannot set push notifications');
return;
}
lodash.forEach(walletsClients, function(walletClient) {
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));
});
lodash.forEach(walletsClients, function(walletClient) {
var opts = {};
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));
else $log.debug('Subscribed to push notifications service: ' + JSON.stringify(response));
});
});
}

View File

@ -231,14 +231,6 @@ angular.module('copayApp.services')
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) {
storage.remove('addressbook-' + network, cb);
};