Merge pull request #3803 from cmgustavo/ref/push-notification-01

Ref/push notification 01
This commit is contained in:
Matias Alejo Garcia 2016-01-22 08:41:48 -03:00
commit b0a3e9316a
7 changed files with 35 additions and 20 deletions

View file

@ -48,11 +48,16 @@
<switch id="spend-unconfirmed" name="spendUnconfirmed" ng-model="spendUnconfirmed" class="green right"></switch> <switch id="spend-unconfirmed" name="spendUnconfirmed" ng-model="spendUnconfirmed" class="green right"></switch>
<div translate>Use Unconfirmed Funds</div> <div translate>Use Unconfirmed Funds</div>
</li> </li>
<li ng-show="mobile">
<switch id="push-notifications" name="pushNotifications" ng-model="pushNotifications" class="green right"></switch>
<div translate>Enable push notifications</div>
</li>
</ul> </ul>
<div ng-show="index.usePushNotifications">
<h4></h4>
<ul class="no-bullet m0">
<li>
<switch id="push-notifications" name="pushNotifications" ng-model="pushNotifications" class="green right"></switch>
<div translate>Enable push notifications</div>
</li>
</ul>
</div>
<h4></h4> <h4></h4>
<ul class="no-bullet m0 "> <ul class="no-bullet m0 ">
<li> <li>

View file

@ -5,20 +5,21 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var SOFT_CONFIRMATION_LIMIT = 12; var SOFT_CONFIRMATION_LIMIT = 12;
self.isCordova = isCordova; self.isCordova = isCordova;
self.isChromeApp = isChromeApp; self.isChromeApp = isChromeApp;
self.usePushNotifications = isMobile.iOS() || isMobile.Android();
self.isSafari = isMobile.Safari(); self.isSafari = isMobile.Safari();
self.isWindowsPhoneApp = isMobile.Windows() && isCordova;
self.usePushNotifications = self.isCordova && !isMobile.Windows();
self.onGoingProcess = {}; self.onGoingProcess = {};
self.historyShowLimit = 10; self.historyShowLimit = 10;
self.updatingTxHistory = {}; self.updatingTxHistory = {};
self.prevState = 'walletHome'; self.prevState = 'walletHome';
document.addEventListener('deviceready', function() { if (self.usePushNotifications) {
storageService.getDeviceToken(function(err, token) { storageService.getDeviceToken(function(err, token) {
$timeout(function() { $timeout(function() {
if (!token) pushNotificationsService.pushNotificationsInit(); if (!token) pushNotificationsService.pushNotificationsInit();
}, 5000); }, 5000);
}); });
}); }
function strip(number) { function strip(number) {
return (parseFloat(number.toPrecision(12))); return (parseFloat(number.toPrecision(12)));
@ -1285,6 +1286,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
$rootScope.$on('Local/SubscribeNotifications', function(event) { $rootScope.$on('Local/SubscribeNotifications', function(event) {
if (!self.usePushNotifications) return;
pushNotificationsService.enableNotifications(); pushNotificationsService.enableNotifications();

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('preferencesController', angular.module('copayApp.controllers').controller('preferencesController',
function($scope, $rootScope, $timeout, $log, configService, profileService) { function($scope, $rootScope, $timeout, $log, configService, profileService, txSignService) {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
$scope.deleted = false; $scope.deleted = false;
@ -75,7 +75,7 @@ angular.module('copayApp.controllers').controller('preferencesController',
}; };
opts.touchIdFor[walletId] = newVal; opts.touchIdFor[walletId] = newVal;
$rootScope.$emit('Local/RequestTouchid', function(err) { txSignService.setTouchId(function(err) {
if (err) { if (err) {
$log.debug(err); $log.debug(err);
$timeout(function() { $timeout(function() {

View file

@ -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, isMobile, uxLanguage, pushNotificationsService) { function($scope, $rootScope, $log, configService, uxLanguage, pushNotificationsService) {
this.init = function() { this.init = function() {
var config = configService.getSync(); var config = configService.getSync();
@ -17,9 +17,6 @@ angular.module('copayApp.controllers').controller('preferencesGlobalController',
$scope.pushNotifications = config.pushNotifications.enabled; $scope.pushNotifications = config.pushNotifications.enabled;
}; };
if (isMobile.Android() || isMobile.iOS()) $scope.mobile = true;
else $scope.mobile = false;
var unwatchSpendUnconfirmed = $scope.$watch('spendUnconfirmed', function(newVal, oldVal) { var unwatchSpendUnconfirmed = $scope.$watch('spendUnconfirmed', function(newVal, oldVal) {
if (newVal == oldVal) return; if (newVal == oldVal) return;
var opts = { var opts = {

View file

@ -87,6 +87,9 @@ angular.module('copayApp.services').factory('configService', function(storageSer
if (!configCache.glidera) { if (!configCache.glidera) {
configCache.glidera = defaultConfig.glidera; configCache.glidera = defaultConfig.glidera;
} }
if (!configCache.pushNotifications) {
configCache.pushNotifications = defaultConfig.pushNotifications;
}
} else { } else {
configCache = lodash.clone(defaultConfig); configCache = lodash.clone(defaultConfig);

View file

@ -1,9 +1,9 @@
'use strict'; 'use strict';
angular.module('copayApp.services') angular.module('copayApp.services')
.factory('pushNotificationsService', function($http, $log, isMobile, profileService, storageService, configService, lodash) { .factory('pushNotificationsService', function($http, $log, isMobile, profileService, storageService, configService, lodash, isCordova) {
var root = {}; var root = {};
var defaults = configService.getDefaults(); var defaults = configService.getDefaults();
var usePushNotifications = isMobile.iOS() || isMobile.Android(); var usePushNotifications = isCordova && !isMobile.Windows();
root.pushNotificationsInit = function() { root.pushNotificationsInit = function() {
if (!usePushNotifications) return; if (!usePushNotifications) return;

View file

@ -2,7 +2,6 @@
angular.module('copayApp.services').factory('txSignService', function($rootScope, profileService, gettextCatalog, lodash, trezor, ledger, configService, bwsError, $log) { angular.module('copayApp.services').factory('txSignService', function($rootScope, profileService, gettextCatalog, lodash, trezor, ledger, configService, bwsError, $log) {
var root = {}; var root = {};
var config = configService.getSync();
var reportSigningStatus = function(opts) { var reportSigningStatus = function(opts) {
if (!opts.reporterFn) return; if (!opts.reporterFn) return;
@ -41,17 +40,26 @@ angular.module('copayApp.services').factory('txSignService', function($rootScope
return cb(); return cb();
}, },
function(msg) { function(msg) {
$log.debug('Touch ID Failed:' + msg); $log.debug('Touch ID Failed:' + JSON.stringify(msg));
return cb(gettext('Touch ID Failed:') + msg); return cb(gettextCatalog.getString('Touch ID Failed') + ': ' + msg.localizedDescription);
} }
); );
} catch (e) { } catch (e) {
$log.debug('Touch ID Failed:' + e); $log.debug('Touch ID Failed:' + JSON.stringify(e));
return cb(gettext('Touch ID Failed:') + e); return cb(gettextCatalog.getString('Touch ID Failed'));
}; };
}; };
root.setTouchId = function(cb) {
if (window.touchidAvailable) {
requestTouchId(cb);
} else {
return cb();
}
};
root.checkTouchId = function(cb) { root.checkTouchId = function(cb) {
var config = configService.getSync();
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
config.touchIdFor = config.touchIdFor || {}; config.touchIdFor = config.touchIdFor || {};
if (window.touchidAvailable && config.touchIdFor[fc.credentials.walletId]) { if (window.touchidAvailable && config.touchIdFor[fc.credentials.walletId]) {