made Identity#create asynchronous

This commit is contained in:
Ivan Socolsky 2014-10-30 18:08:50 -03:00
commit 7e8f1a1668
3 changed files with 79 additions and 55 deletions

View file

@ -4,8 +4,26 @@ angular.module('copayApp.services')
.factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) {
var root = {};
root.check = function(scope) {
copay.Identity.checkIfExistsAny({
pluginManager: pluginManager,
}, function(anyProfile) {
copay.Wallet.checkIfExistsAny({
pluginManager: pluginManager,
}, function(anyWallet) {
scope.retreiving = false;
scope.anyProfile = anyProfile ? true : false;
scope.anyWallet = anyWallet ? true : false;
if (!scope.anyProfile) {
$location.path('/createProfile');
}
});
});
};
root.create = function(scope, form) {
var iden = copay.Identity.create({
copay.Identity.create({
email: form.email.$modelValue,
password: form.password.$modelValue,
pluginManager: pluginManager,
@ -13,31 +31,30 @@ angular.module('copayApp.services')
networkName: config.networkName,
walletDefaults: config.wallet,
passphraseConfig: config.passphraseConfig,
failIfExists: true,
}, function(err, iden) {
if (err || !iden) {
controllerUtils.onErrorDigest(scope, 'User already exists!');
return;
}
var walletOptions = {
nickname: iden.fullName,
networkName: config.networkName,
requiredCopayers: 1,
totalCopayers: 1,
password: iden.password,
name: 'My wallet',
};
iden.createWallet(walletOptions, function(err, wallet) {
if (err || !wallet) {
controllerUtils.onErrorDigest(scope, 'Could not create default wallet');
return;
}
scope.loading = false;
controllerUtils.bindProfile(scope, iden, wallet.id);
});
});
var walletOptions = {
nickname: iden.fullName,
networkName: config.networkName,
requiredCopayers: 1,
totalCopayers: 1,
password: iden.password,
name: 'My wallet',
};
iden.createWallet(walletOptions, function(err, wallet) {
if (err) {
controllerUtils.onErrorDigest(
scope, 'Could not create default wallet');
} else {
iden.store({failIfExists: true}, function(err) {
if (err) {
controllerUtils.onErrorDigest(scope, 'User already exists!');
} else {
controllerUtils.bindProfile(scope, iden, wallet.id);
}
});
}
scope.loading = false;
});
};
@ -60,7 +77,7 @@ angular.module('copayApp.services')
}
scope.loading = false;
});
};
};
return root;
});