Wallet/src/js/controllers/disclaimer.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

'use strict';
angular.module('copayApp.controllers').controller('disclaimerController',
2015-11-24 17:16:52 -03:00
function($scope, $timeout, $log, profileService, isCordova, storageService, applicationService, gettextCatalog, uxLanguage, go) {
2015-11-17 12:39:51 -03:00
self = this;
2015-11-17 13:36:31 -03:00
$scope.lang = uxLanguage.currentLanguage;
2015-11-17 13:36:31 -03:00
$scope.goHome = function() {
storageService.getProfile(function(err, profile) {
profile.agreeDisclaimer = true;
storageService.storeProfile(profile, function() {
go.walletHome();
});
2015-11-23 12:17:04 -03:00
});
};
2015-11-17 15:49:17 -03:00
var create = function() {
2015-11-17 13:36:31 -03:00
$scope.creatingProfile = true;
profileService.create({}, function(err) {
if (err) {
2015-11-24 17:16:52 -03:00
$log.warn(err);
2015-11-23 12:17:04 -03:00
if (err == 'EEXISTS') {
if (profileService.profile.agreeDisclaimer) return go.walletHome();
$scope.creatingProfile = false;
2015-11-23 12:17:04 -03:00
} else {
$scope.error = err;
$scope.$apply();
$timeout(function() {
$log.warn('Retrying to create profile......');
create();
}, 3000);
}
2015-11-17 13:36:31 -03:00
} else {
$scope.error = "";
$scope.creatingProfile = false;
}
});
};
2015-11-17 11:10:09 -03:00
storageService.getProfile(function(err, profile) {
if (!profile) create();
else $scope.creatingProfile = false;
});
});