You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

orders.js 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  5. }) : (function(o, m, k, k2) {
  6. if (k2 === undefined) k2 = k;
  7. o[k2] = m[k];
  8. }));
  9. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  10. Object.defineProperty(o, "default", { enumerable: true, value: v });
  11. }) : function(o, v) {
  12. o["default"] = v;
  13. });
  14. var __importStar = (this && this.__importStar) || function (mod) {
  15. if (mod && mod.__esModule) return mod;
  16. var result = {};
  17. if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  18. __setModuleDefault(result, mod);
  19. return result;
  20. };
  21. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  22. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  23. return new (P || (P = Promise))(function (resolve, reject) {
  24. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  25. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  26. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  27. step((generator = generator.apply(thisArg, _arguments || [])).next());
  28. });
  29. };
  30. Object.defineProperty(exports, "__esModule", { value: true });
  31. const _ = __importStar(require("lodash"));
  32. const common_1 = require("../common");
  33. const account_order_1 = require("./parse/account-order");
  34. function formatResponse(address, responses) {
  35. let orders = [];
  36. for (const response of responses) {
  37. const offers = response.offers.map((offer) => {
  38. return account_order_1.parseAccountOrder(address, offer);
  39. });
  40. orders = orders.concat(offers);
  41. }
  42. return _.sortBy(orders, (order) => order.properties.sequence);
  43. }
  44. function getOrders(address, options = {}) {
  45. return __awaiter(this, void 0, void 0, function* () {
  46. common_1.validate.getOrders({ address, options });
  47. const responses = yield this._requestAll('account_offers', {
  48. account: address,
  49. ledger_index: options.ledgerVersion || (yield this.getLedgerVersion()),
  50. limit: options.limit
  51. });
  52. return formatResponse(address, responses);
  53. });
  54. }
  55. exports.default = getOrders;
  56. //# sourceMappingURL=orders.js.map