From 1e013b1bb6eda03775fa0a089784e337c50e2afc Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 30 Nov 2014 03:58:38 -0300 Subject: [PATCH] fix create profile --- js/controllers/createProfile.js | 15 +++++++++------ js/models/Identity.js | 6 +++--- js/services/balanceService.js | 1 - js/services/identityService.js | 15 ++++++++------- views/homeWallet.html | 8 ++++---- views/includes/sidebar-mobile.html | 10 +++++----- views/includes/sidebar.html | 16 ++++++++-------- 7 files changed, 37 insertions(+), 34 deletions(-) diff --git a/js/controllers/createProfile.js b/js/controllers/createProfile.js index bfa415211..9ddcec3db 100644 --- a/js/controllers/createProfile.js +++ b/js/controllers/createProfile.js @@ -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; + } }); } - }); diff --git a/js/models/Identity.js b/js/models/Identity.js index 002a78517..1b8ff7632 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -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; diff --git a/js/services/balanceService.js b/js/services/balanceService.js index e6a1cc394..448ec7d47 100644 --- a/js/services/balanceService.js +++ b/js/services/balanceService.js @@ -77,7 +77,6 @@ angular.module('copayApp.services') w.balanceInfo.updating = false; if (isFocused) { - _.extend($rootScope, w.balanceInfo); $rootScope.updatingBalance = false; } if (cb) cb(); diff --git a/js/services/identityService.js b/js/services/identityService.js index ad72512b0..4a0096e7f 100644 --- a/js/services/identityService.js +++ b/js/services/identityService.js @@ -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(); }); }; diff --git a/views/homeWallet.html b/views/homeWallet.html index 22d338235..bba7198e8 100644 --- a/views/homeWallet.html +++ b/views/homeWallet.html @@ -17,15 +17,15 @@
- {{totalBalance || 0 |noFractionNumber}} + {{$root.wallet.balanceInfo.totalBalance || 0 |noFractionNumber}} {{$root.wallet.settings.unitName}} - {{totalBalanceAlternative |noFractionNumber:2}} {{alternativeIsoCode}} - N/A - + {{$root.wallet.balanceInfo.totalBalanceAlternative |noFractionNumber:2}} {{$root.wallet.balanceInfo.alternativeIsoCode}} + N/A +
diff --git a/views/includes/sidebar-mobile.html b/views/includes/sidebar-mobile.html index 6be650752..ccc9ffb43 100644 --- a/views/includes/sidebar-mobile.html +++ b/views/includes/sidebar-mobile.html @@ -14,11 +14,11 @@
Waiting for copayers...
- -
- {{totalBalance || 0 |noFractionNumber}} {{$root.wallet.settings.unitName}} - {{totalBalanceAlternative |noFractionNumber:2}} {{alternativeIsoCode}} - N/A + +
+ {{$root.wallet.balanceInfo.totalBalance || 0 |noFractionNumber}} {{$root.wallet.settings.unitName}} + {{$root.wallet.balanceInfo.totalBalanceAlternative |noFractionNumber:2}} {{$root.wallet.balanceInfo.alternativeIsoCode}} + N/A
diff --git a/views/includes/sidebar.html b/views/includes/sidebar.html index 2c6386d14..ae621b153 100644 --- a/views/includes/sidebar.html +++ b/views/includes/sidebar.html @@ -13,11 +13,11 @@
Waiting for copayers...
- -
- {{totalBalance || 0 |noFractionNumber}} {{$root.wallet.settings.unitName}} - {{totalBalanceAlternative |noFractionNumber:2}} {{alternativeIsoCode}} - N/A + +
+ {{$root.wallet.balanceInfo.totalBalance || 0 |noFractionNumber}} {{$root.wallet.settings.unitName}} + {{$root.wallet.balanceInfo.totalBalanceAlternative |noFractionNumber:2}} {{alternativeIsoCode}} + N/A
@@ -34,12 +34,12 @@
-
+
{{'Locked'|translate}}   - - {{lockedBalance || 0|noFractionNumber}} {{$root.wallet.settings.unitName}} - {{lockedBalanceAlternative |noFractionNumber:2}} {{alternativeIsoCode}} + + {{$root.wallet.balanceInfo.lockedBalance || 0|noFractionNumber}} {{$root.wallet.settings.unitName}} - {{$root.wallet.balanceInfo.lockedBalanceAlternative |noFractionNumber:2}} {{$root.wallet.balanceInfo.alternativeIsoCode}}