Merge pull request #2263 from isocolsky/fix/import_wallet

Fix/import wallet
This commit is contained in:
Matias Alejo Garcia 2015-01-05 11:06:08 -03:00
commit 69dbf89847
2 changed files with 35 additions and 19 deletions

View file

@ -53,7 +53,7 @@ module.exports = function(grunt) {
'!js/copayBundle.js', '!js/copayBundle.js',
'!js/copayMain.js' '!js/copayMain.js'
], ],
tasks: ['shell:dev'] tasks: ['exec:dev']
}, },
css: { css: {
files: ['css/src/*.css'], files: ['css/src/*.css'],

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);
});
});
});
}); });
}; };