fix create profile

This commit is contained in:
Matias Alejo Garcia 2014-11-30 03:58:38 -03:00
commit 1e013b1bb6
7 changed files with 37 additions and 34 deletions

View file

@ -1,21 +1,24 @@
'use strict';
angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, notification, pluginManager, identityService) {
identityService.goWalletHome();
$scope.loading = false;
$scope.createProfile = function(form) {
if (form && form.$invalid) {
$scope.error('Error', 'Please enter the required fields');
return;
}
$rootScope.starting = true;
identityService.create(
form.email.$modelValue, form.password.$modelValue, function(err) {
if (err) $scope.error('Error', err.toString());
$rootScope.$digest();
$rootScope.starting = false;
if (err) {
var msg = err.toString();
if (msg.indexOf('EEXIST')>=0 || msg.indexOf('BADC')>=0 ) {
msg = 'This profile already exists'
}
$scope.error = msg;
}
});
}
});

View file

@ -342,8 +342,8 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
log.debug('Updating Indexes for wallet:' + w.getName());
w.updateIndexes(function(err) {
log.debug('Adding wallet to profile:' + w.getName());
self.updateFocusedTimestamp(w.getId());
self.bindWallet(w);
self.updateFocusedTimestamp(w.getId());
var writeOpts = _.extend({
noWallets: true
@ -544,8 +544,8 @@ Identity.prototype.createWallet = function(opts, cb) {
var self = this;
var w = new walletClass(opts);
self.updateFocusedTimestamp(w.getId());
self.bindWallet(w);
self.updateFocusedTimestamp(w.getId());
self.storeWallet(w, function(err) {
if (err) return cb(err);
self.store({
@ -636,7 +636,7 @@ Identity.prototype.decodeSecret = function(secret) {
*/
Identity.prototype.getLastFocusedWalletId = function() {
var max = _.max(this.focusedTimestamp);
var aId = this.wallets[0] ? this.wallets[0].getId() : this.walletIds[0];
var aId = _.findKey(this.wallets) || this.walletIds[0];
if (!max)
return aId;

View file

@ -77,7 +77,6 @@ angular.module('copayApp.services')
w.balanceInfo.updating = false;
if (isFocused) {
_.extend($rootScope, w.balanceInfo);
$rootScope.updatingBalance = false;
}
if (cb) cb();

View file

@ -37,10 +37,10 @@ angular.module('copayApp.services')
}
};
root.create = function(email, password) {
root.create = function(email, password, cb) {
copay.Identity.create({
email: form.email.$modelValue,
password: form.password.$modelValue,
email: email,
password: password,
pluginManager: pluginManager,
network: config.network,
networkName: config.networkName,
@ -50,6 +50,7 @@ angular.module('copayApp.services')
}, function(err, iden) {
if (err) return cb(err);
preconditions.checkState(iden);
root.bind(iden);
var walletOptions = {
nickname: iden.fullName,
@ -60,10 +61,7 @@ angular.module('copayApp.services')
name: 'My wallet',
};
iden.createWallet(walletOptions, function(err, wallet) {
if (err) return cb(err);
root.bind(iden);
return cb();
return cb(err);
});
});
@ -314,6 +312,9 @@ angular.module('copayApp.services')
passphraseConfig: config.passphraseConfig,
}, function(err, iden) {
if (err) return cb(err);
root.bind(iden);
iden.openWallets();
return cb();
});
};