Import profile now checks if profile exists
This commit is contained in:
parent
af6c066c3f
commit
551da51c41
2 changed files with 26 additions and 20 deletions
|
|
@ -28,16 +28,16 @@ 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')) {
|
||||||
$scope.error ='Bad password or corrupt profile file';
|
$scope.error = 'Bad password or corrupt profile file';
|
||||||
} else if ((err.toString() || '').match('EEXISTS')) {
|
} else if ((err.toString() || '').match('EEXISTS')) {
|
||||||
$scope.error = 'Profile already exists';
|
$scope.error = 'Profile already exists';
|
||||||
} else {
|
} else {
|
||||||
$scope.error = 'Unknown error';
|
$scope.error = 'Unknown error';
|
||||||
}
|
}
|
||||||
|
$scope.$digest();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var firstWallet = iden.getLastFocusedWallet();
|
var firstWallet = iden.getLastFocusedWallet();
|
||||||
|
|
|
||||||
|
|
@ -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,26 +367,30 @@ 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) {
|
||||||
|
|
||||||
|
if (!walletData)
|
||||||
|
return callback();
|
||||||
|
|
||||||
|
iden.importWalletFromObj(walletData, opts, function(err, w) {
|
||||||
|
if (err) return callback(err);
|
||||||
|
log.debug('Wallet ' + w.getId() + ' imported');
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}, function(err, results) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
|
||||||
|
iden.store(opts, function(err) {
|
||||||
|
return cb(err, iden);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async.map(json.wallets, function(walletData, callback) {
|
|
||||||
if (!walletData)
|
|
||||||
return callback();
|
|
||||||
|
|
||||||
iden.importWalletFromObj(walletData, opts, function(err, w) {
|
|
||||||
if (err) return callback(err);
|
|
||||||
log.debug('Wallet ' + w.getId() + ' imported');
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}, function(err, results) {
|
|
||||||
if (err) return cb(err);
|
|
||||||
|
|
||||||
iden.store(opts, function(err) {
|
|
||||||
return cb(err, iden);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Identity.prototype.bindWallet = function(w) {
|
Identity.prototype.bindWallet = function(w) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue