@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.
- package/build/cjs/src/configs/api.js +1 -1
- package/build/cjs/src/utils/__tests__/numbers.spec.js +51 -0
- package/build/cjs/src/utils/gmxAccountApi/api.js +4 -7
- package/build/cjs/src/utils/http/__tests__/chainPins.spec.js +76 -0
- package/build/cjs/src/utils/http/chainPins.js +81 -0
- package/build/cjs/src/utils/http/http.js +3 -0
- package/build/cjs/src/utils/http/httpFallback.js +9 -1
- package/build/cjs/src/utils/numbers/utils.js +4 -3
- package/build/cjs/src/utils/orderTransactions/api.js +11 -6
- package/build/esm/src/configs/api.js +1 -1
- package/build/esm/src/utils/__tests__/numbers.spec.js +52 -1
- package/build/esm/src/utils/gmxAccountApi/api.js +4 -7
- package/build/esm/src/utils/http/__tests__/chainPins.spec.js +74 -0
- package/build/esm/src/utils/http/chainPins.js +76 -0
- package/build/esm/src/utils/http/http.js +3 -0
- package/build/esm/src/utils/http/httpFallback.js +9 -1
- package/build/esm/src/utils/numbers/utils.js +4 -3
- package/build/esm/src/utils/orderTransactions/api.js +11 -6
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/src/utils/http/__tests__/chainPins.spec.d.ts +1 -0
- package/build/types/src/utils/http/chainPins.d.ts +9 -0
- package/build/types/src/utils/http/http.d.ts +4 -1
- package/build/types/src/utils/http/httpFallback.d.ts +4 -1
- package/build/types/src/utils/http/types.d.ts +7 -0
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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 >=
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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") {
|