@orderly.network/hooks 1.0.13 → 1.0.15
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/dist/index.d.mts +38 -27
- package/dist/index.d.ts +38 -27
- package/dist/index.js +176 -249
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +178 -250
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -7
package/dist/index.mjs
CHANGED
|
@@ -7,12 +7,14 @@ import useConstant4 from 'use-constant';
|
|
|
7
7
|
export { default as useConstant } from 'use-constant';
|
|
8
8
|
import { SimpleDI, Account, EventEmitter, DefaultConfigStore, LocalStorageStore, EtherAdapter, utils } from '@orderly.network/core';
|
|
9
9
|
import { AccountStatusEnum, OrderStatus, OrderSide, chainsInfoMap, ARBITRUM_TESTNET_CHAINID, ARBITRUM_MAINNET_CHAINID, WS_WalletStatusEnum, OrderType } from '@orderly.network/types';
|
|
10
|
-
import useSWRInfinite from 'swr/infinite';
|
|
10
|
+
import useSWRInfinite, { unstable_serialize } from 'swr/infinite';
|
|
11
|
+
import { useDebouncedCallback } from 'use-debounce';
|
|
12
|
+
export * from 'use-debounce';
|
|
13
|
+
import { jsx } from 'react/jsx-runtime';
|
|
11
14
|
import { Decimal, zero, getPrecisionByNumber, timeConvertString } from '@orderly.network/utils';
|
|
12
15
|
import useSWRSubscription from 'swr/subscription';
|
|
13
16
|
import { pathOr, propOr, compose, head, prop, mergeDeepRight, pick, min } from 'ramda';
|
|
14
17
|
import { positions, account, order } from '@orderly.network/perp';
|
|
15
|
-
export * from 'use-debounce';
|
|
16
18
|
import { createClient } from '@layerzerolabs/scan-client';
|
|
17
19
|
|
|
18
20
|
// src/useQuery.ts
|
|
@@ -174,7 +176,6 @@ var signatureMiddleware = (useSWRNext) => {
|
|
|
174
176
|
url
|
|
175
177
|
};
|
|
176
178
|
const signature = await signer.sign(payload);
|
|
177
|
-
console.log("signature:", fullUrl);
|
|
178
179
|
return fetcher3(fullUrl, {
|
|
179
180
|
headers: {
|
|
180
181
|
...signature,
|
|
@@ -259,8 +260,16 @@ var usePrivateInfiniteQuery = (getKey, options) => {
|
|
|
259
260
|
const account5 = useAccount();
|
|
260
261
|
const middleware = Array.isArray(restOptions?.use) ? restOptions?.use ?? [] : [];
|
|
261
262
|
const result = useSWRInfinite(
|
|
262
|
-
(pageIndex, previousPageData) =>
|
|
263
|
-
|
|
263
|
+
(pageIndex, previousPageData) => {
|
|
264
|
+
const queryKey = getKey(pageIndex, previousPageData);
|
|
265
|
+
if (account5.state.status < AccountStatusEnum.EnableTrading || !queryKey) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
return [queryKey, account5.state.accountId];
|
|
269
|
+
},
|
|
270
|
+
(url, init) => {
|
|
271
|
+
return get(url, init, formatter);
|
|
272
|
+
},
|
|
264
273
|
{
|
|
265
274
|
...restOptions,
|
|
266
275
|
use: [signatureMiddleware, ...middleware]
|
|
@@ -277,9 +286,12 @@ var useBoolean = (initialValue = false) => {
|
|
|
277
286
|
};
|
|
278
287
|
var usePreLoadData = () => {
|
|
279
288
|
useContext(OrderlyContext);
|
|
280
|
-
const { error: tokenError, data: tokenData } = useQuery(
|
|
281
|
-
|
|
282
|
-
|
|
289
|
+
const { error: tokenError, data: tokenData } = useQuery(
|
|
290
|
+
"https://api-evm.orderly.org/v1/public/token",
|
|
291
|
+
{
|
|
292
|
+
revalidateOnFocus: false
|
|
293
|
+
}
|
|
294
|
+
);
|
|
283
295
|
const isDone = useMemo(() => {
|
|
284
296
|
return !!tokenData;
|
|
285
297
|
}, [tokenData]);
|
|
@@ -420,15 +432,123 @@ var useWS = () => {
|
|
|
420
432
|
websocketClient.openPrivate(nextState.accountId);
|
|
421
433
|
}
|
|
422
434
|
});
|
|
435
|
+
if (typeof window !== "undefined") {
|
|
436
|
+
window["__Orderly_WS"] = websocketClient;
|
|
437
|
+
}
|
|
423
438
|
SimpleDI.registerByName(WS_NAME, websocketClient);
|
|
424
439
|
}
|
|
425
440
|
return websocketClient;
|
|
426
441
|
});
|
|
427
442
|
return ws;
|
|
428
443
|
};
|
|
444
|
+
var usePrivateDataObserver = () => {
|
|
445
|
+
const ws = useWS();
|
|
446
|
+
const { mutate: mutate2 } = useSWRConfig();
|
|
447
|
+
const ee = useEventEmitter();
|
|
448
|
+
const { state } = useAccount();
|
|
449
|
+
const updateOrders = useDebouncedCallback(() => {
|
|
450
|
+
mutate2(
|
|
451
|
+
unstable_serialize(() => [
|
|
452
|
+
`/v1/orders?size=100&page=1&status=${OrderStatus.INCOMPLETE}`,
|
|
453
|
+
state.accountId
|
|
454
|
+
])
|
|
455
|
+
);
|
|
456
|
+
mutate2(
|
|
457
|
+
unstable_serialize(() => [
|
|
458
|
+
`/v1/orders?size=100&page=1&status=${OrderStatus.NEW}`,
|
|
459
|
+
state.accountId
|
|
460
|
+
])
|
|
461
|
+
);
|
|
462
|
+
}, 500);
|
|
463
|
+
useEffect(() => {
|
|
464
|
+
if (!state.accountId)
|
|
465
|
+
return;
|
|
466
|
+
const unsubscribe = ws.privateSubscribe("executionreport", {
|
|
467
|
+
onMessage: (data) => {
|
|
468
|
+
updateOrders();
|
|
469
|
+
ee.emit("orders:changed", data);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
return () => unsubscribe?.();
|
|
473
|
+
}, [state.accountId]);
|
|
474
|
+
useEffect(() => {
|
|
475
|
+
if (!state.accountId)
|
|
476
|
+
return;
|
|
477
|
+
const key = ["/v1/positions", state.accountId];
|
|
478
|
+
const unsubscribe = ws.privateSubscribe("position", {
|
|
479
|
+
onMessage: (data) => {
|
|
480
|
+
const { positions: nextPostions } = data;
|
|
481
|
+
mutate2(
|
|
482
|
+
key,
|
|
483
|
+
(prevPositions) => {
|
|
484
|
+
if (!!prevPositions) {
|
|
485
|
+
return {
|
|
486
|
+
...prevPositions,
|
|
487
|
+
rows: prevPositions.rows.map((row) => {
|
|
488
|
+
const item = nextPostions.find(
|
|
489
|
+
(item2) => item2.symbol === row.symbol
|
|
490
|
+
);
|
|
491
|
+
if (item) {
|
|
492
|
+
return {
|
|
493
|
+
symbol: item.symbol,
|
|
494
|
+
position_qty: item.positionQty,
|
|
495
|
+
cost_position: item.costPosition,
|
|
496
|
+
last_sum_unitary_funding: item.lastSumUnitaryFunding,
|
|
497
|
+
pending_long_qty: item.pendingLongQty,
|
|
498
|
+
pending_short_qty: item.pendingShortQty,
|
|
499
|
+
settle_price: item.settlePrice,
|
|
500
|
+
average_open_price: item.averageOpenPrice,
|
|
501
|
+
unsettled_pnl: item.unsettledPnl,
|
|
502
|
+
mark_price: item.markPrice,
|
|
503
|
+
est_liq_price: item.estLiqPrice,
|
|
504
|
+
timestamp: Date.now(),
|
|
505
|
+
imr: item.imr,
|
|
506
|
+
mmr: item.mmr,
|
|
507
|
+
IMR_withdraw_orders: item.imrwithOrders,
|
|
508
|
+
MMR_with_orders: item.mmrwithOrders,
|
|
509
|
+
pnl_24_h: item.pnl24H,
|
|
510
|
+
fee_24_h: item.fee24H
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
return row;
|
|
514
|
+
})
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
revalidate: false
|
|
520
|
+
}
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
return () => {
|
|
525
|
+
unsubscribe?.();
|
|
526
|
+
};
|
|
527
|
+
}, [state.accountId]);
|
|
528
|
+
};
|
|
529
|
+
var DataCenterContext = createContext(
|
|
530
|
+
{}
|
|
531
|
+
);
|
|
532
|
+
var DataCenterProvider = ({ children }) => {
|
|
533
|
+
const { error, done } = usePreLoadData();
|
|
534
|
+
usePrivateDataObserver();
|
|
535
|
+
if (error) {
|
|
536
|
+
return /* @__PURE__ */ jsx("div", { children: "Data load failed" });
|
|
537
|
+
}
|
|
538
|
+
if (!done)
|
|
539
|
+
return null;
|
|
540
|
+
return /* @__PURE__ */ jsx(DataCenterContext.Provider, { value: {}, children });
|
|
541
|
+
};
|
|
429
542
|
var OrderlyConfigProvider = (props) => {
|
|
430
543
|
const [account5, setAccount] = React.useState(null);
|
|
431
|
-
const {
|
|
544
|
+
const {
|
|
545
|
+
configStore,
|
|
546
|
+
keyStore,
|
|
547
|
+
getWalletAdapter,
|
|
548
|
+
brokerId,
|
|
549
|
+
networkId,
|
|
550
|
+
enableSwapDeposit
|
|
551
|
+
} = props;
|
|
432
552
|
if (!brokerId && typeof configStore === "undefined") {
|
|
433
553
|
console.error("[OrderlyConfigProvider]: brokerId is required");
|
|
434
554
|
}
|
|
@@ -456,7 +576,7 @@ var OrderlyConfigProvider = (props) => {
|
|
|
456
576
|
if (!account5) {
|
|
457
577
|
return null;
|
|
458
578
|
}
|
|
459
|
-
return /* @__PURE__ */
|
|
579
|
+
return /* @__PURE__ */ jsx(
|
|
460
580
|
OrderlyProvider,
|
|
461
581
|
{
|
|
462
582
|
value: {
|
|
@@ -466,9 +586,9 @@ var OrderlyConfigProvider = (props) => {
|
|
|
466
586
|
networkId,
|
|
467
587
|
enableSwapDeposit
|
|
468
588
|
// apiBaseUrl,
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
589
|
+
},
|
|
590
|
+
children: /* @__PURE__ */ jsx(DataCenterProvider, { children: props.children })
|
|
591
|
+
}
|
|
472
592
|
);
|
|
473
593
|
};
|
|
474
594
|
var WalletConnectorContext = createContext({});
|
|
@@ -1090,7 +1210,7 @@ var usePositionStream = (symbol, options) => {
|
|
|
1090
1210
|
} = usePrivateQuery(`/v1/positions`, {
|
|
1091
1211
|
// revalidateOnFocus: false,
|
|
1092
1212
|
// revalidateOnReconnect: false,
|
|
1093
|
-
// dedupingInterval:
|
|
1213
|
+
// dedupingInterval: 200,
|
|
1094
1214
|
// keepPreviousData: false,
|
|
1095
1215
|
// revalidateIfStale: true,
|
|
1096
1216
|
...options,
|
|
@@ -1098,10 +1218,6 @@ var usePositionStream = (symbol, options) => {
|
|
|
1098
1218
|
onError: (err) => {
|
|
1099
1219
|
}
|
|
1100
1220
|
});
|
|
1101
|
-
usePositionUpdateStream((positions2) => {
|
|
1102
|
-
console.log("position message", positions2);
|
|
1103
|
-
updatePositions();
|
|
1104
|
-
});
|
|
1105
1221
|
const { data: markPrices } = useMarkPricesStream();
|
|
1106
1222
|
const formatedPositions = useMemo(() => {
|
|
1107
1223
|
if (!data?.rows || !symbolInfo || !accountInfo)
|
|
@@ -1250,41 +1366,6 @@ var pathOr_unsettledPnLPathOr = pathOr(0, [
|
|
|
1250
1366
|
"aggregated",
|
|
1251
1367
|
"unsettledPnL"
|
|
1252
1368
|
]);
|
|
1253
|
-
var usePositionUpdateStream = (callback) => {
|
|
1254
|
-
const ws = useWS();
|
|
1255
|
-
const positionList = useRef({});
|
|
1256
|
-
return useSWRSubscription("positionUpdate", (key, { next }) => {
|
|
1257
|
-
const unsubscribe = ws.privateSubscribe(
|
|
1258
|
-
// { event: "subscribe", topic: "markprices" },
|
|
1259
|
-
"position",
|
|
1260
|
-
{
|
|
1261
|
-
onMessage: (message) => {
|
|
1262
|
-
const { positions: positions2 } = message;
|
|
1263
|
-
let update = false;
|
|
1264
|
-
for (const p in positions2) {
|
|
1265
|
-
const { symbol, positionQty } = positions2[p];
|
|
1266
|
-
if (positionList.current[symbol] !== positionQty) {
|
|
1267
|
-
update = true;
|
|
1268
|
-
positionList.current[symbol] = positionQty;
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
if (update) {
|
|
1272
|
-
callback(positions2.current);
|
|
1273
|
-
}
|
|
1274
|
-
next(null, positionList);
|
|
1275
|
-
},
|
|
1276
|
-
// onUnsubscribe: () => {
|
|
1277
|
-
// return "markprices";
|
|
1278
|
-
// },
|
|
1279
|
-
onError: (error) => {
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
);
|
|
1283
|
-
return () => {
|
|
1284
|
-
unsubscribe?.();
|
|
1285
|
-
};
|
|
1286
|
-
});
|
|
1287
|
-
};
|
|
1288
1369
|
var useHoldingStream = () => {
|
|
1289
1370
|
const ws = useWS();
|
|
1290
1371
|
const { data, isLoading, mutate: mutate2 } = usePrivateQuery(
|
|
@@ -1336,10 +1417,15 @@ var useHoldingStream = () => {
|
|
|
1336
1417
|
};
|
|
1337
1418
|
var useOrderStream = (params) => {
|
|
1338
1419
|
const { status, symbol, side, size = 100 } = params;
|
|
1339
|
-
const ws = useWS();
|
|
1340
1420
|
const { data: markPrices = {} } = useMarkPricesStream();
|
|
1341
|
-
const [doCancelOrder] = useMutation(
|
|
1342
|
-
|
|
1421
|
+
const [doCancelOrder, { error: cancelOrderError }] = useMutation(
|
|
1422
|
+
"/v1/order",
|
|
1423
|
+
"DELETE"
|
|
1424
|
+
);
|
|
1425
|
+
const [doUpdateOrder, { error: updateOrderError }] = useMutation(
|
|
1426
|
+
"/v1/order",
|
|
1427
|
+
"PUT"
|
|
1428
|
+
);
|
|
1343
1429
|
const ordersResponse = usePrivateInfiniteQuery(
|
|
1344
1430
|
(pageIndex, previousPageData) => {
|
|
1345
1431
|
if (previousPageData && !previousPageData.rows?.length)
|
|
@@ -1362,9 +1448,9 @@ var useOrderStream = (params) => {
|
|
|
1362
1448
|
{
|
|
1363
1449
|
initialSize: 1,
|
|
1364
1450
|
// revalidateFirstPage: false,
|
|
1365
|
-
onError: (err) => {
|
|
1366
|
-
|
|
1367
|
-
},
|
|
1451
|
+
// onError: (err) => {
|
|
1452
|
+
// console.error("fetch failed::::", err);
|
|
1453
|
+
// },
|
|
1368
1454
|
formatter: (data) => data
|
|
1369
1455
|
}
|
|
1370
1456
|
);
|
|
@@ -1381,68 +1467,7 @@ var useOrderStream = (params) => {
|
|
|
1381
1467
|
}, [ordersResponse.data, markPrices]);
|
|
1382
1468
|
const total = useMemo(() => {
|
|
1383
1469
|
return ordersResponse.data?.[0]?.meta?.total || 0;
|
|
1384
|
-
}, [ordersResponse.data]);
|
|
1385
|
-
useEffect(() => {
|
|
1386
|
-
const unsubscribe = ws.privateSubscribe(
|
|
1387
|
-
{
|
|
1388
|
-
id: "executionreport_orders",
|
|
1389
|
-
event: "subscribe",
|
|
1390
|
-
topic: "executionreport",
|
|
1391
|
-
ts: Date.now()
|
|
1392
|
-
},
|
|
1393
|
-
{
|
|
1394
|
-
onMessage: (data) => {
|
|
1395
|
-
const { status: status2, orderId, timestamp } = data;
|
|
1396
|
-
ordersResponse.mutate((prevData) => {
|
|
1397
|
-
const newOrder = {
|
|
1398
|
-
order_id: data.orderId,
|
|
1399
|
-
symbol: data.symbol,
|
|
1400
|
-
created_time: data.timestamp,
|
|
1401
|
-
quantity: data.quantity,
|
|
1402
|
-
side: data.side,
|
|
1403
|
-
executed: data.totalExecutedQuantity,
|
|
1404
|
-
price: data.price
|
|
1405
|
-
};
|
|
1406
|
-
const dataList = prevData?.map((item) => item.rows)?.flat() || [];
|
|
1407
|
-
if (status2 === OrderStatus.NEW) {
|
|
1408
|
-
if (!prevData) {
|
|
1409
|
-
return {
|
|
1410
|
-
meta: {
|
|
1411
|
-
total: 1,
|
|
1412
|
-
records_per_page: size,
|
|
1413
|
-
current_page: 1
|
|
1414
|
-
},
|
|
1415
|
-
rows: [newOrder]
|
|
1416
|
-
};
|
|
1417
|
-
}
|
|
1418
|
-
const total2 = (prevData?.[0]?.meta?.total || 0) + 1;
|
|
1419
|
-
const isNew = !dataList.find((item) => item.order_id === orderId);
|
|
1420
|
-
if (isNew) {
|
|
1421
|
-
const list = [newOrder, ...dataList];
|
|
1422
|
-
return rePageData(list, total2, size);
|
|
1423
|
-
}
|
|
1424
|
-
return prevData;
|
|
1425
|
-
}
|
|
1426
|
-
if (status2 === OrderStatus.CANCELLED || status2 === OrderStatus.FILLED) {
|
|
1427
|
-
const total2 = (prevData?.[0]?.meta?.total || 0) - 1;
|
|
1428
|
-
const list = dataList.filter(
|
|
1429
|
-
(order2) => order2.order_id !== orderId
|
|
1430
|
-
);
|
|
1431
|
-
return rePageData(list, total2, size);
|
|
1432
|
-
}
|
|
1433
|
-
if (status2 === OrderStatus.PARTIAL_FILLED) {
|
|
1434
|
-
return editPageData(dataList, newOrder);
|
|
1435
|
-
}
|
|
1436
|
-
if (status2 === OrderStatus.REPLACED) {
|
|
1437
|
-
return editPageData(dataList, newOrder);
|
|
1438
|
-
}
|
|
1439
|
-
return prevData;
|
|
1440
|
-
});
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
);
|
|
1444
|
-
return () => unsubscribe();
|
|
1445
|
-
}, []);
|
|
1470
|
+
}, [ordersResponse.data?.[0]?.meta?.total]);
|
|
1446
1471
|
const cancelAllOrders = useCallback(() => {
|
|
1447
1472
|
}, [ordersResponse.data]);
|
|
1448
1473
|
const updateOrder = useCallback((orderId, order2) => {
|
|
@@ -1469,44 +1494,14 @@ var useOrderStream = (params) => {
|
|
|
1469
1494
|
loadMore,
|
|
1470
1495
|
cancelAllOrders,
|
|
1471
1496
|
updateOrder,
|
|
1472
|
-
cancelOrder
|
|
1497
|
+
cancelOrder,
|
|
1498
|
+
errors: {
|
|
1499
|
+
cancelOrder: cancelOrderError,
|
|
1500
|
+
updateOrder: updateOrderError
|
|
1501
|
+
}
|
|
1473
1502
|
}
|
|
1474
1503
|
];
|
|
1475
1504
|
};
|
|
1476
|
-
function rePageData(list, total, pageSize) {
|
|
1477
|
-
const newData = [];
|
|
1478
|
-
let rows = [];
|
|
1479
|
-
let current_page = 0;
|
|
1480
|
-
for (let i = 0; i < list.length; i++) {
|
|
1481
|
-
rows.push(list[i]);
|
|
1482
|
-
if ((i + 1) % pageSize === 0 || i === list.length - 1) {
|
|
1483
|
-
newData.push({
|
|
1484
|
-
meta: {
|
|
1485
|
-
records_per_page: pageSize,
|
|
1486
|
-
total,
|
|
1487
|
-
current_page: current_page + 1
|
|
1488
|
-
},
|
|
1489
|
-
rows: [...rows]
|
|
1490
|
-
});
|
|
1491
|
-
rows = [];
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
return newData;
|
|
1495
|
-
}
|
|
1496
|
-
function editPageData(list, newOrder) {
|
|
1497
|
-
const newData = list.map((item) => {
|
|
1498
|
-
return {
|
|
1499
|
-
...item,
|
|
1500
|
-
rows: item.rows.map((row) => {
|
|
1501
|
-
if (row.order_id === newOrder.order_id) {
|
|
1502
|
-
return { ...row, newOrder };
|
|
1503
|
-
}
|
|
1504
|
-
return row;
|
|
1505
|
-
})
|
|
1506
|
-
};
|
|
1507
|
-
});
|
|
1508
|
-
return newData;
|
|
1509
|
-
}
|
|
1510
1505
|
|
|
1511
1506
|
// src/orderly/useCollateral.ts
|
|
1512
1507
|
var positionsPath = pathOr([], [0, "rows"]);
|
|
@@ -1565,33 +1560,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
1565
1560
|
const symbolInfo = useSymbolsInfo();
|
|
1566
1561
|
const { totalCollateral } = useCollateral();
|
|
1567
1562
|
const { data: markPrices } = useMarkPricesStream();
|
|
1568
|
-
const {
|
|
1569
|
-
data: orders,
|
|
1570
|
-
error,
|
|
1571
|
-
mutate: updateOrder
|
|
1572
|
-
} = usePrivateQuery(`/v1/orders?status=NEW&size=99`, {
|
|
1573
|
-
formatter: (data) => data.rows,
|
|
1574
|
-
onError: (err) => {
|
|
1575
|
-
}
|
|
1576
|
-
});
|
|
1577
|
-
const ws = useWS();
|
|
1578
|
-
useEffect(() => {
|
|
1579
|
-
const unsubscribe = ws.privateSubscribe(
|
|
1580
|
-
{
|
|
1581
|
-
id: "executionreport_orders",
|
|
1582
|
-
event: "subscribe",
|
|
1583
|
-
topic: "executionreport",
|
|
1584
|
-
ts: Date.now()
|
|
1585
|
-
},
|
|
1586
|
-
{
|
|
1587
|
-
onMessage: (data) => {
|
|
1588
|
-
console.log("refresh orders", data);
|
|
1589
|
-
updateOrder();
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
);
|
|
1593
|
-
return () => unsubscribe();
|
|
1594
|
-
}, []);
|
|
1563
|
+
const [orders] = useOrderStream({ status: OrderStatus.NEW });
|
|
1595
1564
|
const maxQty = useMemo(() => {
|
|
1596
1565
|
if (!symbol)
|
|
1597
1566
|
return 0;
|
|
@@ -1965,7 +1934,6 @@ var useLeverage = () => {
|
|
|
1965
1934
|
const { data: config } = useQuery("/v1/public/config");
|
|
1966
1935
|
const updateLeverage = useCallback((data2) => {
|
|
1967
1936
|
return update(data2).then((res) => {
|
|
1968
|
-
console.log(res);
|
|
1969
1937
|
if (res.success) {
|
|
1970
1938
|
return mutate2();
|
|
1971
1939
|
} else {
|
|
@@ -3147,7 +3115,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3147
3115
|
}
|
|
3148
3116
|
);
|
|
3149
3117
|
const { data: orderlyChains, error: tokenError } = useQuery(
|
|
3150
|
-
// wooSwapEnabled ? "/v1/public/token" :
|
|
3118
|
+
// wooSwapEnabled ? "/v1/public/token" :
|
|
3151
3119
|
"https://api-evm.orderly.org/v1/public/token",
|
|
3152
3120
|
{
|
|
3153
3121
|
revalidateIfStale: false,
|
|
@@ -3158,11 +3126,9 @@ var useChains = (networkId, options = {}) => {
|
|
|
3158
3126
|
}
|
|
3159
3127
|
);
|
|
3160
3128
|
const chains = useMemo(() => {
|
|
3161
|
-
if (!orderlyChains)
|
|
3162
|
-
return void 0;
|
|
3163
3129
|
let orderlyChainsArr = [];
|
|
3164
3130
|
const orderlyChainIds = /* @__PURE__ */ new Set();
|
|
3165
|
-
orderlyChains
|
|
3131
|
+
orderlyChains?.forEach((item) => {
|
|
3166
3132
|
item.chain_details.forEach((chain) => {
|
|
3167
3133
|
const chainId = Number(chain.chain_id);
|
|
3168
3134
|
orderlyChainIds.add(chainId);
|
|
@@ -3188,7 +3154,9 @@ var useChains = (networkId, options = {}) => {
|
|
|
3188
3154
|
return;
|
|
3189
3155
|
}
|
|
3190
3156
|
if (_chain.chain_id === 421613) {
|
|
3191
|
-
const index = testnetArr.findIndex(
|
|
3157
|
+
const index = testnetArr.findIndex(
|
|
3158
|
+
(item2) => item2.network_infos.chain_id === 421613
|
|
3159
|
+
);
|
|
3192
3160
|
if (index > -1) {
|
|
3193
3161
|
testnetArr[index] = _chain;
|
|
3194
3162
|
}
|
|
@@ -3255,16 +3223,19 @@ var useChains = (networkId, options = {}) => {
|
|
|
3255
3223
|
}
|
|
3256
3224
|
});
|
|
3257
3225
|
} else {
|
|
3258
|
-
if (!chainInfos)
|
|
3259
|
-
return void 0;
|
|
3260
3226
|
orderlyChainsArr.forEach((chain) => {
|
|
3261
3227
|
let _chain = chain;
|
|
3262
|
-
const networkInfo = chainInfos
|
|
3263
|
-
console.log(item.chain_id, chain.network_infos.chain_id);
|
|
3228
|
+
const networkInfo = chainInfos?.find((item) => {
|
|
3264
3229
|
return item.chain_id == chain.network_infos.chain_id;
|
|
3265
3230
|
});
|
|
3266
3231
|
if (networkInfo) {
|
|
3267
|
-
const {
|
|
3232
|
+
const {
|
|
3233
|
+
name,
|
|
3234
|
+
public_rpc_url,
|
|
3235
|
+
chain_id,
|
|
3236
|
+
currency_symbol,
|
|
3237
|
+
explorer_base_url
|
|
3238
|
+
} = networkInfo;
|
|
3268
3239
|
_chain.network_infos = {
|
|
3269
3240
|
..._chain.network_infos,
|
|
3270
3241
|
name,
|
|
@@ -3281,7 +3252,9 @@ var useChains = (networkId, options = {}) => {
|
|
|
3281
3252
|
}
|
|
3282
3253
|
map.current.set(_chain.network_infos.chain_id, _chain);
|
|
3283
3254
|
if (_chain.network_infos.chain_id === 421613) {
|
|
3284
|
-
const index = testnetArr.findIndex(
|
|
3255
|
+
const index = testnetArr.findIndex(
|
|
3256
|
+
(item) => item.network_infos.chain_id === 421613
|
|
3257
|
+
);
|
|
3285
3258
|
if (index > -1) {
|
|
3286
3259
|
testnetArr[index] = _chain;
|
|
3287
3260
|
}
|
|
@@ -3313,7 +3286,15 @@ var useChains = (networkId, options = {}) => {
|
|
|
3313
3286
|
testnet: testnetArr,
|
|
3314
3287
|
mainnet: mainnetArr
|
|
3315
3288
|
};
|
|
3316
|
-
}, [
|
|
3289
|
+
}, [
|
|
3290
|
+
data,
|
|
3291
|
+
networkId,
|
|
3292
|
+
field,
|
|
3293
|
+
options,
|
|
3294
|
+
orderlyChains,
|
|
3295
|
+
wooSwapEnabled,
|
|
3296
|
+
chainInfos
|
|
3297
|
+
]);
|
|
3317
3298
|
const findByChainId = useCallback(
|
|
3318
3299
|
(chainId, field2) => {
|
|
3319
3300
|
const chain = map.current.get(chainId);
|
|
@@ -3409,7 +3390,7 @@ var useDeposit = (options) => {
|
|
|
3409
3390
|
network: chain.network_infos.shortName
|
|
3410
3391
|
// chainId: 42161,
|
|
3411
3392
|
};
|
|
3412
|
-
}, [networkId]);
|
|
3393
|
+
}, [networkId, findByChainId]);
|
|
3413
3394
|
const isNativeToken = useMemo(
|
|
3414
3395
|
() => isNativeTokenChecker(options?.address || ""),
|
|
3415
3396
|
[options?.address]
|
|
@@ -3612,59 +3593,6 @@ var useSettleSubscription = (options) => {
|
|
|
3612
3593
|
return () => unsubscribe();
|
|
3613
3594
|
});
|
|
3614
3595
|
};
|
|
3615
|
-
var usePrivateDataObserver = () => {
|
|
3616
|
-
const ws = useWS();
|
|
3617
|
-
const { mutate: mutate2 } = useSWRConfig();
|
|
3618
|
-
const { state } = useAccount();
|
|
3619
|
-
useEffect(() => {
|
|
3620
|
-
if (!state.accountId)
|
|
3621
|
-
return;
|
|
3622
|
-
const key = ["/v1/positions", state.accountId];
|
|
3623
|
-
const unsubscribe = ws.privateSubscribe("position", {
|
|
3624
|
-
onMessage: (data) => {
|
|
3625
|
-
const { positions: nextPostions } = data;
|
|
3626
|
-
mutate2(key, (prevPositions) => {
|
|
3627
|
-
if (!!prevPositions) {
|
|
3628
|
-
return {
|
|
3629
|
-
...prevPositions,
|
|
3630
|
-
rows: prevPositions.rows.map((row) => {
|
|
3631
|
-
const item = nextPostions.find(
|
|
3632
|
-
(item2) => item2.symbol === row.symbol
|
|
3633
|
-
);
|
|
3634
|
-
if (item) {
|
|
3635
|
-
return {
|
|
3636
|
-
symbol: item.symbol,
|
|
3637
|
-
position_qty: item.positionQty,
|
|
3638
|
-
cost_position: item.costPosition,
|
|
3639
|
-
last_sum_unitary_funding: item.lastSumUnitaryFunding,
|
|
3640
|
-
pending_long_qty: item.pendingLongQty,
|
|
3641
|
-
pending_short_qty: item.pendingShortQty,
|
|
3642
|
-
settle_price: item.settlePrice,
|
|
3643
|
-
average_open_price: item.averageOpenPrice,
|
|
3644
|
-
unsettled_pnl: item.unsettledPnl,
|
|
3645
|
-
mark_price: item.markPrice,
|
|
3646
|
-
est_liq_price: item.estLiqPrice,
|
|
3647
|
-
timestamp: Date.now(),
|
|
3648
|
-
imr: item.imr,
|
|
3649
|
-
mmr: item.mmr,
|
|
3650
|
-
IMR_withdraw_orders: item.imrwithOrders,
|
|
3651
|
-
MMR_with_orders: item.mmrwithOrders,
|
|
3652
|
-
pnl_24_h: item.pnl24H,
|
|
3653
|
-
fee_24_h: item.fee24H
|
|
3654
|
-
};
|
|
3655
|
-
}
|
|
3656
|
-
return row;
|
|
3657
|
-
})
|
|
3658
|
-
};
|
|
3659
|
-
}
|
|
3660
|
-
});
|
|
3661
|
-
}
|
|
3662
|
-
});
|
|
3663
|
-
return () => {
|
|
3664
|
-
unsubscribe?.();
|
|
3665
|
-
};
|
|
3666
|
-
}, [state.accountId]);
|
|
3667
|
-
};
|
|
3668
3596
|
var useWooSwapQuery = () => {
|
|
3669
3597
|
const { configStore } = useContext(OrderlyContext);
|
|
3670
3598
|
const account5 = useAccountInstance();
|