mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Fix orderbook reset on reconnect
This commit is contained in:
@@ -78,19 +78,20 @@ function OrderBook(remote, getsC, getsI, paysC, paysI, key) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.on('unsubscribe', function() {
|
this.on('unsubscribe', function() {
|
||||||
self._ownerFunds = { };
|
self.resetCache();
|
||||||
self._remote.removeListener('transaction', updateFundedAmounts);
|
self._remote.removeListener('transaction', updateFundedAmounts);
|
||||||
self._remote.removeListener('transaction', updateTransferRate);
|
self._remote.removeListener('transaction', updateTransferRate);
|
||||||
});
|
});
|
||||||
|
|
||||||
this._remote.on('prepare_subscribe', function() {
|
this._remote.once('prepare_subscribe', function() {
|
||||||
self.subscribe();
|
self.subscribe();
|
||||||
});
|
});
|
||||||
|
|
||||||
this._remote.on('disconnect', function() {
|
this._remote.on('disconnect', function() {
|
||||||
self._ownerFunds = { };
|
self.resetCache();
|
||||||
self._offerCounts = { };
|
self._remote.once('prepare_subscribe', function() {
|
||||||
self._synchronized = false;
|
self.subscribe();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateFundedAmounts(message) {
|
function updateFundedAmounts(message) {
|
||||||
@@ -195,6 +196,16 @@ OrderBook.prototype.unsubscribe = function() {
|
|||||||
this.emit('unsubscribe');
|
this.emit('unsubscribe');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset cached owner funds, offer counts
|
||||||
|
*/
|
||||||
|
|
||||||
|
OrderBook.prototype.resetCache = function() {
|
||||||
|
this._ownerFunds = { };
|
||||||
|
this._offerCounts = { };
|
||||||
|
this._synchronized = false;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that the funds for offer owner have been cached
|
* Check that the funds for offer owner have been cached
|
||||||
*
|
*
|
||||||
@@ -695,6 +706,9 @@ OrderBook.prototype.requestOffers = function(callback) {
|
|||||||
log.info('requested offers', self._key, 'offers: ' + res.offers.length);
|
log.info('requested offers', self._key, 'offers: ' + res.offers.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset offers
|
||||||
|
self._offers = [ ];
|
||||||
|
|
||||||
for (var i=0, l=res.offers.length; i<l; i++) {
|
for (var i=0, l=res.offers.length; i<l; i++) {
|
||||||
var offer = res.offers[i];
|
var offer = res.offers[i];
|
||||||
var fundedAmount;
|
var fundedAmount;
|
||||||
|
|||||||
@@ -1546,7 +1546,7 @@ describe('OrderBook', function() {
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
book.once('model', function(model) {
|
book.on('model', function(model) {
|
||||||
assert.deepEqual(model, expected);
|
assert.deepEqual(model, expected);
|
||||||
assert.strictEqual(book._synchronized, true);
|
assert.strictEqual(book._synchronized, true);
|
||||||
done();
|
done();
|
||||||
|
|||||||
Reference in New Issue
Block a user