Merge pull request #328 from gabrielbazan7/feat/pushNotifications
fix push notifications and remove onboarding email
This commit is contained in:
commit
6ce9f00cdf
11 changed files with 95 additions and 72 deletions
|
|
@ -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
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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) {});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,13 +9,17 @@ 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();
|
||||
});
|
||||
try {
|
||||
PushNotification.hasPermission(function(data) {
|
||||
$scope.PNEnabledByUser = data.isEnabled;
|
||||
});
|
||||
} catch(e) {
|
||||
$log.error(e);
|
||||
};
|
||||
}
|
||||
|
||||
$scope.pushNotifications = {
|
||||
|
|
@ -23,15 +27,8 @@ 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() {
|
||||
if (!$scope.pushNotifications) return;
|
||||
var opts = {
|
||||
pushNotifications: {
|
||||
enabled: $scope.pushNotifications.value
|
||||
|
|
@ -39,9 +36,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);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
|
|
@ -317,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);
|
||||
|
|
|
|||
|
|
@ -11,10 +11,14 @@ 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) {
|
||||
if (root.token) return;
|
||||
$log.debug('Starting push notification registration');
|
||||
root.token = data.registrationId;
|
||||
var config = configService.getSync();
|
||||
|
|
@ -31,7 +35,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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue