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,17 +28,17 @@ angular.module('copayApp.controllers').controller('ImportProfileController',
|
|||
passphraseConfig: config.passphraseConfig,
|
||||
}, function(err, iden) {
|
||||
if (err) {
|
||||
// if (err && !iden) {
|
||||
$scope.loading = false;
|
||||
|
||||
|
||||
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')) {
|
||||
$scope.error = 'Profile already exists';
|
||||
} else {
|
||||
$scope.error = 'Unknown error';
|
||||
}
|
||||
|
||||
$scope.$digest();
|
||||
|
||||
} else {
|
||||
var firstWallet = iden.getLastFocusedWallet();
|
||||
controllerUtils.bindProfile($scope, iden, firstWallet);
|
||||
|
|
|
|||
|
|
@ -300,7 +300,9 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
|
|||
self.addWallet(w);
|
||||
self.bindWallet(w);
|
||||
|
||||
var writeOpts = _.extend({ noWallets: true }, opts);
|
||||
var writeOpts = _.extend({
|
||||
noWallets: true
|
||||
}, opts);
|
||||
|
||||
self.storeWallet(w, function(err) {
|
||||
if (err) return cb(err);
|
||||
|
|
@ -365,26 +367,30 @@ Identity.importFromFullJson = function(str, password, opts, cb) {
|
|||
json.wallets = json.wallets || {};
|
||||
|
||||
iden.store(opts, function(err) {
|
||||
console.log('Error importing existing profile',err);
|
||||
return cb(err, iden);
|
||||
if (err) return cb(err); //profile already exists
|
||||
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue