add disclaimer controller test

This commit is contained in:
Matias Alejo Garcia 2016-06-05 16:27:49 -03:00
commit 7781b93a88
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
5 changed files with 122 additions and 22 deletions

View file

@ -4,45 +4,53 @@ angular.module('copayApp.controllers').controller('disclaimerController',
function($scope, $timeout, $log, $ionicSideMenuDelegate, profileService, applicationService, gettextCatalog, uxLanguage, go) {
var self = this;
self.tries = 0;
$scope.creatingProfile = true;
self.creatingProfile = true;
var create = function(noWallet) {
profileService.create({
noWallet: noWallet
}, function(err) {
var create = function(opts) {
opts = opts || {};
$log.debug('Creating profile');
profileService.create(opts, function(err) {
console.log('[disclaimer.js.13]', err); //TODO
if (err) {
$log.warn(err);
$scope.error = err;
$scope.$apply();
$timeout(function() {
return $timeout(function() {
$log.warn('Retrying to create profile......');
if (self.tries == 3) {
self.tries == 0;
create(true);
return create({
noWallet: true
});
} else {
self.tries += 1;
create(false);
return create();
}
}, 3000);
} else {
$scope.error = "";
$scope.creatingProfile = false;
}
};
$scope.error = "";
self.creatingProfile = false;
console.log('[disclaimer.js.33]'); //TODO
});
};
this.init = function() {
this.init = function(opts) {
$ionicSideMenuDelegate.canDragContent(false);
self.lang = uxLanguage.currentLanguage;
profileService.getProfile(function(err, profile) {
if (!profile) {
create(false);
console.log('[disclaimer.js.43]'); //TODO
create(opts);
console.log('[disclaimer.js.46]'); //TODO
} else {
$log.debug('There is a profile already');
$scope.creatingProfile = false;
$log.info('There is already a profile');
self.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.');

View file

@ -224,6 +224,7 @@ angular.module('copayApp.services')
root._seedWallet = function(opts, cb) {
opts = opts || {};
$log.debug('seedWallet', opts);
var walletClient = bwcService.getClient(null, opts);
var network = opts.networkName || 'livenet';
@ -291,13 +292,15 @@ angular.module('copayApp.services')
return cb(null, Profile.create());
}
root._seedWallet({}, function(err, walletClient) {
root._seedWallet(opts, function(err, walletClient) {
if (err) return cb(err);
var walletName = gettextCatalog.getString('Personal Wallet');
var me = gettextCatalog.getString('me');
walletClient.createWallet(walletName, me, 1, 1, {
network: 'livenet'
network: 'livenet',
walletPrivKey: opts.walletPrivKey,
}, function(err) {
if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb);
var p = Profile.create({
@ -559,16 +562,24 @@ angular.module('copayApp.services')
};
root.create = function(opts, cb) {
$log.info('Creating profile');
$log.info('Creating profile', opts);
var defaults = configService.getDefaults();
console.log('[profileService.js.567]'); //TODO
configService.get(function(err) {
console.log('[profileService.js.570]'); //TODO
root._createNewProfile(opts, function(err, p) {
if (err) return cb(err);
console.log('[profileService.js.574]'); //TODO
root.bindProfile(p, function(err) {
console.log('[profileService.js.577]'); //TODO
// ignore NONAGREEDDISCLAIMER
storageService.storeNewProfile(p, function(err) {
console.log('[profileService.js.581]'); //TODO
return cb(err);
});
});