From 3320510d3563d735260d5d365370379e55720a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Sat, 8 Oct 2016 20:19:55 -0300 Subject: [PATCH 1/4] fix push notifications and remove onboarding email --- app-template/bitpay/appConfig.json | 1 + app-template/copay/appConfig.json | 1 + .../controllers/onboarding/notifications.js | 25 +++++- src/js/controllers/onboarding/tour.js | 83 ++++++++++--------- .../controllers/preferencesNotifications.js | 4 +- src/js/services/profileService.js | 3 +- src/js/services/pushNotificationsService.js | 3 +- www/views/onboarding/notifications.html | 2 +- www/views/onboarding/tour.html | 5 +- 9 files changed, 74 insertions(+), 53 deletions(-) diff --git a/app-template/bitpay/appConfig.json b/app-template/bitpay/appConfig.json index 44be954ac..3c0ee862b 100644 --- a/app-template/bitpay/appConfig.json +++ b/app-template/bitpay/appConfig.json @@ -17,6 +17,7 @@ "winAppName": "BitPayWallet", "wpPublisherId": "{}", "wpProductId": "{}", + "pushSenderId": "1036948132229", "description": "Secure Bitcoin Storage", "version": "0.14.0", "androidVersion": "1", diff --git a/app-template/copay/appConfig.json b/app-template/copay/appConfig.json index 66bb79585..7a6ee7ef3 100644 --- a/app-template/copay/appConfig.json +++ b/app-template/copay/appConfig.json @@ -17,6 +17,7 @@ "winAppName": "CopayWallet", "wpPublisherId": "{31cdd08b-457c-413d-b440-f6665eec847d}", "wpProductId": "{5381aa50-9069-11e4-84cc-293caf9cbdc8}", + "pushSenderId": "1036948132229", "description": "A Secure Bitcoin Wallet", "version": "2.5.0", "androidVersion": "115", diff --git a/src/js/controllers/onboarding/notifications.js b/src/js/controllers/onboarding/notifications.js index a2444abf0..a2c8346e5 100644 --- a/src/js/controllers/onboarding/notifications.js +++ b/src/js/controllers/onboarding/notifications.js @@ -1,13 +1,32 @@ 'use strict'; -angular.module('copayApp.controllers').controller('notificationsController', function($scope, $state, $stateParams, profileService) { +angular.module('copayApp.controllers').controller('notificationsController', function($scope, $state, $timeout, $stateParams, profileService, configService) { + + $scope.$on("$ionicView.enter", function(event, data) { + $scope.walletId = data.stateParams.walletId; + }); - $scope.walletId = $stateParams.walletId; $scope.allowNotif = function() { - profileService.pushNotificationsInit(); + $timeout(function() { + profileService.pushNotificationsInit(); + }); $state.go('onboarding.backupRequest', { walletId: $scope.walletId }); } + $scope.disableNotif = function() { + var opts = { + pushNotifications: { + enabled: false + } + }; + configService.set(opts, function(err) { + if (err) $log.warn(err); + $state.go('onboarding.backupRequest', { + walletId: $scope.walletId + }); + }); + }; + }); diff --git a/src/js/controllers/onboarding/tour.js b/src/js/controllers/onboarding/tour.js index aa2cdd92e..568d2771b 100644 --- a/src/js/controllers/onboarding/tour.js +++ b/src/js/controllers/onboarding/tour.js @@ -1,28 +1,40 @@ 'use strict'; angular.module('copayApp.controllers').controller('tourController', - function($scope, $state, $log, $timeout, $filter, ongoingProcess, profileService, rateService) { + function($scope, $state, $log, $timeout, $filter, ongoingProcess, platformInfo, profileService, rateService) { - var tries = 0; + var isCordova = platformInfo.isCordova; + var isWP = platformInfo.isWP; + var usePushNotifications = isCordova && !isWP; - $scope.init = function() { - $scope.data = { - index: 0 - }; - - $scope.options = { - loop: false, - effect: 'flip', - speed: 500, - spaceBetween: 100 - } + $scope.data = { + index: 0 }; - rateService.whenAvailable(function() { - var localCurrency = 'USD'; - var btcAmount = 1; - var rate = rateService.toFiat(btcAmount * 1e8, localCurrency); - $scope.localCurrencySymbol = '$'; - $scope.localCurrencyPerBtc = $filter('formatFiatAmount')(parseFloat(rate.toFixed(2), 10)); + $scope.options = { + loop: false, + effect: 'flip', + speed: 500, + spaceBetween: 100 + } + + $scope.$on("$ionicSlides.sliderInitialized", function(event, data) { + $scope.slider = data.slider; + }); + + $scope.$on("$ionicSlides.slideChangeStart", function(event, data) { + $scope.data.index = data.slider.activeIndex; + }); + + $scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {}); + + $scope.$on("$ionicView.enter", function(event, data) { + rateService.whenAvailable(function() { + var localCurrency = 'USD'; + var btcAmount = 1; + var rate = rateService.toFiat(btcAmount * 1e8, localCurrency); + $scope.localCurrencySymbol = '$'; + $scope.localCurrencyPerBtc = $filter('formatFiatAmount')(parseFloat(rate.toFixed(2), 10)); + }); }); $scope.createDefaultWallet = function() { @@ -33,21 +45,22 @@ angular.module('copayApp.controllers').controller('tourController', return $timeout(function() { $log.warn('Retrying to create default wallet......'); - if (tries == 3) { - tries == 0; - return $scope.createDefaultWallet(); - } else { - tries += 1; - return $scope.createDefaultWallet(); - } + return $scope.createDefaultWallet(); }, 3000); }; ongoingProcess.set('creatingWallet', false); var wallet = walletClient; - $state.go('onboarding.collectEmail', { - fromOnboarding: true, - walletId: wallet.credentials.walletId - }); + var walletId = wallet.credentials.walletId; + if (!usePushNotifications) { + $state.go('onboarding.backupRequest', { + walletId: walletId + }); + } + else { + $state.go('onboarding.notifications', { + walletId: walletId + }); + } }); }; @@ -60,14 +73,4 @@ angular.module('copayApp.controllers').controller('tourController', if ($scope.data.index != 2) $scope.slider.slideNext(); else $state.go('onboarding.welcome'); } - - $scope.$on("$ionicSlides.sliderInitialized", function(event, data) { - $scope.slider = data.slider; - }); - - $scope.$on("$ionicSlides.slideChangeStart", function(event, data) { - $scope.data.index = data.slider.activeIndex; - }); - - $scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {}); }); diff --git a/src/js/controllers/preferencesNotifications.js b/src/js/controllers/preferencesNotifications.js index 8d947dde8..10ce21a4f 100644 --- a/src/js/controllers/preferencesNotifications.js +++ b/src/js/controllers/preferencesNotifications.js @@ -39,9 +39,9 @@ angular.module('copayApp.controllers').controller('preferencesNotificationsContr }; configService.set(opts, function(err) { if (opts.pushNotifications.enabled) - pushNotificationsService.enableNotifications(profileService.walletClients); + profileService.pushNotificationsInit(); else - pushNotificationsService.disableNotifications(profileService.walletClients); + pushNotificationsService.disableNotifications(profileService.getWallets()); if (err) $log.debug(err); }); }; diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 30563208b..5a6cfc88e 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -296,7 +296,8 @@ angular.module('copayApp.services') if (!val) { return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); } - if (usePushNotifications) + var config = configService.getSync(); + if (config.pushNotifications.enabled && usePushNotifications) root.pushNotificationsInit(); return cb(); }); diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js index f6c621415..57d9d5ddd 100644 --- a/src/js/services/pushNotificationsService.js +++ b/src/js/services/pushNotificationsService.js @@ -14,7 +14,6 @@ angular.module('copayApp.services') 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; var config = configService.getSync(); @@ -31,7 +30,7 @@ angular.module('copayApp.services') if (!config.pushNotifications.enabled) return; if (!root.token) { - $log.warn('No token available for this device. Cannot set push notifications'); + $log.warn('No token available for this device. Cannot set push notifications. Needs registration.'); return; } diff --git a/www/views/onboarding/notifications.html b/www/views/onboarding/notifications.html index 8d03866ca..dac81fdf9 100644 --- a/www/views/onboarding/notifications.html +++ b/www/views/onboarding/notifications.html @@ -5,7 +5,7 @@
- +
diff --git a/www/views/onboarding/tour.html b/www/views/onboarding/tour.html index 9135e5217..de836e0c9 100644 --- a/www/views/onboarding/tour.html +++ b/www/views/onboarding/tour.html @@ -1,4 +1,4 @@ - + @@ -6,9 +6,6 @@ - - - From b29fab9ae2a7a9682619d2575c748f8b2434a61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Sat, 8 Oct 2016 21:12:30 -0300 Subject: [PATCH 2/4] ios fixes --- app-template/config-template.xml | 1 - src/js/controllers/preferencesNotifications.js | 14 +++----------- www/views/preferencesNotifications.html | 5 +---- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/app-template/config-template.xml b/app-template/config-template.xml index 3596fc947..e2fc4058f 100644 --- a/app-template/config-template.xml +++ b/app-template/config-template.xml @@ -32,7 +32,6 @@ - diff --git a/src/js/controllers/preferencesNotifications.js b/src/js/controllers/preferencesNotifications.js index 10ce21a4f..cf8c5a979 100644 --- a/src/js/controllers/preferencesNotifications.js +++ b/src/js/controllers/preferencesNotifications.js @@ -9,12 +9,12 @@ angular.module('copayApp.controllers').controller('preferencesNotificationsContr var isCordova = platformInfo.isCordova; var isIOS = platformInfo.isIOS; + $scope.appName = $window.appConfig.nameCase; $scope.PNEnabledByUser = true; $scope.isIOSApp = isIOS && isCordova; if ($scope.isIOSApp) { - cordova.plugins.diagnostic.isRemoteNotificationsEnabled(function(isEnabled) { - $scope.PNEnabledByUser = isEnabled; - $scope.$digest(); + PushNotification.hasPermission(function(data) { + $scope.PNEnabledByUser = data.isEnabled; }); } @@ -23,14 +23,6 @@ angular.module('copayApp.controllers').controller('preferencesNotificationsContr }; }; - $scope.openSettings = function() { - cordova.plugins.diagnostic.switchToSettings(function() { - $log.debug('switched to settings'); - }, function(err) { - $log.debug(err); - }); - }; - $scope.pushNotificationsChange = function() { var opts = { pushNotifications: { diff --git a/www/views/preferencesNotifications.html b/www/views/preferencesNotifications.html index 8b54a93e2..7385fd380 100644 --- a/www/views/preferencesNotifications.html +++ b/www/views/preferencesNotifications.html @@ -18,11 +18,8 @@
Notifications
- Push notifications for Copay are currently disabled. Enable them in the Settings app. + Push notifications for {{appName}} are currently disabled. Enable them in the Settings app.
- - Open Settings app -
From ee5b2817d7b06d3980229870be47d28ab7d31fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Mon, 10 Oct 2016 13:13:30 -0300 Subject: [PATCH 3/4] fix --- app-template/config-template.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app-template/config-template.xml b/app-template/config-template.xml index e2fc4058f..5a72f4560 100644 --- a/app-template/config-template.xml +++ b/app-template/config-template.xml @@ -56,7 +56,9 @@ - + + + From cd0e5df44751353afa082fb5fc9a8d1d954432cb Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Mon, 10 Oct 2016 13:45:43 -0300 Subject: [PATCH 4/4] Fix if push is not available --- src/js/controllers/preferencesNotifications.js | 11 ++++++++--- src/js/services/profileService.js | 2 ++ src/js/services/pushNotificationsService.js | 7 ++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/js/controllers/preferencesNotifications.js b/src/js/controllers/preferencesNotifications.js index cf8c5a979..5cf80a4af 100644 --- a/src/js/controllers/preferencesNotifications.js +++ b/src/js/controllers/preferencesNotifications.js @@ -13,9 +13,13 @@ angular.module('copayApp.controllers').controller('preferencesNotificationsContr $scope.PNEnabledByUser = true; $scope.isIOSApp = isIOS && isCordova; if ($scope.isIOSApp) { - PushNotification.hasPermission(function(data) { - $scope.PNEnabledByUser = data.isEnabled; - }); + try { + PushNotification.hasPermission(function(data) { + $scope.PNEnabledByUser = data.isEnabled; + }); + } catch(e) { + $log.error(e); + }; } $scope.pushNotifications = { @@ -24,6 +28,7 @@ angular.module('copayApp.controllers').controller('preferencesNotificationsContr }; $scope.pushNotificationsChange = function() { + if (!$scope.pushNotifications) return; var opts = { pushNotifications: { enabled: $scope.pushNotifications.value diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 5a6cfc88e..659f9dd8f 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -318,6 +318,8 @@ angular.module('copayApp.services') var defaults = configService.getDefaults(); var push = pushNotificationsService.init(root.wallet); + if (!push) return; + push.on('notification', function(data) { if (!data.additionalData.foreground) { $log.debug('Push notification event: ', data.message); diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js index 57d9d5ddd..904ae4246 100644 --- a/src/js/services/pushNotificationsService.js +++ b/src/js/services/pushNotificationsService.js @@ -11,7 +11,12 @@ angular.module('copayApp.services') root.init = function(walletsClients) { var defaults = configService.getDefaults(); - var push = PushNotification.init(defaults.pushNotifications.config); + try { + var push = PushNotification.init(defaults.pushNotifications.config); + } catch(e) { + $log.error(e); + return; + }; push.on('registration', function(data) { $log.debug('Starting push notification registration');