@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.js
CHANGED
|
@@ -8,11 +8,12 @@ var useConstant4 = require('use-constant');
|
|
|
8
8
|
var core = require('@orderly.network/core');
|
|
9
9
|
var types = require('@orderly.network/types');
|
|
10
10
|
var useSWRInfinite = require('swr/infinite');
|
|
11
|
+
var useDebounce = require('use-debounce');
|
|
12
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
11
13
|
var utils = require('@orderly.network/utils');
|
|
12
14
|
var useSWRSubscription = require('swr/subscription');
|
|
13
15
|
var ramda = require('ramda');
|
|
14
16
|
var perp = require('@orderly.network/perp');
|
|
15
|
-
var useDebounce = require('use-debounce');
|
|
16
17
|
var scanClient = require('@layerzerolabs/scan-client');
|
|
17
18
|
|
|
18
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -183,7 +184,6 @@ var signatureMiddleware = (useSWRNext) => {
|
|
|
183
184
|
url
|
|
184
185
|
};
|
|
185
186
|
const signature = await signer.sign(payload);
|
|
186
|
-
console.log("signature:", fullUrl);
|
|
187
187
|
return fetcher3(fullUrl, {
|
|
188
188
|
headers: {
|
|
189
189
|
...signature,
|
|
@@ -268,8 +268,16 @@ var usePrivateInfiniteQuery = (getKey, options) => {
|
|
|
268
268
|
const account5 = useAccount();
|
|
269
269
|
const middleware = Array.isArray(restOptions?.use) ? restOptions?.use ?? [] : [];
|
|
270
270
|
const result = useSWRInfinite__default.default(
|
|
271
|
-
(pageIndex, previousPageData) =>
|
|
272
|
-
|
|
271
|
+
(pageIndex, previousPageData) => {
|
|
272
|
+
const queryKey = getKey(pageIndex, previousPageData);
|
|
273
|
+
if (account5.state.status < types.AccountStatusEnum.EnableTrading || !queryKey) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
return [queryKey, account5.state.accountId];
|
|
277
|
+
},
|
|
278
|
+
(url, init) => {
|
|
279
|
+
return net.get(url, init, formatter);
|
|
280
|
+
},
|
|
273
281
|
{
|
|
274
282
|
...restOptions,
|
|
275
283
|
use: [signatureMiddleware, ...middleware]
|
|
@@ -286,9 +294,12 @@ var useBoolean = (initialValue = false) => {
|
|
|
286
294
|
};
|
|
287
295
|
var usePreLoadData = () => {
|
|
288
296
|
React.useContext(OrderlyContext);
|
|
289
|
-
const { error: tokenError, data: tokenData } = useQuery(
|
|
290
|
-
|
|
291
|
-
|
|
297
|
+
const { error: tokenError, data: tokenData } = useQuery(
|
|
298
|
+
"https://api-evm.orderly.org/v1/public/token",
|
|
299
|
+
{
|
|
300
|
+
revalidateOnFocus: false
|
|
301
|
+
}
|
|
302
|
+
);
|
|
292
303
|
const isDone = React.useMemo(() => {
|
|
293
304
|
return !!tokenData;
|
|
294
305
|
}, [tokenData]);
|
|
@@ -429,15 +440,123 @@ var useWS = () => {
|
|
|
429
440
|
websocketClient.openPrivate(nextState.accountId);
|
|
430
441
|
}
|
|
431
442
|
});
|
|
443
|
+
if (typeof window !== "undefined") {
|
|
444
|
+
window["__Orderly_WS"] = websocketClient;
|
|
445
|
+
}
|
|
432
446
|
core.SimpleDI.registerByName(WS_NAME, websocketClient);
|
|
433
447
|
}
|
|
434
448
|
return websocketClient;
|
|
435
449
|
});
|
|
436
450
|
return ws;
|
|
437
451
|
};
|
|
452
|
+
var usePrivateDataObserver = () => {
|
|
453
|
+
const ws = useWS();
|
|
454
|
+
const { mutate: mutate2 } = useSWR.useSWRConfig();
|
|
455
|
+
const ee = useEventEmitter();
|
|
456
|
+
const { state } = useAccount();
|
|
457
|
+
const updateOrders = useDebounce.useDebouncedCallback(() => {
|
|
458
|
+
mutate2(
|
|
459
|
+
useSWRInfinite.unstable_serialize(() => [
|
|
460
|
+
`/v1/orders?size=100&page=1&status=${types.OrderStatus.INCOMPLETE}`,
|
|
461
|
+
state.accountId
|
|
462
|
+
])
|
|
463
|
+
);
|
|
464
|
+
mutate2(
|
|
465
|
+
useSWRInfinite.unstable_serialize(() => [
|
|
466
|
+
`/v1/orders?size=100&page=1&status=${types.OrderStatus.NEW}`,
|
|
467
|
+
state.accountId
|
|
468
|
+
])
|
|
469
|
+
);
|
|
470
|
+
}, 500);
|
|
471
|
+
React.useEffect(() => {
|
|
472
|
+
if (!state.accountId)
|
|
473
|
+
return;
|
|
474
|
+
const unsubscribe = ws.privateSubscribe("executionreport", {
|
|
475
|
+
onMessage: (data) => {
|
|
476
|
+
updateOrders();
|
|
477
|
+
ee.emit("orders:changed", data);
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
return () => unsubscribe?.();
|
|
481
|
+
}, [state.accountId]);
|
|
482
|
+
React.useEffect(() => {
|
|
483
|
+
if (!state.accountId)
|
|
484
|
+
return;
|
|
485
|
+
const key = ["/v1/positions", state.accountId];
|
|
486
|
+
const unsubscribe = ws.privateSubscribe("position", {
|
|
487
|
+
onMessage: (data) => {
|
|
488
|
+
const { positions: nextPostions } = data;
|
|
489
|
+
mutate2(
|
|
490
|
+
key,
|
|
491
|
+
(prevPositions) => {
|
|
492
|
+
if (!!prevPositions) {
|
|
493
|
+
return {
|
|
494
|
+
...prevPositions,
|
|
495
|
+
rows: prevPositions.rows.map((row) => {
|
|
496
|
+
const item = nextPostions.find(
|
|
497
|
+
(item2) => item2.symbol === row.symbol
|
|
498
|
+
);
|
|
499
|
+
if (item) {
|
|
500
|
+
return {
|
|
501
|
+
symbol: item.symbol,
|
|
502
|
+
position_qty: item.positionQty,
|
|
503
|
+
cost_position: item.costPosition,
|
|
504
|
+
last_sum_unitary_funding: item.lastSumUnitaryFunding,
|
|
505
|
+
pending_long_qty: item.pendingLongQty,
|
|
506
|
+
pending_short_qty: item.pendingShortQty,
|
|
507
|
+
settle_price: item.settlePrice,
|
|
508
|
+
average_open_price: item.averageOpenPrice,
|
|
509
|
+
unsettled_pnl: item.unsettledPnl,
|
|
510
|
+
mark_price: item.markPrice,
|
|
511
|
+
est_liq_price: item.estLiqPrice,
|
|
512
|
+
timestamp: Date.now(),
|
|
513
|
+
imr: item.imr,
|
|
514
|
+
mmr: item.mmr,
|
|
515
|
+
IMR_withdraw_orders: item.imrwithOrders,
|
|
516
|
+
MMR_with_orders: item.mmrwithOrders,
|
|
517
|
+
pnl_24_h: item.pnl24H,
|
|
518
|
+
fee_24_h: item.fee24H
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
return row;
|
|
522
|
+
})
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
revalidate: false
|
|
528
|
+
}
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
return () => {
|
|
533
|
+
unsubscribe?.();
|
|
534
|
+
};
|
|
535
|
+
}, [state.accountId]);
|
|
536
|
+
};
|
|
537
|
+
var DataCenterContext = React.createContext(
|
|
538
|
+
{}
|
|
539
|
+
);
|
|
540
|
+
var DataCenterProvider = ({ children }) => {
|
|
541
|
+
const { error, done } = usePreLoadData();
|
|
542
|
+
usePrivateDataObserver();
|
|
543
|
+
if (error) {
|
|
544
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { children: "Data load failed" });
|
|
545
|
+
}
|
|
546
|
+
if (!done)
|
|
547
|
+
return null;
|
|
548
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DataCenterContext.Provider, { value: {}, children });
|
|
549
|
+
};
|
|
438
550
|
var OrderlyConfigProvider = (props) => {
|
|
439
551
|
const [account5, setAccount] = React__default.default.useState(null);
|
|
440
|
-
const {
|
|
552
|
+
const {
|
|
553
|
+
configStore,
|
|
554
|
+
keyStore,
|
|
555
|
+
getWalletAdapter,
|
|
556
|
+
brokerId,
|
|
557
|
+
networkId,
|
|
558
|
+
enableSwapDeposit
|
|
559
|
+
} = props;
|
|
441
560
|
if (!brokerId && typeof configStore === "undefined") {
|
|
442
561
|
console.error("[OrderlyConfigProvider]: brokerId is required");
|
|
443
562
|
}
|
|
@@ -465,7 +584,7 @@ var OrderlyConfigProvider = (props) => {
|
|
|
465
584
|
if (!account5) {
|
|
466
585
|
return null;
|
|
467
586
|
}
|
|
468
|
-
return /* @__PURE__ */
|
|
587
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
469
588
|
OrderlyProvider,
|
|
470
589
|
{
|
|
471
590
|
value: {
|
|
@@ -475,9 +594,9 @@ var OrderlyConfigProvider = (props) => {
|
|
|
475
594
|
networkId,
|
|
476
595
|
enableSwapDeposit
|
|
477
596
|
// apiBaseUrl,
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
|
|
597
|
+
},
|
|
598
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(DataCenterProvider, { children: props.children })
|
|
599
|
+
}
|
|
481
600
|
);
|
|
482
601
|
};
|
|
483
602
|
var WalletConnectorContext = React.createContext({});
|
|
@@ -1099,7 +1218,7 @@ var usePositionStream = (symbol, options) => {
|
|
|
1099
1218
|
} = usePrivateQuery(`/v1/positions`, {
|
|
1100
1219
|
// revalidateOnFocus: false,
|
|
1101
1220
|
// revalidateOnReconnect: false,
|
|
1102
|
-
// dedupingInterval:
|
|
1221
|
+
// dedupingInterval: 200,
|
|
1103
1222
|
// keepPreviousData: false,
|
|
1104
1223
|
// revalidateIfStale: true,
|
|
1105
1224
|
...options,
|
|
@@ -1107,10 +1226,6 @@ var usePositionStream = (symbol, options) => {
|
|
|
1107
1226
|
onError: (err) => {
|
|
1108
1227
|
}
|
|
1109
1228
|
});
|
|
1110
|
-
usePositionUpdateStream((positions2) => {
|
|
1111
|
-
console.log("position message", positions2);
|
|
1112
|
-
updatePositions();
|
|
1113
|
-
});
|
|
1114
1229
|
const { data: markPrices } = useMarkPricesStream();
|
|
1115
1230
|
const formatedPositions = React.useMemo(() => {
|
|
1116
1231
|
if (!data?.rows || !symbolInfo || !accountInfo)
|
|
@@ -1259,41 +1374,6 @@ var pathOr_unsettledPnLPathOr = ramda.pathOr(0, [
|
|
|
1259
1374
|
"aggregated",
|
|
1260
1375
|
"unsettledPnL"
|
|
1261
1376
|
]);
|
|
1262
|
-
var usePositionUpdateStream = (callback) => {
|
|
1263
|
-
const ws = useWS();
|
|
1264
|
-
const positionList = React.useRef({});
|
|
1265
|
-
return useSWRSubscription__default.default("positionUpdate", (key, { next }) => {
|
|
1266
|
-
const unsubscribe = ws.privateSubscribe(
|
|
1267
|
-
// { event: "subscribe", topic: "markprices" },
|
|
1268
|
-
"position",
|
|
1269
|
-
{
|
|
1270
|
-
onMessage: (message) => {
|
|
1271
|
-
const { positions: positions2 } = message;
|
|
1272
|
-
let update = false;
|
|
1273
|
-
for (const p in positions2) {
|
|
1274
|
-
const { symbol, positionQty } = positions2[p];
|
|
1275
|
-
if (positionList.current[symbol] !== positionQty) {
|
|
1276
|
-
update = true;
|
|
1277
|
-
positionList.current[symbol] = positionQty;
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
if (update) {
|
|
1281
|
-
callback(positions2.current);
|
|
1282
|
-
}
|
|
1283
|
-
next(null, positionList);
|
|
1284
|
-
},
|
|
1285
|
-
// onUnsubscribe: () => {
|
|
1286
|
-
// return "markprices";
|
|
1287
|
-
// },
|
|
1288
|
-
onError: (error) => {
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
);
|
|
1292
|
-
return () => {
|
|
1293
|
-
unsubscribe?.();
|
|
1294
|
-
};
|
|
1295
|
-
});
|
|
1296
|
-
};
|
|
1297
1377
|
var useHoldingStream = () => {
|
|
1298
1378
|
const ws = useWS();
|
|
1299
1379
|
const { data, isLoading, mutate: mutate2 } = usePrivateQuery(
|
|
@@ -1345,10 +1425,15 @@ var useHoldingStream = () => {
|
|
|
1345
1425
|
};
|
|
1346
1426
|
var useOrderStream = (params) => {
|
|
1347
1427
|
const { status, symbol, side, size = 100 } = params;
|
|
1348
|
-
const ws = useWS();
|
|
1349
1428
|
const { data: markPrices = {} } = useMarkPricesStream();
|
|
1350
|
-
const [doCancelOrder] = useMutation(
|
|
1351
|
-
|
|
1429
|
+
const [doCancelOrder, { error: cancelOrderError }] = useMutation(
|
|
1430
|
+
"/v1/order",
|
|
1431
|
+
"DELETE"
|
|
1432
|
+
);
|
|
1433
|
+
const [doUpdateOrder, { error: updateOrderError }] = useMutation(
|
|
1434
|
+
"/v1/order",
|
|
1435
|
+
"PUT"
|
|
1436
|
+
);
|
|
1352
1437
|
const ordersResponse = usePrivateInfiniteQuery(
|
|
1353
1438
|
(pageIndex, previousPageData) => {
|
|
1354
1439
|
if (previousPageData && !previousPageData.rows?.length)
|
|
@@ -1371,9 +1456,9 @@ var useOrderStream = (params) => {
|
|
|
1371
1456
|
{
|
|
1372
1457
|
initialSize: 1,
|
|
1373
1458
|
// revalidateFirstPage: false,
|
|
1374
|
-
onError: (err) => {
|
|
1375
|
-
|
|
1376
|
-
},
|
|
1459
|
+
// onError: (err) => {
|
|
1460
|
+
// console.error("fetch failed::::", err);
|
|
1461
|
+
// },
|
|
1377
1462
|
formatter: (data) => data
|
|
1378
1463
|
}
|
|
1379
1464
|
);
|
|
@@ -1390,68 +1475,7 @@ var useOrderStream = (params) => {
|
|
|
1390
1475
|
}, [ordersResponse.data, markPrices]);
|
|
1391
1476
|
const total = React.useMemo(() => {
|
|
1392
1477
|
return ordersResponse.data?.[0]?.meta?.total || 0;
|
|
1393
|
-
}, [ordersResponse.data]);
|
|
1394
|
-
React.useEffect(() => {
|
|
1395
|
-
const unsubscribe = ws.privateSubscribe(
|
|
1396
|
-
{
|
|
1397
|
-
id: "executionreport_orders",
|
|
1398
|
-
event: "subscribe",
|
|
1399
|
-
topic: "executionreport",
|
|
1400
|
-
ts: Date.now()
|
|
1401
|
-
},
|
|
1402
|
-
{
|
|
1403
|
-
onMessage: (data) => {
|
|
1404
|
-
const { status: status2, orderId, timestamp } = data;
|
|
1405
|
-
ordersResponse.mutate((prevData) => {
|
|
1406
|
-
const newOrder = {
|
|
1407
|
-
order_id: data.orderId,
|
|
1408
|
-
symbol: data.symbol,
|
|
1409
|
-
created_time: data.timestamp,
|
|
1410
|
-
quantity: data.quantity,
|
|
1411
|
-
side: data.side,
|
|
1412
|
-
executed: data.totalExecutedQuantity,
|
|
1413
|
-
price: data.price
|
|
1414
|
-
};
|
|
1415
|
-
const dataList = prevData?.map((item) => item.rows)?.flat() || [];
|
|
1416
|
-
if (status2 === types.OrderStatus.NEW) {
|
|
1417
|
-
if (!prevData) {
|
|
1418
|
-
return {
|
|
1419
|
-
meta: {
|
|
1420
|
-
total: 1,
|
|
1421
|
-
records_per_page: size,
|
|
1422
|
-
current_page: 1
|
|
1423
|
-
},
|
|
1424
|
-
rows: [newOrder]
|
|
1425
|
-
};
|
|
1426
|
-
}
|
|
1427
|
-
const total2 = (prevData?.[0]?.meta?.total || 0) + 1;
|
|
1428
|
-
const isNew = !dataList.find((item) => item.order_id === orderId);
|
|
1429
|
-
if (isNew) {
|
|
1430
|
-
const list = [newOrder, ...dataList];
|
|
1431
|
-
return rePageData(list, total2, size);
|
|
1432
|
-
}
|
|
1433
|
-
return prevData;
|
|
1434
|
-
}
|
|
1435
|
-
if (status2 === types.OrderStatus.CANCELLED || status2 === types.OrderStatus.FILLED) {
|
|
1436
|
-
const total2 = (prevData?.[0]?.meta?.total || 0) - 1;
|
|
1437
|
-
const list = dataList.filter(
|
|
1438
|
-
(order2) => order2.order_id !== orderId
|
|
1439
|
-
);
|
|
1440
|
-
return rePageData(list, total2, size);
|
|
1441
|
-
}
|
|
1442
|
-
if (status2 === types.OrderStatus.PARTIAL_FILLED) {
|
|
1443
|
-
return editPageData(dataList, newOrder);
|
|
1444
|
-
}
|
|
1445
|
-
if (status2 === types.OrderStatus.REPLACED) {
|
|
1446
|
-
return editPageData(dataList, newOrder);
|
|
1447
|
-
}
|
|
1448
|
-
return prevData;
|
|
1449
|
-
});
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
);
|
|
1453
|
-
return () => unsubscribe();
|
|
1454
|
-
}, []);
|
|
1478
|
+
}, [ordersResponse.data?.[0]?.meta?.total]);
|
|
1455
1479
|
const cancelAllOrders = React.useCallback(() => {
|
|
1456
1480
|
}, [ordersResponse.data]);
|
|
1457
1481
|
const updateOrder = React.useCallback((orderId, order2) => {
|
|
@@ -1478,44 +1502,14 @@ var useOrderStream = (params) => {
|
|
|
1478
1502
|
loadMore,
|
|
1479
1503
|
cancelAllOrders,
|
|
1480
1504
|
updateOrder,
|
|
1481
|
-
cancelOrder
|
|
1505
|
+
cancelOrder,
|
|
1506
|
+
errors: {
|
|
1507
|
+
cancelOrder: cancelOrderError,
|
|
1508
|
+
updateOrder: updateOrderError
|
|
1509
|
+
}
|
|
1482
1510
|
}
|
|
1483
1511
|
];
|
|
1484
1512
|
};
|
|
1485
|
-
function rePageData(list, total, pageSize) {
|
|
1486
|
-
const newData = [];
|
|
1487
|
-
let rows = [];
|
|
1488
|
-
let current_page = 0;
|
|
1489
|
-
for (let i = 0; i < list.length; i++) {
|
|
1490
|
-
rows.push(list[i]);
|
|
1491
|
-
if ((i + 1) % pageSize === 0 || i === list.length - 1) {
|
|
1492
|
-
newData.push({
|
|
1493
|
-
meta: {
|
|
1494
|
-
records_per_page: pageSize,
|
|
1495
|
-
total,
|
|
1496
|
-
current_page: current_page + 1
|
|
1497
|
-
},
|
|
1498
|
-
rows: [...rows]
|
|
1499
|
-
});
|
|
1500
|
-
rows = [];
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
return newData;
|
|
1504
|
-
}
|
|
1505
|
-
function editPageData(list, newOrder) {
|
|
1506
|
-
const newData = list.map((item) => {
|
|
1507
|
-
return {
|
|
1508
|
-
...item,
|
|
1509
|
-
rows: item.rows.map((row) => {
|
|
1510
|
-
if (row.order_id === newOrder.order_id) {
|
|
1511
|
-
return { ...row, newOrder };
|
|
1512
|
-
}
|
|
1513
|
-
return row;
|
|
1514
|
-
})
|
|
1515
|
-
};
|
|
1516
|
-
});
|
|
1517
|
-
return newData;
|
|
1518
|
-
}
|
|
1519
1513
|
|
|
1520
1514
|
// src/orderly/useCollateral.ts
|
|
1521
1515
|
var positionsPath = ramda.pathOr([], [0, "rows"]);
|
|
@@ -1574,33 +1568,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
1574
1568
|
const symbolInfo = useSymbolsInfo();
|
|
1575
1569
|
const { totalCollateral } = useCollateral();
|
|
1576
1570
|
const { data: markPrices } = useMarkPricesStream();
|
|
1577
|
-
const {
|
|
1578
|
-
data: orders,
|
|
1579
|
-
error,
|
|
1580
|
-
mutate: updateOrder
|
|
1581
|
-
} = usePrivateQuery(`/v1/orders?status=NEW&size=99`, {
|
|
1582
|
-
formatter: (data) => data.rows,
|
|
1583
|
-
onError: (err) => {
|
|
1584
|
-
}
|
|
1585
|
-
});
|
|
1586
|
-
const ws = useWS();
|
|
1587
|
-
React.useEffect(() => {
|
|
1588
|
-
const unsubscribe = ws.privateSubscribe(
|
|
1589
|
-
{
|
|
1590
|
-
id: "executionreport_orders",
|
|
1591
|
-
event: "subscribe",
|
|
1592
|
-
topic: "executionreport",
|
|
1593
|
-
ts: Date.now()
|
|
1594
|
-
},
|
|
1595
|
-
{
|
|
1596
|
-
onMessage: (data) => {
|
|
1597
|
-
console.log("refresh orders", data);
|
|
1598
|
-
updateOrder();
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
);
|
|
1602
|
-
return () => unsubscribe();
|
|
1603
|
-
}, []);
|
|
1571
|
+
const [orders] = useOrderStream({ status: types.OrderStatus.NEW });
|
|
1604
1572
|
const maxQty = React.useMemo(() => {
|
|
1605
1573
|
if (!symbol)
|
|
1606
1574
|
return 0;
|
|
@@ -1974,7 +1942,6 @@ var useLeverage = () => {
|
|
|
1974
1942
|
const { data: config } = useQuery("/v1/public/config");
|
|
1975
1943
|
const updateLeverage = React.useCallback((data2) => {
|
|
1976
1944
|
return update(data2).then((res) => {
|
|
1977
|
-
console.log(res);
|
|
1978
1945
|
if (res.success) {
|
|
1979
1946
|
return mutate2();
|
|
1980
1947
|
} else {
|
|
@@ -3156,7 +3123,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3156
3123
|
}
|
|
3157
3124
|
);
|
|
3158
3125
|
const { data: orderlyChains, error: tokenError } = useQuery(
|
|
3159
|
-
// wooSwapEnabled ? "/v1/public/token" :
|
|
3126
|
+
// wooSwapEnabled ? "/v1/public/token" :
|
|
3160
3127
|
"https://api-evm.orderly.org/v1/public/token",
|
|
3161
3128
|
{
|
|
3162
3129
|
revalidateIfStale: false,
|
|
@@ -3167,11 +3134,9 @@ var useChains = (networkId, options = {}) => {
|
|
|
3167
3134
|
}
|
|
3168
3135
|
);
|
|
3169
3136
|
const chains = React.useMemo(() => {
|
|
3170
|
-
if (!orderlyChains)
|
|
3171
|
-
return void 0;
|
|
3172
3137
|
let orderlyChainsArr = [];
|
|
3173
3138
|
const orderlyChainIds = /* @__PURE__ */ new Set();
|
|
3174
|
-
orderlyChains
|
|
3139
|
+
orderlyChains?.forEach((item) => {
|
|
3175
3140
|
item.chain_details.forEach((chain) => {
|
|
3176
3141
|
const chainId = Number(chain.chain_id);
|
|
3177
3142
|
orderlyChainIds.add(chainId);
|
|
@@ -3197,7 +3162,9 @@ var useChains = (networkId, options = {}) => {
|
|
|
3197
3162
|
return;
|
|
3198
3163
|
}
|
|
3199
3164
|
if (_chain.chain_id === 421613) {
|
|
3200
|
-
const index = testnetArr.findIndex(
|
|
3165
|
+
const index = testnetArr.findIndex(
|
|
3166
|
+
(item2) => item2.network_infos.chain_id === 421613
|
|
3167
|
+
);
|
|
3201
3168
|
if (index > -1) {
|
|
3202
3169
|
testnetArr[index] = _chain;
|
|
3203
3170
|
}
|
|
@@ -3264,16 +3231,19 @@ var useChains = (networkId, options = {}) => {
|
|
|
3264
3231
|
}
|
|
3265
3232
|
});
|
|
3266
3233
|
} else {
|
|
3267
|
-
if (!chainInfos)
|
|
3268
|
-
return void 0;
|
|
3269
3234
|
orderlyChainsArr.forEach((chain) => {
|
|
3270
3235
|
let _chain = chain;
|
|
3271
|
-
const networkInfo = chainInfos
|
|
3272
|
-
console.log(item.chain_id, chain.network_infos.chain_id);
|
|
3236
|
+
const networkInfo = chainInfos?.find((item) => {
|
|
3273
3237
|
return item.chain_id == chain.network_infos.chain_id;
|
|
3274
3238
|
});
|
|
3275
3239
|
if (networkInfo) {
|
|
3276
|
-
const {
|
|
3240
|
+
const {
|
|
3241
|
+
name,
|
|
3242
|
+
public_rpc_url,
|
|
3243
|
+
chain_id,
|
|
3244
|
+
currency_symbol,
|
|
3245
|
+
explorer_base_url
|
|
3246
|
+
} = networkInfo;
|
|
3277
3247
|
_chain.network_infos = {
|
|
3278
3248
|
..._chain.network_infos,
|
|
3279
3249
|
name,
|
|
@@ -3290,7 +3260,9 @@ var useChains = (networkId, options = {}) => {
|
|
|
3290
3260
|
}
|
|
3291
3261
|
map.current.set(_chain.network_infos.chain_id, _chain);
|
|
3292
3262
|
if (_chain.network_infos.chain_id === 421613) {
|
|
3293
|
-
const index = testnetArr.findIndex(
|
|
3263
|
+
const index = testnetArr.findIndex(
|
|
3264
|
+
(item) => item.network_infos.chain_id === 421613
|
|
3265
|
+
);
|
|
3294
3266
|
if (index > -1) {
|
|
3295
3267
|
testnetArr[index] = _chain;
|
|
3296
3268
|
}
|
|
@@ -3322,7 +3294,15 @@ var useChains = (networkId, options = {}) => {
|
|
|
3322
3294
|
testnet: testnetArr,
|
|
3323
3295
|
mainnet: mainnetArr
|
|
3324
3296
|
};
|
|
3325
|
-
}, [
|
|
3297
|
+
}, [
|
|
3298
|
+
data,
|
|
3299
|
+
networkId,
|
|
3300
|
+
field,
|
|
3301
|
+
options,
|
|
3302
|
+
orderlyChains,
|
|
3303
|
+
wooSwapEnabled,
|
|
3304
|
+
chainInfos
|
|
3305
|
+
]);
|
|
3326
3306
|
const findByChainId = React.useCallback(
|
|
3327
3307
|
(chainId, field2) => {
|
|
3328
3308
|
const chain = map.current.get(chainId);
|
|
@@ -3418,7 +3398,7 @@ var useDeposit = (options) => {
|
|
|
3418
3398
|
network: chain.network_infos.shortName
|
|
3419
3399
|
// chainId: 42161,
|
|
3420
3400
|
};
|
|
3421
|
-
}, [networkId]);
|
|
3401
|
+
}, [networkId, findByChainId]);
|
|
3422
3402
|
const isNativeToken = React.useMemo(
|
|
3423
3403
|
() => isNativeTokenChecker(options?.address || ""),
|
|
3424
3404
|
[options?.address]
|
|
@@ -3621,59 +3601,6 @@ var useSettleSubscription = (options) => {
|
|
|
3621
3601
|
return () => unsubscribe();
|
|
3622
3602
|
});
|
|
3623
3603
|
};
|
|
3624
|
-
var usePrivateDataObserver = () => {
|
|
3625
|
-
const ws = useWS();
|
|
3626
|
-
const { mutate: mutate2 } = useSWR.useSWRConfig();
|
|
3627
|
-
const { state } = useAccount();
|
|
3628
|
-
React.useEffect(() => {
|
|
3629
|
-
if (!state.accountId)
|
|
3630
|
-
return;
|
|
3631
|
-
const key = ["/v1/positions", state.accountId];
|
|
3632
|
-
const unsubscribe = ws.privateSubscribe("position", {
|
|
3633
|
-
onMessage: (data) => {
|
|
3634
|
-
const { positions: nextPostions } = data;
|
|
3635
|
-
mutate2(key, (prevPositions) => {
|
|
3636
|
-
if (!!prevPositions) {
|
|
3637
|
-
return {
|
|
3638
|
-
...prevPositions,
|
|
3639
|
-
rows: prevPositions.rows.map((row) => {
|
|
3640
|
-
const item = nextPostions.find(
|
|
3641
|
-
(item2) => item2.symbol === row.symbol
|
|
3642
|
-
);
|
|
3643
|
-
if (item) {
|
|
3644
|
-
return {
|
|
3645
|
-
symbol: item.symbol,
|
|
3646
|
-
position_qty: item.positionQty,
|
|
3647
|
-
cost_position: item.costPosition,
|
|
3648
|
-
last_sum_unitary_funding: item.lastSumUnitaryFunding,
|
|
3649
|
-
pending_long_qty: item.pendingLongQty,
|
|
3650
|
-
pending_short_qty: item.pendingShortQty,
|
|
3651
|
-
settle_price: item.settlePrice,
|
|
3652
|
-
average_open_price: item.averageOpenPrice,
|
|
3653
|
-
unsettled_pnl: item.unsettledPnl,
|
|
3654
|
-
mark_price: item.markPrice,
|
|
3655
|
-
est_liq_price: item.estLiqPrice,
|
|
3656
|
-
timestamp: Date.now(),
|
|
3657
|
-
imr: item.imr,
|
|
3658
|
-
mmr: item.mmr,
|
|
3659
|
-
IMR_withdraw_orders: item.imrwithOrders,
|
|
3660
|
-
MMR_with_orders: item.mmrwithOrders,
|
|
3661
|
-
pnl_24_h: item.pnl24H,
|
|
3662
|
-
fee_24_h: item.fee24H
|
|
3663
|
-
};
|
|
3664
|
-
}
|
|
3665
|
-
return row;
|
|
3666
|
-
})
|
|
3667
|
-
};
|
|
3668
|
-
}
|
|
3669
|
-
});
|
|
3670
|
-
}
|
|
3671
|
-
});
|
|
3672
|
-
return () => {
|
|
3673
|
-
unsubscribe?.();
|
|
3674
|
-
};
|
|
3675
|
-
}, [state.accountId]);
|
|
3676
|
-
};
|
|
3677
3604
|
var useWooSwapQuery = () => {
|
|
3678
3605
|
const { configStore } = React.useContext(OrderlyContext);
|
|
3679
3606
|
const account5 = useAccountInstance();
|