mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
Fix requestOffers not returning an EventEmitter
This commit is contained in:
@@ -153,8 +153,20 @@ OrderBook.prototype.subscribe = function() {
|
||||
log.info('subscribing', this._key);
|
||||
}
|
||||
|
||||
this.requestOffers().once('success', function() {
|
||||
self.subscribeTransactions();
|
||||
var steps = [
|
||||
function(callback) {
|
||||
self.requestTransferRate(callback);
|
||||
},
|
||||
function(callback) {
|
||||
self.requestOffers(callback);
|
||||
},
|
||||
function(callback) {
|
||||
self.subscribeTransactions(callback);
|
||||
}
|
||||
];
|
||||
|
||||
async.series(steps, function(err) {
|
||||
//XXX What now?
|
||||
});
|
||||
};
|
||||
|
||||
@@ -646,25 +658,15 @@ OrderBook.prototype.updateTransferRate = function(message) {
|
||||
* Request orderbook entries from server
|
||||
*/
|
||||
|
||||
OrderBook.prototype.requestOffers = function() {
|
||||
OrderBook.prototype.requestOffers = function(callback) {
|
||||
var self = this;
|
||||
|
||||
if (!this._shouldSubscribe) {
|
||||
return;
|
||||
if (typeof callback !== 'function') {
|
||||
callback = function(){};
|
||||
}
|
||||
|
||||
if (!this._currencyGets.is_native() && !this._issuerTransferRate) {
|
||||
// Defer until transfer rate is requested
|
||||
if (this._remote.trace) {
|
||||
log.info('waiting for transfer rate');
|
||||
}
|
||||
|
||||
this.once('transfer_rate', function() {
|
||||
self.requestOffers();
|
||||
});
|
||||
|
||||
this.requestTransferRate();
|
||||
return;
|
||||
if (!this._shouldSubscribe) {
|
||||
return callback(new Error('Should not request offers'));
|
||||
}
|
||||
|
||||
if (this._remote.trace) {
|
||||
@@ -674,7 +676,7 @@ OrderBook.prototype.requestOffers = function() {
|
||||
function handleOffers(res) {
|
||||
if (!Array.isArray(res.offers)) {
|
||||
// XXX What now?
|
||||
return;
|
||||
return callback(new Error('Invalid response'));
|
||||
}
|
||||
|
||||
if (self._remote.trace) {
|
||||
@@ -700,6 +702,8 @@ OrderBook.prototype.requestOffers = function() {
|
||||
self._synchronized = true;
|
||||
|
||||
self.emit('model', self._offers);
|
||||
|
||||
callback(null, self._offers);
|
||||
};
|
||||
|
||||
function handleError(err) {
|
||||
@@ -707,6 +711,8 @@ OrderBook.prototype.requestOffers = function() {
|
||||
if (self._remote.trace) {
|
||||
log.info('failed to request offers', self._key, err);
|
||||
}
|
||||
|
||||
callback(err);
|
||||
};
|
||||
|
||||
var request = this._remote.requestBookOffers(this.toJSON());
|
||||
@@ -721,28 +727,37 @@ OrderBook.prototype.requestOffers = function() {
|
||||
* Subscribe to transactions stream
|
||||
*/
|
||||
|
||||
OrderBook.prototype.subscribeTransactions = function() {
|
||||
OrderBook.prototype.subscribeTransactions = function(callback) {
|
||||
var self = this;
|
||||
|
||||
if (typeof callback !== 'function') {
|
||||
callback = function(){};
|
||||
}
|
||||
|
||||
if (!this._shouldSubscribe) {
|
||||
return;
|
||||
return callback('Should not subscribe');
|
||||
}
|
||||
|
||||
if (this._remote.trace) {
|
||||
log.info('subscribing to transactions');
|
||||
}
|
||||
|
||||
function handleSubscribed() {
|
||||
self._subscribed = true;
|
||||
function handleSubscribed(res) {
|
||||
if (self._remote.trace) {
|
||||
log.info('subscribed to transactions');
|
||||
}
|
||||
|
||||
self._subscribed = true;
|
||||
|
||||
callback(null, res);
|
||||
};
|
||||
|
||||
function handleError(err) {
|
||||
if (self._remote.trace) {
|
||||
log.info('failed to subscribe to transactions', self._key, err);
|
||||
}
|
||||
|
||||
callback(err);
|
||||
};
|
||||
|
||||
var request = this._remote.requestSubscribe();
|
||||
|
||||
Reference in New Issue
Block a user