save profile on wallet import

This commit is contained in:
Ivan Socolsky 2015-01-05 10:58:02 -03:00
commit b1e686ee68

View file

@ -468,11 +468,16 @@ Identity.prototype.close = function() {
Identity.prototype.importWalletFromObj = function(obj, opts, cb) { Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
var self = this; var self = this;
preconditions.checkArgument(cb); preconditions.checkArgument(cb);
self.verifyChecksum(function(err, match) {
if (err) return cb(err);
if (!match) return cb('The profile is out of sync. Please re-login to get the latest changes.');
var importFunction = opts.importWallet || Wallet.fromUntrustedObj; var importFunction = opts.importWallet || Wallet.fromUntrustedObj;
var readOpts = { var readOpts = {
networkOpts: this.networkOpts, networkOpts: self.networkOpts,
blockchainOpts: this.blockchainOpts, blockchainOpts: self.blockchainOpts,
skipFields: opts.skipFields, skipFields: opts.skipFields,
}; };
@ -484,10 +489,21 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
log.debug('Updating Indexes for wallet:' + w.getName()); log.debug('Updating Indexes for wallet:' + w.getName());
w.updateIndexes(function(err) { w.updateIndexes(function(err) {
log.debug('Adding wallet to profile:' + w.getName()); log.debug('Adding wallet to profile:' + w.getName());
self.storeWallet(w, function (err) {
if (err) return cb(err);
self.addWallet(w); self.addWallet(w);
self.updateFocusedTimestamp(w.getId()); self.updateFocusedTimestamp(w.getId());
self.bindWallet(w); self.bindWallet(w);
self.storeWallet(w, cb);
self.backupNeeded = true;
self.store({
noWallets: true,
}, function(err) {
return cb(err);
});
});
});
}); });
}; };