@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 CHANGED
@@ -9,8 +9,9 @@ import { AccountState, Account, EventEmitter, ConfigKey, ConfigStore, OrderlyKey
9
9
  export { default as useConstant } from 'use-constant';
10
10
  import { WS } from '@orderly.network/net';
11
11
  import * as react from 'react';
12
- import react__default, { PropsWithChildren } from 'react';
12
+ import { PropsWithChildren } from 'react';
13
13
  import { NetworkId, OrderSide, OrderEntity, API, WSMessage, OrderStatus, WS_WalletStatusEnum } from '@orderly.network/types';
14
+ import * as react_jsx_runtime from 'react/jsx-runtime';
14
15
  import * as swr_subscription from 'swr/subscription';
15
16
  import { Decimal } from '@orderly.network/utils';
16
17
  export * from 'use-debounce';
@@ -98,6 +99,7 @@ interface OrderlyConfigContextState {
98
99
  }
99
100
  declare const OrderlyContext: react.Context<OrderlyConfigContextState>;
100
101
  declare const OrderlyProvider: react.Provider<OrderlyConfigContextState>;
102
+ declare const useOrderlyContext: () => OrderlyConfigContextState;
101
103
 
102
104
  declare type RequireAtLeastOne<T, R extends keyof T = keyof T> = Omit<T, R> & {
103
105
  [K in R]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<R, K>>>;
@@ -109,7 +111,7 @@ interface ConfigProviderProps {
109
111
  brokerId: string;
110
112
  networkId: NetworkId;
111
113
  }
112
- declare const OrderlyConfigProvider: (props: PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>) => react__default.JSX.Element | null;
114
+ declare const OrderlyConfigProvider: (props: PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>) => react_jsx_runtime.JSX.Element | null;
113
115
 
114
116
  declare type ConnectedChain = {
115
117
  id: string;
@@ -339,6 +341,7 @@ declare const useDeposit: (options?: useDepositOptions | undefined) => {
339
341
  declare const useHoldingStream: () => {
340
342
  data: API.Holding[] | undefined;
341
343
  usdc: API.Holding | undefined;
344
+ balance: any;
342
345
  isLoading: boolean;
343
346
  };
344
347
 
@@ -429,4 +432,4 @@ declare const useSwap: () => {
429
432
  status: WS_WalletStatusEnum;
430
433
  };
431
434
 
432
- export { ConfigProviderProps, OrderlyConfigContextState, 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 };
435
+ export { ConfigProviderProps, 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 };
package/dist/index.d.ts CHANGED
@@ -9,8 +9,9 @@ import { AccountState, Account, EventEmitter, ConfigKey, ConfigStore, OrderlyKey
9
9
  export { default as useConstant } from 'use-constant';
10
10
  import { WS } from '@orderly.network/net';
11
11
  import * as react from 'react';
12
- import react__default, { PropsWithChildren } from 'react';
12
+ import { PropsWithChildren } from 'react';
13
13
  import { NetworkId, OrderSide, OrderEntity, API, WSMessage, OrderStatus, WS_WalletStatusEnum } from '@orderly.network/types';
14
+ import * as react_jsx_runtime from 'react/jsx-runtime';
14
15
  import * as swr_subscription from 'swr/subscription';
15
16
  import { Decimal } from '@orderly.network/utils';
16
17
  export * from 'use-debounce';
@@ -98,6 +99,7 @@ interface OrderlyConfigContextState {
98
99
  }
99
100
  declare const OrderlyContext: react.Context<OrderlyConfigContextState>;
100
101
  declare const OrderlyProvider: react.Provider<OrderlyConfigContextState>;
102
+ declare const useOrderlyContext: () => OrderlyConfigContextState;
101
103
 
102
104
  declare type RequireAtLeastOne<T, R extends keyof T = keyof T> = Omit<T, R> & {
103
105
  [K in R]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<R, K>>>;
@@ -109,7 +111,7 @@ interface ConfigProviderProps {
109
111
  brokerId: string;
110
112
  networkId: NetworkId;
111
113
  }
112
- declare const OrderlyConfigProvider: (props: PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>) => react__default.JSX.Element | null;
114
+ declare const OrderlyConfigProvider: (props: PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>) => react_jsx_runtime.JSX.Element | null;
113
115
 
114
116
  declare type ConnectedChain = {
115
117
  id: string;
@@ -339,6 +341,7 @@ declare const useDeposit: (options?: useDepositOptions | undefined) => {
339
341
  declare const useHoldingStream: () => {
340
342
  data: API.Holding[] | undefined;
341
343
  usdc: API.Holding | undefined;
344
+ balance: any;
342
345
  isLoading: boolean;
343
346
  };
344
347
 
@@ -429,4 +432,4 @@ declare const useSwap: () => {
429
432
  status: WS_WalletStatusEnum;
430
433
  };
431
434
 
432
- export { ConfigProviderProps, OrderlyConfigContextState, 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 };
435
+ export { ConfigProviderProps, 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 };
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ 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 jsxRuntime = require('react/jsx-runtime');
11
12
  var utils = require('@orderly.network/utils');
12
13
  var useSWRSubscription = require('swr/subscription');
13
14
  var ramda = require('ramda');
@@ -30,6 +31,9 @@ var OrderlyContext = React.createContext({
30
31
  // configStore: new MemoryConfigStore(),
31
32
  });
32
33
  var OrderlyProvider = OrderlyContext.Provider;
34
+ var useOrderlyContext = () => {
35
+ return React.useContext(OrderlyContext);
36
+ };
33
37
 
34
38
  // src/useConfig.ts
35
39
  var useConfig = (key, defaultValue) => {
@@ -472,7 +476,7 @@ var OrderlyConfigProvider = (props) => {
472
476
  if (!account5) {
473
477
  return null;
474
478
  }
475
- return /* @__PURE__ */ React__default.default.createElement(
479
+ return /* @__PURE__ */ jsxRuntime.jsx(
476
480
  OrderlyProvider,
477
481
  {
478
482
  value: {
@@ -480,10 +484,9 @@ var OrderlyConfigProvider = (props) => {
480
484
  keyStore: innerKeyStore,
481
485
  getWalletAdapter: innerGetWalletAdapter,
482
486
  networkId
483
- // apiBaseUrl,
484
- }
485
- },
486
- props.children
487
+ },
488
+ children: props.children
489
+ }
487
490
  );
488
491
  };
489
492
  var WalletConnectorContext = React.createContext({});
@@ -1100,8 +1103,8 @@ var usePositionStream = (symbol, options) => {
1100
1103
  const fundingRates = useFundingRates();
1101
1104
  const {
1102
1105
  data,
1103
- error,
1104
- mutate: updatePositions
1106
+ error
1107
+ // mutate: updatePositions,
1105
1108
  } = usePrivateQuery(`/v1/positions`, {
1106
1109
  // revalidateOnFocus: false,
1107
1110
  // revalidateOnReconnect: false,
@@ -1113,10 +1116,6 @@ var usePositionStream = (symbol, options) => {
1113
1116
  onError: (err) => {
1114
1117
  }
1115
1118
  });
1116
- usePositionUpdateStream((positions2) => {
1117
- console.log("position message", positions2);
1118
- updatePositions();
1119
- });
1120
1119
  const { data: markPrices } = useMarkPricesStream();
1121
1120
  const formatedPositions = React.useMemo(() => {
1122
1121
  if (!data?.rows || !symbolInfo || !accountInfo)
@@ -1265,41 +1264,6 @@ var pathOr_unsettledPnLPathOr = ramda.pathOr(0, [
1265
1264
  "aggregated",
1266
1265
  "unsettledPnL"
1267
1266
  ]);
1268
- var usePositionUpdateStream = (callback) => {
1269
- const ws = useWS();
1270
- const positionList = React.useRef({});
1271
- return useSWRSubscription__default.default("positionUpdate", (key, { next }) => {
1272
- const unsubscribe = ws.privateSubscribe(
1273
- // { event: "subscribe", topic: "markprices" },
1274
- "position",
1275
- {
1276
- onMessage: (message) => {
1277
- const { positions: positions2 } = message;
1278
- let update = false;
1279
- for (const p in positions2) {
1280
- const { symbol, positionQty } = positions2[p];
1281
- if (positionList.current[symbol] !== positionQty) {
1282
- update = true;
1283
- positionList.current[symbol] = positionQty;
1284
- }
1285
- }
1286
- if (update) {
1287
- callback(positions2.current);
1288
- }
1289
- next(null, positionList);
1290
- },
1291
- // onUnsubscribe: () => {
1292
- // return "markprices";
1293
- // },
1294
- onError: (error) => {
1295
- }
1296
- }
1297
- );
1298
- return () => {
1299
- unsubscribe?.();
1300
- };
1301
- });
1302
- };
1303
1267
  var useHoldingStream = () => {
1304
1268
  const ws = useWS();
1305
1269
  const { data, isLoading, mutate: mutate2 } = usePrivateQuery(
@@ -1314,7 +1278,7 @@ var useHoldingStream = () => {
1314
1278
  const usdc2 = data?.find((item) => item.token === "USDC");
1315
1279
  return usdc2;
1316
1280
  }, [data]);
1317
- useSWRSubscription__default.default("holding", (_, { next }) => {
1281
+ const { data: balance } = useSWRSubscription__default.default("holding", (_, { next }) => {
1318
1282
  const unsubscribe = ws.privateSubscribe(
1319
1283
  {
1320
1284
  id: "balance",
@@ -1346,6 +1310,7 @@ var useHoldingStream = () => {
1346
1310
  return {
1347
1311
  data,
1348
1312
  usdc,
1313
+ balance,
1349
1314
  isLoading
1350
1315
  };
1351
1316
  };
@@ -1576,37 +1541,11 @@ var useCollateral = (options = { dp: 6 }) => {
1576
1541
  var positionsPath2 = ramda.pathOr([], [0, "rows"]);
1577
1542
  var useMaxQty = (symbol, side, reduceOnly = false) => {
1578
1543
  const positionsData = usePositionStream();
1544
+ const [orders] = useOrderStream({ status: types.OrderStatus.NEW });
1579
1545
  const { data: accountInfo } = usePrivateQuery("/v1/client/info");
1580
1546
  const symbolInfo = useSymbolsInfo();
1581
1547
  const { totalCollateral } = useCollateral();
1582
1548
  const { data: markPrices } = useMarkPricesStream();
1583
- const {
1584
- data: orders,
1585
- error,
1586
- mutate: updateOrder
1587
- } = usePrivateQuery(`/v1/orders?status=NEW&size=99`, {
1588
- formatter: (data) => data.rows,
1589
- onError: (err) => {
1590
- }
1591
- });
1592
- const ws = useWS();
1593
- React.useEffect(() => {
1594
- const unsubscribe = ws.privateSubscribe(
1595
- {
1596
- id: "executionreport_orders",
1597
- event: "subscribe",
1598
- topic: "executionreport",
1599
- ts: Date.now()
1600
- },
1601
- {
1602
- onMessage: (data) => {
1603
- console.log("refresh orders", data);
1604
- updateOrder();
1605
- }
1606
- }
1607
- );
1608
- return () => unsubscribe();
1609
- }, []);
1610
1549
  const maxQty = React.useMemo(() => {
1611
1550
  if (!symbol)
1612
1551
  return 0;
@@ -3571,6 +3510,17 @@ var usePrivateDataObserver = () => {
3571
3510
  const ws = useWS();
3572
3511
  const { mutate: mutate2 } = useSWR.useSWRConfig();
3573
3512
  const { state } = useAccount();
3513
+ React.useEffect(() => {
3514
+ console.log("----!!!usePrivateDataObserver!!!----");
3515
+ }, []);
3516
+ React.useEffect(() => {
3517
+ const unsubscribe = ws.privateSubscribe("executionreport", {
3518
+ onMessage: (data) => {
3519
+ console.log(data);
3520
+ }
3521
+ });
3522
+ return () => unsubscribe?.();
3523
+ }, [state.accountId]);
3574
3524
  React.useEffect(() => {
3575
3525
  if (!state.accountId)
3576
3526
  return;
@@ -3578,6 +3528,7 @@ var usePrivateDataObserver = () => {
3578
3528
  const unsubscribe = ws.privateSubscribe("position", {
3579
3529
  onMessage: (data) => {
3580
3530
  const { positions: nextPostions } = data;
3531
+ console.log("ws-----data-----", data);
3581
3532
  mutate2(key, (prevPositions) => {
3582
3533
  if (!!prevPositions) {
3583
3534
  return {
@@ -4265,6 +4216,7 @@ exports.useMutation = useMutation;
4265
4216
  exports.useOrderEntry = useOrderEntry;
4266
4217
  exports.useOrderStream = useOrderStream;
4267
4218
  exports.useOrderbookStream = useOrderbookStream;
4219
+ exports.useOrderlyContext = useOrderlyContext;
4268
4220
  exports.usePositionStream = usePositionStream;
4269
4221
  exports.usePreLoadData = usePreLoadData;
4270
4222
  exports.usePrivateDataObserver = usePrivateDataObserver;