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

@ -82,10 +82,14 @@ Identity.prototype.getName = function() {
* @param cb
* @return {undefined}
*/
Identity.create = function(opts) {
Identity.create = function(opts, cb) {
opts = _.extend({}, opts);
return new Identity(opts);
var iden = new Identity(opts);
iden.store(opts, function(err) {
if (err) return cb(err);
return cb(null, iden);
});
};
@ -386,7 +390,9 @@ Identity.prototype.bindWallet = function(w) {
});
w.on('ready', function() {
log.debug('<ready> Wallet' + w.getName());
self.store({noWallets:true}, function() {
self.store({
noWallets: true
}, function() {
self.storeWallet(w);
});
});

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;
});