@gmx-io/sdk 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -303,13 +303,14 @@ export function formatNumberHuman(n, showDollar = false, displayDecimals = 1) {
303
303
  const isNegative = n < 0;
304
304
  const absN = Math.abs(n);
305
305
  const sign = showDollar ? "$\u200a" : "";
306
- if (absN >= 1000000000) {
306
+ // Promote the suffix when the displayed value rounds to 1000 in the smaller unit.
307
+ if (Number((absN / 1000000).toFixed(displayDecimals)) >= 1000) {
307
308
  return `${isNegative ? "-" : ""}${sign}${(absN / 1000000000).toFixed(displayDecimals)}b`;
308
309
  }
309
- if (absN >= 1000000) {
310
+ if (Number((absN / 1000).toFixed(displayDecimals)) >= 1000) {
310
311
  return `${isNegative ? "-" : ""}${sign}${(absN / 1000000).toFixed(displayDecimals)}m`;
311
312
  }
312
- if (absN >= 1000) {
313
+ if (Number(absN.toFixed(displayDecimals)) >= 1000) {
313
314
  return `${isNegative ? "-" : ""}${sign}${(absN / 1000).toFixed(displayDecimals)}k`;
314
315
  }
315
316
  return `${isNegative ? "-" : ""}${sign}${absN.toFixed(displayDecimals)}`;
@@ -1,3 +1,4 @@
1
+ import { postJsonPinned, postJsonPinning } from "../http/chainPins";
1
2
  import { HttpError } from "../http/http";
2
3
  import { parseTradingCapacity } from "../markets/api";
3
4
  import { isUint256, parseUint256DecimalString } from "../numbers";
@@ -172,31 +173,35 @@ function parsePrepareResponse(raw) {
172
173
  validationWarnings: parseValidationWarnings(raw.validationWarnings),
173
174
  };
174
175
  }
176
+ // the express chain stays on the origin that served it: prepare and submit pin that origin by request id, submit and status reuse it
177
+ function chainKeys(prepared) {
178
+ return [prepared.requestId, prepared.idempotencyKey];
179
+ }
175
180
  export async function prepareOrder(ctx, request) {
176
- return ctx.api.postJson("/v1/orders/txns/prepare", request, {
181
+ return postJsonPinning(ctx.api, "/v1/orders/txns/prepare", request, chainKeys, {
177
182
  transform: parsePrepareResponse,
178
183
  });
179
184
  }
180
185
  export async function submitOrder(ctx, request) {
181
- return ctx.api.postJson("/v1/orders/txns/submit", request);
186
+ return postJsonPinned(ctx.api, [request.requestId, request.idempotencyKey], "/v1/orders/txns/submit", request);
182
187
  }
183
188
  export async function prepareEditOrder(ctx, request) {
184
- return ctx.api.postJson("/v1/orders/txns/edit/prepare", request, {
189
+ return postJsonPinning(ctx.api, "/v1/orders/txns/edit/prepare", request, chainKeys, {
185
190
  transform: parsePrepareResponse,
186
191
  });
187
192
  }
188
193
  export async function prepareCancelOrder(ctx, request) {
189
- return ctx.api.postJson("/v1/orders/txns/cancel/prepare", request, {
194
+ return postJsonPinning(ctx.api, "/v1/orders/txns/cancel/prepare", request, chainKeys, {
190
195
  transform: parsePrepareResponse,
191
196
  });
192
197
  }
193
198
  export async function prepareCollateral(ctx, request) {
194
- return ctx.api.postJson("/v1/orders/txns/collateral/prepare", request, {
199
+ return postJsonPinning(ctx.api, "/v1/orders/txns/collateral/prepare", request, chainKeys, {
195
200
  transform: parsePrepareResponse,
196
201
  });
197
202
  }
198
203
  export async function fetchOrderStatus(ctx, request) {
199
- return ctx.api.postJson("/v1/orders/txns/status", request);
204
+ return postJsonPinned(ctx.api, [request.requestId, request.idempotencyKey], "/v1/orders/txns/status", request);
200
205
  }
201
206
  export async function signPreparedOrder(prepared, signer, chainId, accountAddress) {
202
207
  if (prepared.payloadType !== "typed-data") {