fixing import of existing profile

This commit is contained in:
Ivan Socolsky 2014-11-18 12:12:09 -03:00
commit af6c066c3f
2 changed files with 23 additions and 7 deletions

View file

@ -27,9 +27,18 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
walletDefaults: config.wallet, walletDefaults: config.wallet,
passphraseConfig: config.passphraseConfig, passphraseConfig: config.passphraseConfig,
}, function(err, iden) { }, function(err, iden) {
if (err && !iden) { if (err) {
// if (err && !iden) {
$scope.loading = false; $scope.loading = false;
$scope.error = (err.toString() || '').match('BADSTR') ? 'Bad password or corrupt profile file' : 'Unknown error';
if ((err.toString() || '').match('BADSTR')) {
$scope.error ='Bad password or corrupt profile file';
} else if ((err.toString() || '').match('EEXISTS')) {
$scope.error = 'Profile already exists';
} else {
$scope.error = 'Unknown error';
}
} else { } else {
var firstWallet = iden.getLastFocusedWallet(); var firstWallet = iden.getLastFocusedWallet();
controllerUtils.bindProfile($scope, iden, firstWallet); controllerUtils.bindProfile($scope, iden, firstWallet);

View file

@ -299,11 +299,12 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
log.debug('Adding wallet to profile:' + w.getName()); log.debug('Adding wallet to profile:' + w.getName());
self.addWallet(w); self.addWallet(w);
self.bindWallet(w); self.bindWallet(w);
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);
self.store({ self.store(writeOpts, function(err) {
noWallets: true
}, function(err) {
return cb(err, w); return cb(err, w);
}); });
}); });
@ -327,7 +328,6 @@ Identity.importFromEncryptedFullJson = function(ejson, password, opts, cb) {
var crypto = opts.cryptoUtil || cryptoUtil; var crypto = opts.cryptoUtil || cryptoUtil;
var str = crypto.decrypt(password, ejson); var str = crypto.decrypt(password, ejson);
if (!str) { if (!str) {
// 0.7.3 broken KDF // 0.7.3 broken KDF
log.debug('Trying legacy encryption...'); log.debug('Trying legacy encryption...');
@ -360,8 +360,15 @@ Identity.importFromFullJson = function(str, password, opts, cb) {
var iden = new Identity(opts); var iden = new Identity(opts);
opts.failIfExists = true;
json.wallets = json.wallets || {}; json.wallets = json.wallets || {};
iden.store(opts, function(err) {
console.log('Error importing existing profile',err);
return cb(err, iden);
});
async.map(json.wallets, function(walletData, callback) { async.map(json.wallets, function(walletData, callback) {
if (!walletData) if (!walletData)
return callback(); return callback();
@ -374,7 +381,7 @@ Identity.importFromFullJson = function(str, password, opts, cb) {
}, function(err, results) { }, function(err, results) {
if (err) return cb(err); if (err) return cb(err);
iden.store(null, function(err) { iden.store(opts, function(err) {
return cb(err, iden); return cb(err, iden);
}); });
}); });