2016-08-25 16:31:47 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-09-02 16:29:14 -03:00
|
|
|
angular.module('copayApp.controllers').controller('collectEmailController', function($scope, $state, $stateParams, profileService, configService, walletService, platformInfo) {
|
2016-08-29 11:56:31 -03:00
|
|
|
|
2016-08-29 17:42:19 -03:00
|
|
|
var isCordova = platformInfo.isCordova;
|
|
|
|
|
var isWP = platformInfo.isWP;
|
|
|
|
|
var usePushNotifications = isCordova && !isWP;
|
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;
|
|
|
|
|
|
|
|
|
|
var config = configService.getSync();
|
|
|
|
|
config.emailFor = config.emailFor || {};
|
|
|
|
|
$scope.email = config.emailFor && config.emailFor[walletId];
|
|
|
|
|
|
2016-08-25 16:31:47 -03:00
|
|
|
$scope.save = function(form) {
|
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-02 15:42:45 -03:00
|
|
|
if (!usePushNotifications) $state.go('onboarding.backupRequest', {walletId: walletId});
|
|
|
|
|
else $state.go('onboarding.notifications', {walletId: walletId});
|
2016-09-02 11:15:03 -03:00
|
|
|
});
|
2016-08-25 16:31:47 -03:00
|
|
|
});
|
|
|
|
|
};
|
2016-09-02 13:00:38 -03:00
|
|
|
|
|
|
|
|
$scope.onboardingMailSkip = function() {
|
2016-09-02 15:42:45 -03:00
|
|
|
$state.go('onboarding.backupRequest', {walletId: walletId});
|
2016-09-02 13:00:38 -03:00
|
|
|
};
|
2016-08-25 16:31:47 -03:00
|
|
|
});
|