mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Fix orderbook unsubscribe
This commit is contained in:
@@ -36,11 +36,9 @@ function OrderBook(remote, currency_gets, issuer_gets, currency_pays, issuer_pay
|
|||||||
|
|
||||||
function listenerAdded(type, listener) {
|
function listenerAdded(type, listener) {
|
||||||
if (~OrderBook.subscribe_events.indexOf(type)) {
|
if (~OrderBook.subscribe_events.indexOf(type)) {
|
||||||
|
self._subs += 1;
|
||||||
if (!self._subs && self._remote._connected) {
|
if (!self._subs && self._remote._connected) {
|
||||||
self._subs += 1;
|
|
||||||
self._subscribe();
|
self._subscribe();
|
||||||
} else {
|
|
||||||
self._subs += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -59,6 +57,8 @@ function OrderBook(remote, currency_gets, issuer_gets, currency_pays, issuer_pay
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.on('removeListener', listenerRemoved);
|
||||||
|
|
||||||
// ST: This *should* call _prepareSubscribe.
|
// ST: This *should* call _prepareSubscribe.
|
||||||
this._remote.on('prepare_subscribe', this._subscribe.bind(this));
|
this._remote.on('prepare_subscribe', this._subscribe.bind(this));
|
||||||
|
|
||||||
@@ -85,17 +85,21 @@ OrderBook.subscribe_events = ['transaction', 'model', 'trade'];
|
|||||||
*/
|
*/
|
||||||
OrderBook.prototype._subscribe = function () {
|
OrderBook.prototype._subscribe = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (self.is_valid() && self._subs) {
|
if (self.is_valid() && self._subs) {
|
||||||
var request = this._remote.request_subscribe();
|
var request = this._remote.request_subscribe();
|
||||||
request.addBook(self.to_json(), true);
|
request.addBook(self.to_json(), true);
|
||||||
|
|
||||||
request.once('success', function(res) {
|
request.once('success', function(res) {
|
||||||
self._sync = true;
|
self._sync = true;
|
||||||
self._offers = res.offers;
|
self._offers = res.offers;
|
||||||
self.emit('model', self._offers);
|
self.emit('model', self._offers);
|
||||||
});
|
});
|
||||||
|
|
||||||
request.once('error', function(err) {
|
request.once('error', function(err) {
|
||||||
// XXX What now?
|
// XXX What now?
|
||||||
});
|
});
|
||||||
|
|
||||||
request.request();
|
request.request();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user