@orderly.network/hooks 1.0.0 → 1.0.2
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 +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +28 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import useSWR, { useSWRConfig } from 'swr';
|
|
2
2
|
export { SWRConfig, default as useSWR } from 'swr';
|
|
3
|
-
import {
|
|
3
|
+
import { get, WS, mutate } from '@orderly.network/net';
|
|
4
4
|
import React, { createContext, useContext, useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
|
5
5
|
import useSWRMutation from 'swr/mutation';
|
|
6
6
|
import useConstant4 from 'use-constant';
|
|
7
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
|
+
import useSWRInfinite from 'swr/infinite';
|
|
10
11
|
import { Decimal, zero, getPrecisionByNumber, timeConvertString } from '@orderly.network/utils';
|
|
11
12
|
import useSWRSubscription from 'swr/subscription';
|
|
12
13
|
import { pathOr, propOr, compose, head, prop, mergeDeepRight, pick, min } from 'ramda';
|
|
13
14
|
import { positions, account, order } from '@orderly.network/perp';
|
|
14
|
-
import useSWRInfinite from 'swr/infinite';
|
|
15
15
|
export * from 'use-debounce';
|
|
16
16
|
import { createClient } from '@layerzerolabs/scan-client';
|
|
17
17
|
|
|
@@ -254,6 +254,20 @@ var usePrivateQuery = (query, options) => {
|
|
|
254
254
|
}
|
|
255
255
|
);
|
|
256
256
|
};
|
|
257
|
+
var usePrivateInfiniteQuery = (getKey, options) => {
|
|
258
|
+
const { formatter, ...restOptions } = options || {};
|
|
259
|
+
const account5 = useAccount();
|
|
260
|
+
const middleware = Array.isArray(restOptions?.use) ? restOptions?.use ?? [] : [];
|
|
261
|
+
const result = useSWRInfinite(
|
|
262
|
+
(pageIndex, previousPageData) => account5.state.status >= AccountStatusEnum.EnableTrading ? getKey(pageIndex, previousPageData) : null,
|
|
263
|
+
(url, init) => get(url, init, formatter),
|
|
264
|
+
{
|
|
265
|
+
...restOptions,
|
|
266
|
+
use: [signatureMiddleware, ...middleware]
|
|
267
|
+
}
|
|
268
|
+
);
|
|
269
|
+
return result;
|
|
270
|
+
};
|
|
257
271
|
var useBoolean = (initialValue = false) => {
|
|
258
272
|
const [value, setValue] = useState(initialValue);
|
|
259
273
|
const setTrue = useCallback(() => setValue(true), []);
|
|
@@ -420,6 +434,7 @@ var useWS = () => {
|
|
|
420
434
|
return ws;
|
|
421
435
|
};
|
|
422
436
|
var OrderlyConfigProvider = (props) => {
|
|
437
|
+
const [account5, setAccount] = React.useState(null);
|
|
423
438
|
const { configStore, keyStore, getWalletAdapter, brokerId, networkId } = props;
|
|
424
439
|
if (!brokerId && typeof configStore === "undefined") {
|
|
425
440
|
console.error("[OrderlyConfigProvider]: brokerId is required");
|
|
@@ -434,16 +449,20 @@ var OrderlyConfigProvider = (props) => {
|
|
|
434
449
|
return getWalletAdapter || ((options) => new EtherAdapter(options));
|
|
435
450
|
});
|
|
436
451
|
useEffect(() => {
|
|
437
|
-
let
|
|
438
|
-
if (!
|
|
439
|
-
|
|
452
|
+
let account6 = SimpleDI.get(Account.instanceName);
|
|
453
|
+
if (!account6) {
|
|
454
|
+
account6 = new Account(
|
|
440
455
|
innerConfigStore,
|
|
441
456
|
innerKeyStore,
|
|
442
457
|
innerGetWalletAdapter
|
|
443
458
|
);
|
|
444
|
-
SimpleDI.registerByName(Account.instanceName,
|
|
459
|
+
SimpleDI.registerByName(Account.instanceName, account6);
|
|
445
460
|
}
|
|
461
|
+
setAccount(account6);
|
|
446
462
|
}, []);
|
|
463
|
+
if (!account5) {
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
447
466
|
return /* @__PURE__ */ React.createElement(
|
|
448
467
|
OrderlyProvider,
|
|
449
468
|
{
|
|
@@ -1278,20 +1297,6 @@ var useHoldingStream = () => {
|
|
|
1278
1297
|
isLoading
|
|
1279
1298
|
};
|
|
1280
1299
|
};
|
|
1281
|
-
var usePrivateInfiniteQuery = (getKey, options) => {
|
|
1282
|
-
const { formatter, ...restOptions } = options || {};
|
|
1283
|
-
const account5 = useAccount();
|
|
1284
|
-
const middleware = Array.isArray(restOptions?.use) ? restOptions?.use ?? [] : [];
|
|
1285
|
-
const result = useSWRInfinite(
|
|
1286
|
-
(pageIndex, previousPageData) => account5.state.status >= AccountStatusEnum.EnableTrading ? getKey(pageIndex, previousPageData) : null,
|
|
1287
|
-
(url, init) => get(url, init, formatter),
|
|
1288
|
-
{
|
|
1289
|
-
...restOptions,
|
|
1290
|
-
use: [signatureMiddleware, ...middleware]
|
|
1291
|
-
}
|
|
1292
|
-
);
|
|
1293
|
-
return result;
|
|
1294
|
-
};
|
|
1295
1300
|
var useOrderStream = (params) => {
|
|
1296
1301
|
const { status, symbol, side, size = 100 } = params;
|
|
1297
1302
|
const ws = useWS();
|
|
@@ -1300,7 +1305,7 @@ var useOrderStream = (params) => {
|
|
|
1300
1305
|
const [doUpdateOrder] = useMutation("/v1/order", "PUT");
|
|
1301
1306
|
const ordersResponse = usePrivateInfiniteQuery(
|
|
1302
1307
|
(pageIndex, previousPageData) => {
|
|
1303
|
-
if (previousPageData && !previousPageData.length)
|
|
1308
|
+
if (previousPageData && !previousPageData.rows?.length)
|
|
1304
1309
|
return null;
|
|
1305
1310
|
const search = new URLSearchParams([
|
|
1306
1311
|
["size", size.toString()],
|
|
@@ -1319,6 +1324,7 @@ var useOrderStream = (params) => {
|
|
|
1319
1324
|
},
|
|
1320
1325
|
{
|
|
1321
1326
|
initialSize: 1,
|
|
1327
|
+
// revalidateFirstPage: false,
|
|
1322
1328
|
onError: (err) => {
|
|
1323
1329
|
console.error("fetch failed::::", err);
|
|
1324
1330
|
},
|
|
@@ -4138,6 +4144,6 @@ var useSwap = () => {
|
|
|
4138
4144
|
};
|
|
4139
4145
|
};
|
|
4140
4146
|
|
|
4141
|
-
export { OrderlyConfigProvider, OrderlyContext, OrderlyProvider, 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, usePrivateQuery, useQuery, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useWS, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
|
|
4147
|
+
export { OrderlyConfigProvider, OrderlyContext, OrderlyProvider, 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, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
|
|
4142
4148
|
//# sourceMappingURL=out.js.map
|
|
4143
4149
|
//# sourceMappingURL=index.mjs.map
|