Merge pull request #1666 from matiu/bug/more-sync-fixes
Bug/more sync fixes
This commit is contained in:
commit
bd26b23fad
6 changed files with 154 additions and 48 deletions
|
|
@ -158,7 +158,7 @@ Identity.prototype.retrieveWalletFromStorage = function(walletId, opts, callback
|
|||
return callback(error);
|
||||
}
|
||||
try {
|
||||
log.debug('## OPENING Wallet: ' + walletId);
|
||||
log.info('## OPENING Wallet:', walletId);
|
||||
if (_.isString(walletData)) {
|
||||
walletData = JSON.parse(walletData);
|
||||
}
|
||||
|
|
@ -209,7 +209,7 @@ Identity.prototype.storeWallet = function(wallet, cb) {
|
|||
* @param {Function} cb
|
||||
*/
|
||||
Identity.storeWalletDebounced = _.debounce(function(identity, wallet, cb) {
|
||||
identity.storeWallet(wallet,cb);
|
||||
identity.storeWallet(wallet, cb);
|
||||
}, 3000);
|
||||
|
||||
|
||||
|
|
@ -252,10 +252,13 @@ Identity.prototype.store = function(opts, cb) {
|
|||
storeFunction.call(self.storage, this.getId(), this.toObj(), function(err) {
|
||||
if (err) return cb(err);
|
||||
|
||||
console.log('[Identity.js.255:opts:]', opts); //TODO
|
||||
if (opts.noWallets)
|
||||
return cb();
|
||||
|
||||
async.map(self.wallets, self.storeWallet, cb);
|
||||
async.each(_.values(self.wallets), function(wallet, in_cb) {
|
||||
self.storeWallet(wallet, in_cb);
|
||||
}, cb);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -312,11 +315,14 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) {
|
|||
if (!w) return cb(new Error('Could not decrypt'));
|
||||
|
||||
this._checkVersion(w.version);
|
||||
this.addWallet(w, function(err) {
|
||||
if (err) return cb(err, null);
|
||||
self.wallets[w.getId()] = w;
|
||||
self.bindWallet(w);
|
||||
self.store(null, function(err) {
|
||||
this.addWallet(w);
|
||||
self.bindWallet(w);
|
||||
self.storeWallet(w, function(err) {
|
||||
if (err) return cb(err);
|
||||
|
||||
self.store({
|
||||
noWallets: true
|
||||
}, function(err) {
|
||||
return cb(err, w);
|
||||
});
|
||||
});
|
||||
|
|
@ -376,7 +382,7 @@ Identity.prototype.bindWallet = function(w) {
|
|||
var self = this;
|
||||
|
||||
self.wallets[w.getId()] = w;
|
||||
log.debug('Binding wallet ' + w.getName());
|
||||
log.debug('Binding wallet:' + w.getName());
|
||||
|
||||
w.on('txProposalsUpdated', function() {
|
||||
Identity.storeWalletDebounced(self, w);
|
||||
|
|
@ -390,13 +396,6 @@ Identity.prototype.bindWallet = function(w) {
|
|||
w.on('txProposalEvent', function() {
|
||||
Identity.storeWalletDebounced(self, w);
|
||||
});
|
||||
w.on('ready', function() {
|
||||
self.store({
|
||||
noWallets: true
|
||||
}, function() {
|
||||
Identity.storeWalletDebounced(self, w);
|
||||
});
|
||||
});
|
||||
w.on('addressBookUpdated', function() {
|
||||
Identity.storeWalletDebounced(self, w);
|
||||
});
|
||||
|
|
@ -476,23 +475,24 @@ Identity.prototype.createWallet = function(opts, cb) {
|
|||
var self = this;
|
||||
|
||||
var w = new walletClass(opts);
|
||||
this.addWallet(w, function(err) {
|
||||
this.addWallet(w);
|
||||
self.bindWallet(w);
|
||||
w.netStart();
|
||||
self.storeWallet(w, function(err) {
|
||||
if (err) return cb(err);
|
||||
self.bindWallet(w);
|
||||
w.netStart();
|
||||
return cb(err, w);
|
||||
|
||||
self.store({
|
||||
noWallets: true
|
||||
}, function(err) {
|
||||
return cb(err, w);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Identity.prototype.addWallet = function(wallet, cb) {
|
||||
Identity.prototype.addWallet = function(wallet) {
|
||||
preconditions.checkArgument(wallet);
|
||||
preconditions.checkArgument(wallet.getId);
|
||||
preconditions.checkArgument(cb);
|
||||
|
||||
this.wallets[wallet.getId()] = wallet;
|
||||
|
||||
// TODO (eordano): Consider not saving automatically after this
|
||||
this.storage.setItem(wallet.getStorageKey(), wallet.toObj(), cb);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -662,14 +662,7 @@ Identity.prototype.joinWallet = function(opts, cb) {
|
|||
err = 'walletFull';
|
||||
}
|
||||
}
|
||||
if (err)
|
||||
return cb(err);
|
||||
|
||||
self.store({
|
||||
noWallets: true
|
||||
}, function(err) {
|
||||
return cb(err, w);
|
||||
});
|
||||
return cb(err, w);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue