@orderly.network/hooks 1.0.7 → 1.0.8
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 +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +26 -74
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -75
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -8,6 +8,7 @@ export { default as useConstant } from 'use-constant';
|
|
|
8
8
|
import { SimpleDI, Account, EventEmitter, MemoryConfigStore, 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
10
|
import useSWRInfinite from 'swr/infinite';
|
|
11
|
+
import { jsx } from 'react/jsx-runtime';
|
|
11
12
|
import { Decimal, zero, getPrecisionByNumber, timeConvertString } from '@orderly.network/utils';
|
|
12
13
|
import useSWRSubscription from 'swr/subscription';
|
|
13
14
|
import { pathOr, propOr, compose, head, prop, mergeDeepRight, pick, min } from 'ramda';
|
|
@@ -21,6 +22,9 @@ var OrderlyContext = createContext({
|
|
|
21
22
|
// configStore: new MemoryConfigStore(),
|
|
22
23
|
});
|
|
23
24
|
var OrderlyProvider = OrderlyContext.Provider;
|
|
25
|
+
var useOrderlyContext = () => {
|
|
26
|
+
return useContext(OrderlyContext);
|
|
27
|
+
};
|
|
24
28
|
|
|
25
29
|
// src/useConfig.ts
|
|
26
30
|
var useConfig = (key, defaultValue) => {
|
|
@@ -463,7 +467,7 @@ var OrderlyConfigProvider = (props) => {
|
|
|
463
467
|
if (!account5) {
|
|
464
468
|
return null;
|
|
465
469
|
}
|
|
466
|
-
return /* @__PURE__ */
|
|
470
|
+
return /* @__PURE__ */ jsx(
|
|
467
471
|
OrderlyProvider,
|
|
468
472
|
{
|
|
469
473
|
value: {
|
|
@@ -471,10 +475,9 @@ var OrderlyConfigProvider = (props) => {
|
|
|
471
475
|
keyStore: innerKeyStore,
|
|
472
476
|
getWalletAdapter: innerGetWalletAdapter,
|
|
473
477
|
networkId
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}
|
|
477
|
-
props.children
|
|
478
|
+
},
|
|
479
|
+
children: props.children
|
|
480
|
+
}
|
|
478
481
|
);
|
|
479
482
|
};
|
|
480
483
|
var WalletConnectorContext = createContext({});
|
|
@@ -1091,8 +1094,8 @@ var usePositionStream = (symbol, options) => {
|
|
|
1091
1094
|
const fundingRates = useFundingRates();
|
|
1092
1095
|
const {
|
|
1093
1096
|
data,
|
|
1094
|
-
error
|
|
1095
|
-
mutate: updatePositions
|
|
1097
|
+
error
|
|
1098
|
+
// mutate: updatePositions,
|
|
1096
1099
|
} = usePrivateQuery(`/v1/positions`, {
|
|
1097
1100
|
// revalidateOnFocus: false,
|
|
1098
1101
|
// revalidateOnReconnect: false,
|
|
@@ -1104,10 +1107,6 @@ var usePositionStream = (symbol, options) => {
|
|
|
1104
1107
|
onError: (err) => {
|
|
1105
1108
|
}
|
|
1106
1109
|
});
|
|
1107
|
-
usePositionUpdateStream((positions2) => {
|
|
1108
|
-
console.log("position message", positions2);
|
|
1109
|
-
updatePositions();
|
|
1110
|
-
});
|
|
1111
1110
|
const { data: markPrices } = useMarkPricesStream();
|
|
1112
1111
|
const formatedPositions = useMemo(() => {
|
|
1113
1112
|
if (!data?.rows || !symbolInfo || !accountInfo)
|
|
@@ -1256,41 +1255,6 @@ var pathOr_unsettledPnLPathOr = pathOr(0, [
|
|
|
1256
1255
|
"aggregated",
|
|
1257
1256
|
"unsettledPnL"
|
|
1258
1257
|
]);
|
|
1259
|
-
var usePositionUpdateStream = (callback) => {
|
|
1260
|
-
const ws = useWS();
|
|
1261
|
-
const positionList = useRef({});
|
|
1262
|
-
return useSWRSubscription("positionUpdate", (key, { next }) => {
|
|
1263
|
-
const unsubscribe = ws.privateSubscribe(
|
|
1264
|
-
// { event: "subscribe", topic: "markprices" },
|
|
1265
|
-
"position",
|
|
1266
|
-
{
|
|
1267
|
-
onMessage: (message) => {
|
|
1268
|
-
const { positions: positions2 } = message;
|
|
1269
|
-
let update = false;
|
|
1270
|
-
for (const p in positions2) {
|
|
1271
|
-
const { symbol, positionQty } = positions2[p];
|
|
1272
|
-
if (positionList.current[symbol] !== positionQty) {
|
|
1273
|
-
update = true;
|
|
1274
|
-
positionList.current[symbol] = positionQty;
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
if (update) {
|
|
1278
|
-
callback(positions2.current);
|
|
1279
|
-
}
|
|
1280
|
-
next(null, positionList);
|
|
1281
|
-
},
|
|
1282
|
-
// onUnsubscribe: () => {
|
|
1283
|
-
// return "markprices";
|
|
1284
|
-
// },
|
|
1285
|
-
onError: (error) => {
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
);
|
|
1289
|
-
return () => {
|
|
1290
|
-
unsubscribe?.();
|
|
1291
|
-
};
|
|
1292
|
-
});
|
|
1293
|
-
};
|
|
1294
1258
|
var useHoldingStream = () => {
|
|
1295
1259
|
const ws = useWS();
|
|
1296
1260
|
const { data, isLoading, mutate: mutate2 } = usePrivateQuery(
|
|
@@ -1305,7 +1269,7 @@ var useHoldingStream = () => {
|
|
|
1305
1269
|
const usdc2 = data?.find((item) => item.token === "USDC");
|
|
1306
1270
|
return usdc2;
|
|
1307
1271
|
}, [data]);
|
|
1308
|
-
useSWRSubscription("holding", (_, { next }) => {
|
|
1272
|
+
const { data: balance } = useSWRSubscription("holding", (_, { next }) => {
|
|
1309
1273
|
const unsubscribe = ws.privateSubscribe(
|
|
1310
1274
|
{
|
|
1311
1275
|
id: "balance",
|
|
@@ -1337,6 +1301,7 @@ var useHoldingStream = () => {
|
|
|
1337
1301
|
return {
|
|
1338
1302
|
data,
|
|
1339
1303
|
usdc,
|
|
1304
|
+
balance,
|
|
1340
1305
|
isLoading
|
|
1341
1306
|
};
|
|
1342
1307
|
};
|
|
@@ -1567,37 +1532,11 @@ var useCollateral = (options = { dp: 6 }) => {
|
|
|
1567
1532
|
var positionsPath2 = pathOr([], [0, "rows"]);
|
|
1568
1533
|
var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
1569
1534
|
const positionsData = usePositionStream();
|
|
1535
|
+
const [orders] = useOrderStream({ status: OrderStatus.NEW });
|
|
1570
1536
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
1571
1537
|
const symbolInfo = useSymbolsInfo();
|
|
1572
1538
|
const { totalCollateral } = useCollateral();
|
|
1573
1539
|
const { data: markPrices } = useMarkPricesStream();
|
|
1574
|
-
const {
|
|
1575
|
-
data: orders,
|
|
1576
|
-
error,
|
|
1577
|
-
mutate: updateOrder
|
|
1578
|
-
} = usePrivateQuery(`/v1/orders?status=NEW&size=99`, {
|
|
1579
|
-
formatter: (data) => data.rows,
|
|
1580
|
-
onError: (err) => {
|
|
1581
|
-
}
|
|
1582
|
-
});
|
|
1583
|
-
const ws = useWS();
|
|
1584
|
-
useEffect(() => {
|
|
1585
|
-
const unsubscribe = ws.privateSubscribe(
|
|
1586
|
-
{
|
|
1587
|
-
id: "executionreport_orders",
|
|
1588
|
-
event: "subscribe",
|
|
1589
|
-
topic: "executionreport",
|
|
1590
|
-
ts: Date.now()
|
|
1591
|
-
},
|
|
1592
|
-
{
|
|
1593
|
-
onMessage: (data) => {
|
|
1594
|
-
console.log("refresh orders", data);
|
|
1595
|
-
updateOrder();
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
);
|
|
1599
|
-
return () => unsubscribe();
|
|
1600
|
-
}, []);
|
|
1601
1540
|
const maxQty = useMemo(() => {
|
|
1602
1541
|
if (!symbol)
|
|
1603
1542
|
return 0;
|
|
@@ -3562,6 +3501,17 @@ var usePrivateDataObserver = () => {
|
|
|
3562
3501
|
const ws = useWS();
|
|
3563
3502
|
const { mutate: mutate2 } = useSWRConfig();
|
|
3564
3503
|
const { state } = useAccount();
|
|
3504
|
+
useEffect(() => {
|
|
3505
|
+
console.log("----!!!usePrivateDataObserver!!!----");
|
|
3506
|
+
}, []);
|
|
3507
|
+
useEffect(() => {
|
|
3508
|
+
const unsubscribe = ws.privateSubscribe("executionreport", {
|
|
3509
|
+
onMessage: (data) => {
|
|
3510
|
+
console.log(data);
|
|
3511
|
+
}
|
|
3512
|
+
});
|
|
3513
|
+
return () => unsubscribe?.();
|
|
3514
|
+
}, [state.accountId]);
|
|
3565
3515
|
useEffect(() => {
|
|
3566
3516
|
if (!state.accountId)
|
|
3567
3517
|
return;
|
|
@@ -3569,6 +3519,7 @@ var usePrivateDataObserver = () => {
|
|
|
3569
3519
|
const unsubscribe = ws.privateSubscribe("position", {
|
|
3570
3520
|
onMessage: (data) => {
|
|
3571
3521
|
const { positions: nextPostions } = data;
|
|
3522
|
+
console.log("ws-----data-----", data);
|
|
3572
3523
|
mutate2(key, (prevPositions) => {
|
|
3573
3524
|
if (!!prevPositions) {
|
|
3574
3525
|
return {
|
|
@@ -4213,6 +4164,6 @@ var useSwap = () => {
|
|
|
4213
4164
|
};
|
|
4214
4165
|
};
|
|
4215
4166
|
|
|
4216
|
-
export { OrderlyConfigProvider, OrderlyContext, OrderlyProvider, WalletConnectorContext, useAccount, useAccountInfo, useAccountInstance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useWS, useWalletConnector, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
|
|
4167
|
+
export { OrderlyConfigProvider, OrderlyContext, OrderlyProvider, WalletConnectorContext, useAccount, useAccountInfo, useAccountInstance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, useOrderlyContext, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useWS, useWalletConnector, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
|
|
4217
4168
|
//# sourceMappingURL=out.js.map
|
|
4218
4169
|
//# sourceMappingURL=index.mjs.map
|