2016-08-25 16:31:47 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-10-10 17:12:14 -03:00
|
|
|
angular.module('copayApp.controllers').controller('collectEmailController', function($scope, $state, $timeout, $stateParams, $ionicConfig, profileService, configService, walletService, platformInfo) {
|
2016-08-29 11:56:31 -03:00
|
|
|
|
2016-10-10 17:12:14 -03:00
|
|
|
$ionicConfig.views.swipeBackEnabled(false);
|
2016-08-29 17:42:19 -03:00
|
|
|
var isCordova = platformInfo.isCordova;
|
|
|
|
|
var isWP = platformInfo.isWP;
|
|
|
|
|
var usePushNotifications = isCordova && !isWP;
|
2016-09-13 17:12:17 -03:00
|
|
|
var requiresOptIn = platformInfo.isIOS;
|
2016-08-29 17:42:19 -03:00
|
|
|
|
2016-09-02 11:15:03 -03:00
|
|
|
var wallet = profileService.getWallet($stateParams.walletId);
|
|
|
|
|
var walletId = wallet.credentials.walletId;
|
2016-09-16 14:40:55 -03:00
|
|
|
$scope.data = {};
|
|
|
|
|
$scope.data.accept = false;
|
2016-09-02 11:15:03 -03:00
|
|
|
|
2016-09-09 11:14:04 -03:00
|
|
|
$scope.save = function() {
|
2016-09-02 11:15:03 -03:00
|
|
|
var opts = {
|
|
|
|
|
emailFor: {}
|
|
|
|
|
};
|
|
|
|
|
opts.emailFor[walletId] = $scope.email;
|
2016-08-25 16:31:47 -03:00
|
|
|
walletService.updateRemotePreferences(wallet, {
|
2016-09-02 11:15:03 -03:00
|
|
|
email: $scope.email,
|
2016-08-25 16:31:47 -03:00
|
|
|
}, function(err) {
|
|
|
|
|
if (err) $log.warn(err);
|
2016-09-02 11:15:03 -03:00
|
|
|
configService.set(opts, function(err) {
|
|
|
|
|
if (err) $log.warn(err);
|
2016-09-13 23:25:50 -03:00
|
|
|
$scope.goNextView();
|
2016-09-02 11:15:03 -03:00
|
|
|
});
|
2016-08-25 16:31:47 -03:00
|
|
|
});
|
|
|
|
|
};
|
2016-09-02 13:00:38 -03:00
|
|
|
|
2016-09-13 23:25:50 -03:00
|
|
|
$scope.goNextView = function() {
|
2016-09-13 17:12:17 -03:00
|
|
|
if (!usePushNotifications) {
|
|
|
|
|
$state.go('onboarding.backupRequest', {
|
|
|
|
|
walletId: walletId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (requiresOptIn) {
|
|
|
|
|
$state.go('onboarding.notifications', {
|
|
|
|
|
walletId: walletId
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
profileService.pushNotificationsInit();
|
|
|
|
|
$state.go('onboarding.backupRequest', {
|
|
|
|
|
walletId: walletId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-09 11:14:04 -03:00
|
|
|
$scope.confirm = function(emailForm) {
|
|
|
|
|
if (emailForm.$invalid) return;
|
|
|
|
|
$scope.confirmation = true;
|
|
|
|
|
$scope.email = emailForm.email.$modelValue;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.cancel = function() {
|
|
|
|
|
$scope.confirmation = false;
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
}, 1);
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-25 16:31:47 -03:00
|
|
|
});
|