Import profile now checks if profile exists

This commit is contained in:
Matias Pando 2014-11-19 11:15:09 -03:00
commit 551da51c41
2 changed files with 26 additions and 20 deletions

View file

@ -28,7 +28,6 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
passphraseConfig: config.passphraseConfig, passphraseConfig: config.passphraseConfig,
}, function(err, iden) { }, function(err, iden) {
if (err) { if (err) {
// if (err && !iden) {
$scope.loading = false; $scope.loading = false;
if ((err.toString() || '').match('BADSTR')) { if ((err.toString() || '').match('BADSTR')) {
@ -38,6 +37,7 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
} else { } else {
$scope.error = 'Unknown error'; $scope.error = 'Unknown error';
} }
$scope.$digest();
} else { } else {
var firstWallet = iden.getLastFocusedWallet(); var firstWallet = iden.getLastFocusedWallet();

View file

@ -300,7 +300,9 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
self.addWallet(w); self.addWallet(w);
self.bindWallet(w); self.bindWallet(w);
var writeOpts = _.extend({ noWallets: true }, opts); var writeOpts = _.extend({
noWallets: true
}, opts);
self.storeWallet(w, function(err) { self.storeWallet(w, function(err) {
if (err) return cb(err); if (err) return cb(err);
@ -365,11 +367,11 @@ Identity.importFromFullJson = function(str, password, opts, cb) {
json.wallets = json.wallets || {}; json.wallets = json.wallets || {};
iden.store(opts, function(err) { iden.store(opts, function(err) {
console.log('Error importing existing profile',err); if (err) return cb(err); //profile already exists
return cb(err, iden);
});
opts.failIfExists = false;
async.map(json.wallets, function(walletData, callback) { async.map(json.wallets, function(walletData, callback) {
if (!walletData) if (!walletData)
return callback(); return callback();
@ -385,6 +387,10 @@ Identity.importFromFullJson = function(str, password, opts, cb) {
return cb(err, iden); return cb(err, iden);
}); });
}); });
});
}; };
Identity.prototype.bindWallet = function(w) { Identity.prototype.bindWallet = function(w) {