refactor getLedgerVersionHelper

This commit is contained in:
Ivan Tivonenko
2015-09-20 23:59:36 +03:00
parent 51e8f9a87a
commit d573c5746b
12 changed files with 48 additions and 61 deletions

View File

@@ -1,6 +1,7 @@
/* @flow */
'use strict';
const _ = require('lodash');
const async = require('async');
const utils = require('./utils');
const validate = utils.common.validate;
const composeAsync = utils.common.composeAsync;
@@ -26,19 +27,6 @@ function getOrdersAsync(account, options, callback) {
validate.address(account);
validate.getOrdersOptions(options);
if (!options.ledgerVersion) {
const self = this;
this.remote.getLedgerSequence((err, seq) => {
if (err) {
convertErrors(callback)(err);
return;
}
const newOptions = _.extend(options, {ledgerVersion: seq});
getOrdersAsync.call(self, account, newOptions, callback);
});
return;
}
const getter = _.partial(requestAccountOffers, this.remote, account,
options.ledgerVersion);
utils.getRecursive(getter, options.limit,
@@ -47,7 +35,9 @@ function getOrdersAsync(account, options, callback) {
}
function getOrders(account: string, options = {}) {
return utils.promisify(getOrdersAsync).call(this, account, options);
return utils.promisify(async.seq(
utils.getLedgerOptionsWithLedgerVersion,
getOrdersAsync)).call(this, account, options);
}
module.exports = getOrders;