From 08c9e81f9b5ad387dcdea7e12e62e526075a6df7 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 9 Mar 2016 19:10:35 -0300 Subject: [PATCH 1/6] fix focus wallet tapping on notification --- src/js/controllers/index.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 3ad881565..a7324e2a5 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -49,6 +49,34 @@ angular.module('copayApp.controllers').controller('indexController', function($r ret.tab = 'walletHome'; var vanillaScope = ret; + if (ret.usePushNotifications) { + // Listening for push notifications + var push = PushNotification.init(configService.getDefaults().pushNotifications.config); + + push.on('notification', function(data) { + if (!data.additionalData.foreground) { + window.ignoreMobilePause = true; + // window.plugins.spinnerDialog.show(null, gettextCatalog.getString('LOADING...'), true); + $log.debug('Push notification event: ', data.message); + + $timeout(function() { + var wallets = profileService.getWallets(); + var walletToFind = data.additionalData.walletId; + + var walletFound = lodash.find(wallets, function(w) { + return (lodash.isEqual(walletToFind, sjcl.hash.sha256.hash(w.id))); + }); + + if (!walletFound) return $log.debug('Wallet not found'); + profileService.setAndStoreFocus(walletFound.id, function() { + // $timeout(function() { + // window.plugins.spinnerDialog.hide(); + // }, 200); + }); + }, 100); + } + }); + } function strip(number) { return (parseFloat(number.toPrecision(12))); From e180d0bbd4a04031d8a9a418d01b12a41c44cdb0 Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 10 Mar 2016 10:58:58 -0300 Subject: [PATCH 2/6] refactor push object listeners and calls --- src/js/controllers/index.js | 33 ------------ src/js/services/profileService.js | 59 ++++++++++++++++----- src/js/services/pushNotificationsService.js | 21 +------- 3 files changed, 46 insertions(+), 67 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index a7324e2a5..c9462b189 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -49,35 +49,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r ret.tab = 'walletHome'; var vanillaScope = ret; - if (ret.usePushNotifications) { - // Listening for push notifications - var push = PushNotification.init(configService.getDefaults().pushNotifications.config); - - push.on('notification', function(data) { - if (!data.additionalData.foreground) { - window.ignoreMobilePause = true; - // window.plugins.spinnerDialog.show(null, gettextCatalog.getString('LOADING...'), true); - $log.debug('Push notification event: ', data.message); - - $timeout(function() { - var wallets = profileService.getWallets(); - var walletToFind = data.additionalData.walletId; - - var walletFound = lodash.find(wallets, function(w) { - return (lodash.isEqual(walletToFind, sjcl.hash.sha256.hash(w.id))); - }); - - if (!walletFound) return $log.debug('Wallet not found'); - profileService.setAndStoreFocus(walletFound.id, function() { - // $timeout(function() { - // window.plugins.spinnerDialog.hide(); - // }, 200); - }); - }, 100); - } - }); - } - function strip(number) { return (parseFloat(number.toPrecision(12))); }; @@ -1407,10 +1378,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.updateAll({ quiet: true diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 9a33010ad..7e9fba822 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -1,9 +1,10 @@ 'use strict'; 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, $location, $timeout, $filter, $log, sjcl, lodash, storageService, bwcService, configService, notificationService, pushNotificationsService, isChromeApp, isCordova, gettext, gettextCatalog, nodeWebkit, bwsError, uxLanguage, bitcore) { var root = {}; var errors = bwcService.getErrors(); + var usePushNotifications = isCordova && !isMobile.Windows(); var FOREGROUND_UPDATE_PERIOD = 5; var BACKGROUND_UPDATE_PERIOD = 30; @@ -133,22 +134,52 @@ angular.module('copayApp.services') if (err) return cb(err); root._setFocus(focusedWalletId, function() { $rootScope.$emit('Local/ProfileBound'); - storageService.getDeviceToken(function(err, token) { - if (!token) - pushNotificationsService.pushNotificationsInit(); - - root.isDisclaimerAccepted(function(val) { - if (!val) { - return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); - } else { - return cb(); - } - }); + if (usePushNotifications) + root.pushNotificationsInit(); + root.isDisclaimerAccepted(function(val) { + if (!val) { + return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); + } else { + return cb(); + } }); }); }); }); + }; + 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); + }); + }); + }); + + 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.hash.sha256.hash(w.id))); + }); + + if (!walletFound) return $log.debug('Wallet not found'); + root.setAndStoreFocus(walletFound.id, function() {}); + }, 100); + } + }); }; @@ -306,8 +337,8 @@ angular.module('copayApp.services') // check if exist if (lodash.find(root.profile.credentials, { - 'walletId': walletData.walletId - })) { + 'walletId': walletData.walletId + })) { return cb(gettext('Cannot join the same wallet more that once')); } } catch (ex) { diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js index ee4b72027..12282f52d 100644 --- a/src/js/services/pushNotificationsService.js +++ b/src/js/services/pushNotificationsService.js @@ -2,25 +2,8 @@ angular.module('copayApp.services') .factory('pushNotificationsService', function($http, $rootScope, $log, isMobile, storageService, configService, lodash, isCordova) { var root = {}; - var defaults = configService.getDefaults(); var usePushNotifications = isCordova && !isMobile.Windows(); - root.pushNotificationsInit = function() { - if (!usePushNotifications) return; - - var config = configService.getSync(); - if (!config.pushNotifications.enabled) return; - - var push = PushNotification.init(defaults.pushNotifications.config); - - push.on('registration', function(data) { - $log.debug('Starting push notification registration'); - storageService.setDeviceToken(data.registrationId, function() { - $rootScope.$emit('Local/pushNotificationsReady'); - }); - }); - }; - root.enableNotifications = function(walletsClients) { if (!usePushNotifications) return; @@ -28,19 +11,17 @@ angular.module('copayApp.services') 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; } - 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)); + if (err) $log.warn('Subscription error: ' + err.message + ': ' + JSON.stringify(opts)); else $log.debug('Subscribed to push notifications service: ' + JSON.stringify(response)); }); }); From 886c1dd33c7ce9d89223e868fa93af90b77517a3 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 30 Mar 2016 15:51:03 -0300 Subject: [PATCH 3/6] add mobile dependency --- src/js/services/profileService.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 7e9fba822..91e3cb4d7 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -1,6 +1,6 @@ 'use strict'; angular.module('copayApp.services') - .factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, sjcl, lodash, storageService, bwcService, configService, notificationService, pushNotificationsService, isChromeApp, isCordova, gettext, gettextCatalog, nodeWebkit, bwsError, uxLanguage, bitcore) { + .factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, sjcl, lodash, storageService, bwcService, configService, notificationService, pushNotificationsService, isChromeApp, isCordova, isMobile, gettext, gettextCatalog, nodeWebkit, bwsError, uxLanguage, bitcore) { var root = {}; var errors = bwcService.getErrors(); From f16efeb69e701d2a98e8e2212ecb8ad6fc0549c4 Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 7 Apr 2016 12:19:51 -0300 Subject: [PATCH 4/6] remove unnecessary variables/services --- src/js/controllers/index.js | 5 ++--- src/js/services/profileService.js | 2 +- src/js/services/pushNotificationsService.js | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index c9462b189..b30bcdcce 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -1,6 +1,6 @@ '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 SOFT_CONFIRMATION_LIMIT = 12; var errors = bwcService.getErrors(); @@ -11,7 +11,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r ret.isChromeApp = isChromeApp; ret.isSafari = isMobile.Safari(); ret.isWindowsPhoneApp = isMobile.Windows() && isCordova; - ret.usePushNotifications = ret.isCordova && !isMobile.Windows(); ret.onGoingProcess = {}; ret.historyShowLimit = 10; ret.historyShowMoreLimit = 100; @@ -1486,7 +1485,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); }); - //untilItChange FALSE + //untilItChange FALSE lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', 'NewOutgoingTxByThirdParty', 'Local/GlideraTx' ], function(eventName) { diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 91e3cb4d7..26db7aea5 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -1,6 +1,6 @@ 'use strict'; angular.module('copayApp.services') - .factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, sjcl, lodash, storageService, bwcService, configService, notificationService, pushNotificationsService, isChromeApp, isCordova, isMobile, 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 errors = bwcService.getErrors(); diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js index 12282f52d..82e7fbccc 100644 --- a/src/js/services/pushNotificationsService.js +++ b/src/js/services/pushNotificationsService.js @@ -1,6 +1,6 @@ 'use strict'; 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 usePushNotifications = isCordova && !isMobile.Windows(); From 48bf75e638a3762468cafb065aa436c19713fd1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Thu, 7 Apr 2016 12:58:32 -0300 Subject: [PATCH 5/6] remove token from localstorage and general refactor --- public/views/preferencesGlobal.html | 16 ++++----- src/js/controllers/preferencesGlobal.js | 3 +- src/js/services/profileService.js | 14 ++------ src/js/services/pushNotificationsService.js | 38 ++++++++++++++------- src/js/services/storageService.js | 8 ----- 5 files changed, 37 insertions(+), 42 deletions(-) diff --git a/public/views/preferencesGlobal.html b/public/views/preferencesGlobal.html index 373f49f20..97234d94f 100644 --- a/public/views/preferencesGlobal.html +++ b/public/views/preferencesGlobal.html @@ -1,6 +1,6 @@ -
@@ -16,7 +16,7 @@
Language
- +

  • @@ -42,13 +42,13 @@
    Bitcoin Network Fee Policy
    -
  • +
  • Use Unconfirmed Funds
-
+

  • @@ -63,8 +63,8 @@
    Enable Glidera Service
  • - -