@orderly.network/hooks 0.0.19 → 0.0.21

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
@@ -1,10 +1,10 @@
1
1
  import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
2
2
  export { SWRConfiguration, default as useSWR } from 'swr';
3
3
  import { SWRMutationConfiguration } from 'swr/mutation';
4
- import { Account, AccountState, EventEmitter, ConfigStore, OrderlyKeyStore, WalletAdapter, WSMessage } from '@orderly.network/core';
5
- export { default as useConstant } from 'use-constant';
4
+ import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, EventEmitter, WSMessage } from '@orderly.network/core';
6
5
  import * as react from 'react';
7
- import { FC, PropsWithChildren } from 'react';
6
+ import react__default, { FC, PropsWithChildren } from 'react';
7
+ export { default as useConstant } from 'use-constant';
8
8
  import { WS } from '@orderly.network/net';
9
9
  import { OrderSide, OrderEntity, API } from '@orderly.network/types';
10
10
  import * as swr__internal from 'swr/_internal';
@@ -51,20 +51,20 @@ declare const useAccount: () => {
51
51
  createAccount: () => Promise<string>;
52
52
  disconnect: () => Promise<void>;
53
53
  connect: () => Promise<any>;
54
+ setChain: (chainId: number) => Promise<any>;
54
55
  };
55
56
 
56
- declare const useAppState: () => {};
57
-
58
- declare const useEventEmitter: (channel?: string) => EventEmitter<string | symbol, any>;
59
-
60
- declare const DataSourceProvider: FC<PropsWithChildren>;
61
-
62
- declare const useWS: () => WS;
57
+ declare const useAccountInstance: () => Account;
63
58
 
64
59
  interface OrderlyAppConfig {
65
60
  logoUrl: string;
66
61
  theme: any;
67
62
  }
63
+ type AppStateErrors = {
64
+ ChainNetworkNotSupport: boolean;
65
+ IpNotSupport: boolean;
66
+ NetworkError: boolean;
67
+ };
68
68
  interface OrderlyContextState extends OrderlyAppConfig {
69
69
  fetcher?: (url: string, init: RequestInit) => Promise<any>;
70
70
  apiBaseUrl: string;
@@ -77,11 +77,35 @@ interface OrderlyContextState extends OrderlyAppConfig {
77
77
  networkId: string;
78
78
  onWalletConnect?: () => Promise<any>;
79
79
  onWalletDisconnect?: () => Promise<any>;
80
+ onSetChain?: (chainId: number) => Promise<any>;
80
81
  ready: boolean;
82
+ onAppTestChange?: (name: string) => void;
83
+ errors: AppStateErrors;
81
84
  }
82
85
  declare const OrderlyContext: react.Context<OrderlyContextState>;
83
86
  declare const OrderlyProvider: react.Provider<OrderlyContextState>;
84
87
 
88
+ declare const useAppState: () => {
89
+ errors: AppStateErrors;
90
+ ready: boolean;
91
+ };
92
+
93
+ declare const usePreLoadData: (onSuccess: (name: string) => void) => void;
94
+
95
+ declare const useEventEmitter: (channel?: string) => EventEmitter<string | symbol, any>;
96
+
97
+ declare function useSessionStorage<T>(key: string, initialValue: T): [T, (data: any) => void];
98
+
99
+ type useRunOnceProps = {
100
+ fn: () => any;
101
+ sessionKey?: string;
102
+ };
103
+ declare const useRunOnce: react__default.FC<useRunOnceProps>;
104
+
105
+ declare const DataSourceProvider: FC<PropsWithChildren>;
106
+
107
+ declare const useWS: () => WS;
108
+
85
109
  type OrderBookItem = number[];
86
110
  type OrderbookData = {
87
111
  asks: OrderBookItem[];
@@ -164,10 +188,10 @@ declare const useLeverage: () => ({
164
188
 
165
189
  declare const useTickerStream: (symbol: string) => any;
166
190
 
167
- declare const useFundingRate$1: (symbol: string) => {
191
+ declare const useFundingRate: (symbol: string) => {
192
+ est_funding_rate: string;
168
193
  countDown: string;
169
194
  symbol?: string | undefined;
170
- est_funding_rate?: number | undefined;
171
195
  est_funding_rate_timestamp?: number | undefined;
172
196
  last_funding_rate?: number | undefined;
173
197
  last_funding_rate_timestamp?: number | undefined;
@@ -184,16 +208,21 @@ declare enum OrderStatus {
184
208
  NEW = "NEW",
185
209
  COMPLETED = "COMPLETED"
186
210
  }
187
- declare const useOrderStream: ({ status, symbol, }?: {
211
+ declare const useOrderStream: ({ status, symbol, side, size, }?: {
188
212
  symbol?: string | undefined;
189
213
  status?: OrderStatus | undefined;
214
+ size?: number | undefined;
215
+ side?: OrderSide | undefined;
190
216
  }) => (any[] | {
191
217
  cancelAllOrders: () => void;
192
218
  updateOrder: (orderId: string, order: OrderEntity) => any;
193
219
  cancelOrder: (orderId: string, symbol?: string) => any;
194
220
  } | null)[];
195
221
 
196
- declare const useMarketTradeStream: (symbol: string) => {
222
+ interface MarketTradeStreamOptions {
223
+ level?: number;
224
+ }
225
+ declare const useMarketTradeStream: (symbol: string, options?: MarketTradeStreamOptions) => {
197
226
  data: API.Trade[] | undefined;
198
227
  isLoading: boolean;
199
228
  };
@@ -204,6 +233,7 @@ type CollateralOutputs = {
204
233
  totalCollateral: number;
205
234
  freeCollateral: number;
206
235
  totalValue: number;
236
+ availableBalance: number;
207
237
  };
208
238
  /**
209
239
  * 用户保证金
@@ -216,13 +246,19 @@ declare const useCollateral: (options?: Options) => CollateralOutputs;
216
246
 
217
247
  declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
218
248
 
219
- declare const useMarginRatio: () => number;
249
+ declare const useMarginRatio: () => number[];
220
250
 
221
251
  type inputOptions = {
222
252
  filter?: (item: API.Chain) => boolean;
223
253
  pick?: "dexs" | "network_infos" | "token_infos";
224
254
  };
225
- declare const useChains: (networkId?: "testnet" | "mainnet", options?: inputOptions) => any[];
255
+ declare const useChains: (networkId?: "testnet" | "mainnet", options?: inputOptions & SWRConfiguration) => any[];
256
+
257
+ declare const useHolding: () => {
258
+ data: API.Holding[] | undefined;
259
+ usdc: API.Holding | undefined;
260
+ isLoading: boolean;
261
+ };
226
262
 
227
263
  declare const useBalance: () => any;
228
264
 
@@ -276,23 +312,15 @@ interface FundingRate {
276
312
  */
277
313
  declare const useFundingRateBySymbol: (symbol: string) => swr__internal.SWRResponse<FundingRate, any, any>;
278
314
 
279
- /**
280
- * FundingRate
281
- * @param symbol
282
- */
283
- declare const useFundingRate: (symbol?: string) => swr__internal.SWRResponse<FundingRate, any, any>;
284
-
285
- declare const index_useFundingRate: typeof useFundingRate;
286
315
  declare const index_useFundingRateBySymbol: typeof useFundingRateBySymbol;
287
316
  declare const index_useInfo: typeof useInfo;
288
317
  declare const index_useToken: typeof useToken;
289
318
  declare namespace index {
290
319
  export {
291
- index_useFundingRate as useFundingRate,
292
320
  index_useFundingRateBySymbol as useFundingRateBySymbol,
293
321
  index_useInfo as useInfo,
294
322
  index_useToken as useToken,
295
323
  };
296
324
  }
297
325
 
298
- export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useBalance, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate$1 as useFundingRate, useLeverage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateDataObserver, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS };
326
+ export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHolding, useLeverage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateObserve, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
2
2
  export { SWRConfiguration, default as useSWR } from 'swr';
3
3
  import { SWRMutationConfiguration } from 'swr/mutation';
4
- import { Account, AccountState, EventEmitter, ConfigStore, OrderlyKeyStore, WalletAdapter, WSMessage } from '@orderly.network/core';
5
- export { default as useConstant } from 'use-constant';
4
+ import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, EventEmitter, WSMessage } from '@orderly.network/core';
6
5
  import * as react from 'react';
7
- import { FC, PropsWithChildren } from 'react';
6
+ import react__default, { FC, PropsWithChildren } from 'react';
7
+ export { default as useConstant } from 'use-constant';
8
8
  import { WS } from '@orderly.network/net';
9
9
  import { OrderSide, OrderEntity, API } from '@orderly.network/types';
10
10
  import * as swr__internal from 'swr/_internal';
@@ -51,20 +51,20 @@ declare const useAccount: () => {
51
51
  createAccount: () => Promise<string>;
52
52
  disconnect: () => Promise<void>;
53
53
  connect: () => Promise<any>;
54
+ setChain: (chainId: number) => Promise<any>;
54
55
  };
55
56
 
56
- declare const useAppState: () => {};
57
-
58
- declare const useEventEmitter: (channel?: string) => EventEmitter<string | symbol, any>;
59
-
60
- declare const DataSourceProvider: FC<PropsWithChildren>;
61
-
62
- declare const useWS: () => WS;
57
+ declare const useAccountInstance: () => Account;
63
58
 
64
59
  interface OrderlyAppConfig {
65
60
  logoUrl: string;
66
61
  theme: any;
67
62
  }
63
+ type AppStateErrors = {
64
+ ChainNetworkNotSupport: boolean;
65
+ IpNotSupport: boolean;
66
+ NetworkError: boolean;
67
+ };
68
68
  interface OrderlyContextState extends OrderlyAppConfig {
69
69
  fetcher?: (url: string, init: RequestInit) => Promise<any>;
70
70
  apiBaseUrl: string;
@@ -77,11 +77,35 @@ interface OrderlyContextState extends OrderlyAppConfig {
77
77
  networkId: string;
78
78
  onWalletConnect?: () => Promise<any>;
79
79
  onWalletDisconnect?: () => Promise<any>;
80
+ onSetChain?: (chainId: number) => Promise<any>;
80
81
  ready: boolean;
82
+ onAppTestChange?: (name: string) => void;
83
+ errors: AppStateErrors;
81
84
  }
82
85
  declare const OrderlyContext: react.Context<OrderlyContextState>;
83
86
  declare const OrderlyProvider: react.Provider<OrderlyContextState>;
84
87
 
88
+ declare const useAppState: () => {
89
+ errors: AppStateErrors;
90
+ ready: boolean;
91
+ };
92
+
93
+ declare const usePreLoadData: (onSuccess: (name: string) => void) => void;
94
+
95
+ declare const useEventEmitter: (channel?: string) => EventEmitter<string | symbol, any>;
96
+
97
+ declare function useSessionStorage<T>(key: string, initialValue: T): [T, (data: any) => void];
98
+
99
+ type useRunOnceProps = {
100
+ fn: () => any;
101
+ sessionKey?: string;
102
+ };
103
+ declare const useRunOnce: react__default.FC<useRunOnceProps>;
104
+
105
+ declare const DataSourceProvider: FC<PropsWithChildren>;
106
+
107
+ declare const useWS: () => WS;
108
+
85
109
  type OrderBookItem = number[];
86
110
  type OrderbookData = {
87
111
  asks: OrderBookItem[];
@@ -164,10 +188,10 @@ declare const useLeverage: () => ({
164
188
 
165
189
  declare const useTickerStream: (symbol: string) => any;
166
190
 
167
- declare const useFundingRate$1: (symbol: string) => {
191
+ declare const useFundingRate: (symbol: string) => {
192
+ est_funding_rate: string;
168
193
  countDown: string;
169
194
  symbol?: string | undefined;
170
- est_funding_rate?: number | undefined;
171
195
  est_funding_rate_timestamp?: number | undefined;
172
196
  last_funding_rate?: number | undefined;
173
197
  last_funding_rate_timestamp?: number | undefined;
@@ -184,16 +208,21 @@ declare enum OrderStatus {
184
208
  NEW = "NEW",
185
209
  COMPLETED = "COMPLETED"
186
210
  }
187
- declare const useOrderStream: ({ status, symbol, }?: {
211
+ declare const useOrderStream: ({ status, symbol, side, size, }?: {
188
212
  symbol?: string | undefined;
189
213
  status?: OrderStatus | undefined;
214
+ size?: number | undefined;
215
+ side?: OrderSide | undefined;
190
216
  }) => (any[] | {
191
217
  cancelAllOrders: () => void;
192
218
  updateOrder: (orderId: string, order: OrderEntity) => any;
193
219
  cancelOrder: (orderId: string, symbol?: string) => any;
194
220
  } | null)[];
195
221
 
196
- declare const useMarketTradeStream: (symbol: string) => {
222
+ interface MarketTradeStreamOptions {
223
+ level?: number;
224
+ }
225
+ declare const useMarketTradeStream: (symbol: string, options?: MarketTradeStreamOptions) => {
197
226
  data: API.Trade[] | undefined;
198
227
  isLoading: boolean;
199
228
  };
@@ -204,6 +233,7 @@ type CollateralOutputs = {
204
233
  totalCollateral: number;
205
234
  freeCollateral: number;
206
235
  totalValue: number;
236
+ availableBalance: number;
207
237
  };
208
238
  /**
209
239
  * 用户保证金
@@ -216,13 +246,19 @@ declare const useCollateral: (options?: Options) => CollateralOutputs;
216
246
 
217
247
  declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
218
248
 
219
- declare const useMarginRatio: () => number;
249
+ declare const useMarginRatio: () => number[];
220
250
 
221
251
  type inputOptions = {
222
252
  filter?: (item: API.Chain) => boolean;
223
253
  pick?: "dexs" | "network_infos" | "token_infos";
224
254
  };
225
- declare const useChains: (networkId?: "testnet" | "mainnet", options?: inputOptions) => any[];
255
+ declare const useChains: (networkId?: "testnet" | "mainnet", options?: inputOptions & SWRConfiguration) => any[];
256
+
257
+ declare const useHolding: () => {
258
+ data: API.Holding[] | undefined;
259
+ usdc: API.Holding | undefined;
260
+ isLoading: boolean;
261
+ };
226
262
 
227
263
  declare const useBalance: () => any;
228
264
 
@@ -276,23 +312,15 @@ interface FundingRate {
276
312
  */
277
313
  declare const useFundingRateBySymbol: (symbol: string) => swr__internal.SWRResponse<FundingRate, any, any>;
278
314
 
279
- /**
280
- * FundingRate
281
- * @param symbol
282
- */
283
- declare const useFundingRate: (symbol?: string) => swr__internal.SWRResponse<FundingRate, any, any>;
284
-
285
- declare const index_useFundingRate: typeof useFundingRate;
286
315
  declare const index_useFundingRateBySymbol: typeof useFundingRateBySymbol;
287
316
  declare const index_useInfo: typeof useInfo;
288
317
  declare const index_useToken: typeof useToken;
289
318
  declare namespace index {
290
319
  export {
291
- index_useFundingRate as useFundingRate,
292
320
  index_useFundingRateBySymbol as useFundingRateBySymbol,
293
321
  index_useInfo as useInfo,
294
322
  index_useToken as useToken,
295
323
  };
296
324
  }
297
325
 
298
- export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useBalance, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate$1 as useFundingRate, useLeverage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateDataObserver, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS };
326
+ export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHolding, useLeverage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateObserve, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS };