Wallet/src/js/controllers/disclaimer.js
2016-03-09 11:53:47 -03:00

60 lines
1.7 KiB
JavaScript

'use strict';
angular.module('copayApp.controllers').controller('disclaimerController',
function($scope, $timeout, $log, profileService, isCordova, applicationService, gettextCatalog, uxLanguage, go) {
var self = this;
self.tries = 0;
$scope.creatingProfile = true;
var create = function(noWallet) {
profileService.create({
noWallet: noWallet
}, function(err) {
if (err) {
$log.warn(err);
$scope.error = err;
$scope.$apply();
$timeout(function() {
$log.warn('Retrying to create profile......');
if (self.tries == 3) {
self.tries == 0;
create(true);
} else {
self.tries += 1;
create(false);
}
}, 3000);
} else {
$scope.error = "";
$scope.creatingProfile = false;
}
});
};
this.init = function() {
self.lang = uxLanguage.currentLanguage;
profileService.getProfile(function(err, profile) {
if (!profile) {
create(false);
} else {
$log.debug('There is a profile already');
$scope.creatingProfile = false;
profileService.bindProfile(profile, function(err) {
if (!err || !err.message || !err.message.match('NONAGREEDDISCLAIMER')) {
$log.debug('Disclaimer already accepted at #disclaimer. Redirect to Wallet Home.')
go.walletHome();
}
});
}
});
};
this.accept = function() {
profileService.setDisclaimerAccepted(function(err) {
if (err) $log.error(err);
else go.walletHome();
});
};
});