Wallet/src/js/controllers/disclaimer.js

60 lines
1.7 KiB
JavaScript
Raw Normal View History

'use strict';
angular.module('copayApp.controllers').controller('disclaimerController',
function($scope, $timeout, $log, profileService, isCordova, applicationService, gettextCatalog, uxLanguage, go) {
2015-12-16 01:41:16 -03:00
var self = this;
2015-12-14 14:02:27 -03:00
self.tries = 0;
$scope.creatingProfile = true;
2015-12-14 14:02:27 -03:00
var create = function(noWallet) {
profileService.create({
noWallet: noWallet
}, function(err) {
2015-11-17 13:36:31 -03:00
if (err) {
2015-11-24 17:16:52 -03:00
$log.warn(err);
2015-11-30 13:32:54 -03:00
$scope.error = err;
$scope.$apply();
$timeout(function() {
$log.warn('Retrying to create profile......');
2015-12-14 14:02:27 -03:00
if (self.tries == 3) {
self.tries == 0;
create(true);
} else {
self.tries += 1;
create(false);
}
2015-11-30 13:32:54 -03:00
}, 3000);
2015-11-17 13:36:31 -03:00
} else {
$scope.error = "";
$scope.creatingProfile = false;
}
});
};
2015-11-17 11:10:09 -03:00
2015-12-04 18:45:35 -03:00
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();
}
});
}
});
2015-12-04 18:45:35 -03:00
};
2016-02-22 19:32:24 -03:00
this.accept = function() {
profileService.setDisclaimerAccepted(function(err) {
if (err) $log.error(err);
else go.walletHome();
});
};
});