@orderly.network/hooks 2.0.3 → 2.0.4

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.mjs CHANGED
@@ -7,13 +7,13 @@ import useConstant from 'use-constant';
7
7
  export { default as useConstant } from 'use-constant';
8
8
  import { SimpleDI, Account, EventEmitter, EVENT_NAMES, DefaultConfigStore, LocalStorageStore } from '@orderly.network/core';
9
9
  import { zero, getGlobalObject, getTimestamp, Decimal, timeConvertString, isTestnet, getPrecisionByNumber, camelCaseToUnderscoreCase, windowGuard, removeTrailingZeros, commify, todpIfNeed } from '@orderly.network/utils';
10
- import { OrderSide, OrderType, EnumTrackerKeys, AccountStatusEnum, SDKError, OrderStatus, AlgoOrderRootType, nativeTokenAddress, chainsInfoMap, ARBITRUM_TESTNET_CHAINID, ARBITRUM_MAINNET_CHAINID, isNativeTokenChecker, ChainNamespace, MaxUint256, DEPOSIT_FEE_RATE, TrackerListenerKeyMap, AlgoOrderType, TriggerPriceType } from '@orderly.network/types';
10
+ import { OrderType, OrderSide, EnumTrackerKeys, AccountStatusEnum, SDKError, AlgoOrderRootType, OrderStatus, nativeTokenAddress, chainsInfoMap, ARBITRUM_TESTNET_CHAINID, ARBITRUM_MAINNET_CHAINID, isNativeTokenChecker, ChainNamespace, MaxUint256, DEPOSIT_FEE_RATE, LedgerWalletKey, TrackerListenerKeyMap, AlgoOrderType, TriggerPriceType } from '@orderly.network/types';
11
11
  import useSWRInfinite, { unstable_serialize } from 'swr/infinite';
12
12
  import { jsx } from 'react/jsx-runtime';
13
- import { pathOr, prop, omit, pick, compose, head, mergeDeepRight, min, max, propOr, isNil, path, lensIndex, over } from 'ramda';
13
+ import { pathOr, prop, omit, pick, compose, head, mergeDeepRight, min, max, isNil, propOr, path, lensIndex, over } from 'ramda';
14
14
  import { create } from 'zustand';
15
15
  import { immer } from 'zustand/middleware/immer';
16
- import { account, order, positions } from '@orderly.network/perp';
16
+ import { order, account, positions } from '@orderly.network/perp';
17
17
  import useSWRSubscription from 'swr/subscription';
18
18
  import { useDebouncedCallback, useThrottledCallback } from 'use-debounce';
19
19
  export * from 'use-debounce';
@@ -33,9 +33,9 @@ var __export = (target, all) => {
33
33
  // src/version.ts
34
34
  if (typeof window !== "undefined") {
35
35
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
36
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.0.3";
36
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.0.4";
37
37
  }
38
- var version_default = "2.0.3";
38
+ var version_default = "2.0.4";
39
39
  var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
40
40
  var OrderlyContext = createContext({
41
41
  // configStore: new MemoryConfigStore(),
@@ -2162,7 +2162,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
2162
2162
  }
2163
2163
  const level = options?.level ?? 10;
2164
2164
  const padding = options?.padding ?? true;
2165
- useState(null);
2165
+ const [requestData, setRequestData] = useState(null);
2166
2166
  const [data, setData] = useState(initial);
2167
2167
  const [isLoading, setIsLoading] = useState(true);
2168
2168
  const config = useSymbolsInfo()[symbol];
@@ -3038,7 +3038,10 @@ var useFundingRate = (symbol) => {
3038
3038
  if (getTimestamp() > next_funding_time) {
3039
3039
  return null;
3040
3040
  }
3041
- return new Decimal(Number(est_funding_rate2) * 100).toFixed(4, Decimal.ROUND_DOWN);
3041
+ return new Decimal(Number(est_funding_rate2) * 100).toFixed(
3042
+ 4,
3043
+ Decimal.ROUND_DOWN
3044
+ );
3042
3045
  }, [data]);
3043
3046
  return {
3044
3047
  ...data,
@@ -3712,7 +3715,7 @@ var useMarginRatio = () => {
3712
3715
  }, [rows, notional]);
3713
3716
  return { marginRatio, currentLeverage, mmr };
3714
3717
  };
3715
- var TestNetWhiteList = [421614, 901901901, 1516];
3718
+ var TestNetWhiteList = [421614, 901901901];
3716
3719
  function useChains(networkId, options = {}) {
3717
3720
  const { pick: pickField, ...swrOptions } = options;
3718
3721
  const {
@@ -4001,7 +4004,7 @@ var useWithdraw = (options) => {
4001
4004
  const networkId = useConfig("networkId");
4002
4005
  const [_, { findByChainId }] = useChains(void 0);
4003
4006
  const ee = useEventEmitter();
4004
- useHoldingStream();
4007
+ const { usdc } = useHoldingStream();
4005
4008
  const maxAmount = useMemo(() => {
4006
4009
  return freeCollateral;
4007
4010
  }, [freeCollateral]);
@@ -4433,7 +4436,7 @@ var useSymbolPriceRange = (symbol, side, price) => {
4433
4436
  return range;
4434
4437
  };
4435
4438
  function offsetToPrice(inputs) {
4436
- const { qty, offset, entryPrice, orderType, orderSide } = inputs;
4439
+ const { offset, entryPrice, orderType, orderSide } = inputs;
4437
4440
  if (!offset)
4438
4441
  return;
4439
4442
  if (orderSide === OrderSide.BUY) {
@@ -4450,7 +4453,7 @@ function offsetToPrice(inputs) {
4450
4453
  }
4451
4454
  }
4452
4455
  function priceToOffset(inputs, options = {}) {
4453
- const { qty, price, entryPrice, orderType, orderSide } = inputs;
4456
+ const { price, entryPrice, orderType, orderSide } = inputs;
4454
4457
  const { symbol } = options;
4455
4458
  let decimal;
4456
4459
  if (orderSide === OrderSide.BUY) {
@@ -4471,7 +4474,7 @@ function priceToOffset(inputs, options = {}) {
4471
4474
  return decimal.abs().toNumber();
4472
4475
  }
4473
4476
  function offsetPercentageToPrice(inputs) {
4474
- const { qty, percentage, entryPrice, orderType, orderSide } = inputs;
4477
+ const { percentage, entryPrice, orderType, orderSide } = inputs;
4475
4478
  if (!percentage)
4476
4479
  return;
4477
4480
  if (orderSide === OrderSide.BUY) {
@@ -4488,7 +4491,7 @@ function offsetPercentageToPrice(inputs) {
4488
4491
  }
4489
4492
  }
4490
4493
  function priceToOffsetPercentage(inputs) {
4491
- const { qty, price, entryPrice, orderType, orderSide } = inputs;
4494
+ const { price, entryPrice, orderType, orderSide } = inputs;
4492
4495
  if (orderSide === OrderSide.BUY) {
4493
4496
  if (entryPrice === 0)
4494
4497
  return 0;
@@ -4614,7 +4617,6 @@ function tpslCalculateHelper(key, inputs, options = {}) {
4614
4617
  case "sl_offset": {
4615
4618
  offset = inputs.value;
4616
4619
  trigger_price = offsetToPrice({
4617
- qty,
4618
4620
  offset: Number(inputs.value),
4619
4621
  entryPrice,
4620
4622
  orderSide: inputs.orderSide,
@@ -4626,7 +4628,6 @@ function tpslCalculateHelper(key, inputs, options = {}) {
4626
4628
  case "sl_offset_percentage": {
4627
4629
  offset_percentage = inputs.value;
4628
4630
  trigger_price = offsetPercentageToPrice({
4629
- qty,
4630
4631
  percentage: Number(`${inputs.value}`.replace(/\.0{0,2}$/, "")),
4631
4632
  entryPrice,
4632
4633
  orderSide: inputs.orderSide,
@@ -4651,7 +4652,6 @@ function tpslCalculateHelper(key, inputs, options = {}) {
4651
4652
  ),
4652
4653
  [`${keyPrefix}offset`]: offset ?? priceToOffset(
4653
4654
  {
4654
- qty,
4655
4655
  price: Number(trigger_price),
4656
4656
  entryPrice,
4657
4657
  orderSide: inputs.orderSide,
@@ -4660,7 +4660,6 @@ function tpslCalculateHelper(key, inputs, options = {}) {
4660
4660
  options
4661
4661
  ),
4662
4662
  [`${keyPrefix}offset_percentage`]: offset_percentage ?? priceToOffsetPercentage({
4663
- qty,
4664
4663
  price: Number(trigger_price),
4665
4664
  entryPrice,
4666
4665
  orderSide: inputs.orderSide,
@@ -5691,7 +5690,6 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
5691
5690
  const newValue = tpslCalculateHelper(
5692
5691
  key,
5693
5692
  {
5694
- key,
5695
5693
  value,
5696
5694
  entryPrice: position.average_open_price,
5697
5695
  qty: side === OrderSide.BUY ? Number(prev.quantity) : -Number(prev.quantity),
@@ -6146,6 +6144,19 @@ function useMaintenanceStatus() {
6146
6144
  endTime
6147
6145
  };
6148
6146
  }
6147
+ var useStorageLedgerAddress = () => {
6148
+ const [ledgerWallet, setLedgerWallet] = useLocalStorage(LedgerWalletKey, []);
6149
+ const setLedgerAddress = (address) => {
6150
+ if (!ledgerWallet.includes(address)) {
6151
+ const arr = [...ledgerWallet, address];
6152
+ setLedgerWallet(arr);
6153
+ }
6154
+ };
6155
+ return {
6156
+ setLedgerAddress,
6157
+ ledgerWallet
6158
+ };
6159
+ };
6149
6160
  var usePrivateDataObserver = (options) => {
6150
6161
  const ws = useWS();
6151
6162
  const ee = useEventEmitter();
@@ -6291,34 +6302,37 @@ var usePrivateDataObserver = (options) => {
6291
6302
  const key = ["/v1/positions", state.accountId];
6292
6303
  const unsubscribe = ws.privateSubscribe("position", {
6293
6304
  onMessage: (data) => {
6294
- const { positions: nextPostions } = data;
6305
+ const { positions: nextPositions } = data;
6295
6306
  mutate(
6296
6307
  key,
6297
6308
  (prevPositions) => {
6298
6309
  if (!!prevPositions) {
6299
- const newPostions = {
6310
+ const newPositions = {
6300
6311
  ...prevPositions,
6301
6312
  rows: prevPositions.rows.map((row) => {
6302
- const itemIndex = nextPostions.findIndex(
6313
+ const itemIndex = nextPositions.findIndex(
6303
6314
  (item) => item.symbol === row.symbol
6304
6315
  );
6305
6316
  if (itemIndex >= 0) {
6306
- const itemArr = nextPostions.splice(itemIndex, 1);
6317
+ const itemArr = nextPositions.splice(itemIndex, 1);
6307
6318
  const item = itemArr[0];
6319
+ if (item.averageOpenPrice === 0) {
6320
+ return row;
6321
+ }
6308
6322
  return object2underscore(item);
6309
6323
  }
6310
6324
  return row;
6311
6325
  })
6312
6326
  };
6313
- if (nextPostions.length > 0) {
6314
- newPostions.rows = [
6315
- ...newPostions.rows,
6316
- ...nextPostions.map((item) => {
6327
+ if (nextPositions.length > 0) {
6328
+ newPositions.rows = [
6329
+ ...newPositions.rows,
6330
+ ...nextPositions.map((item) => {
6317
6331
  return object2underscore(item);
6318
6332
  })
6319
6333
  ];
6320
6334
  }
6321
- return newPostions;
6335
+ return newPositions;
6322
6336
  }
6323
6337
  },
6324
6338
  {
@@ -6908,7 +6922,6 @@ function tpslInputHandle(inputs) {
6908
6922
  const _tpslValue = tpslCalculateHelper(
6909
6923
  input,
6910
6924
  {
6911
- key: input,
6912
6925
  value,
6913
6926
  entryPrice: price,
6914
6927
  // order price or mark price
@@ -7568,7 +7581,7 @@ var qrPaint = (ctx, options) => {
7568
7581
  var DataPaint = class extends BasePaint {
7569
7582
  constructor() {
7570
7583
  super(...arguments);
7571
- this.positionInfoCellWidth = 110;
7584
+ this.positionInfoCellWidth = 90;
7572
7585
  this.DEFAULT_PROFIT_COLOR = "rgb(0,181,159)";
7573
7586
  this.DEFAULT_LOSS_COLOR = "rgb(255,103,194)";
7574
7587
  this.transformTop = 0;
@@ -7736,10 +7749,12 @@ var DataPaint = class extends BasePaint {
7736
7749
  options
7737
7750
  );
7738
7751
  const { position } = layout;
7752
+ const informations = options.data?.position?.informations || [];
7739
7753
  (options.data?.position.informations.length ?? 0) === 2;
7740
- options.data?.position.informations.forEach((info, index) => {
7741
- let left = position.left + index % 2 * this.positionInfoCellWidth;
7742
- let top = position.top + Math.floor(index / 2) * 38 + this.transformTop;
7754
+ const col = informations.length > 4 ? 3 : 2;
7755
+ informations.forEach((info, index) => {
7756
+ let left = position.left + index % col * this.positionInfoCellWidth;
7757
+ let top = position.top + Math.floor(index / col) * 38 + this.transformTop;
7743
7758
  this._drawText(info.title, {
7744
7759
  left: this._ratio(left),
7745
7760
  top: this._ratio(top),
@@ -14540,6 +14555,6 @@ var useRestrictedAreas = (params) => {
14540
14555
  };
14541
14556
  };
14542
14557
 
14543
- export { AssetHistoryStatusEnum, DefaultLayoutConfig, DistributionId, ENVType2 as ENVType, ExtendedConfigStore, MarketsStorageKey, MarketsType, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, OrderlyTrackerProvider, StatusContext, StatusProvider, TWType, WalletConnectorContext, WsNetworkStatus, checkNotional, cleanStringStyle, parseJSON, useAccount, useAccountInfo2 as useAccountInfo, useAccountInstance, useAccountRewardsHistory, useAllBrokers, useApiKeyManager, useAssetsHistory, useBoolean, useChain, useChains, useCheckReferralCode, useCollateral, useCommission, useConfig, useCurEpochEstimate, useDaily, useDeposit, useDistribution, useDistributionHistory, useEpochInfo, useEventEmitter, useFundingFeeHistory, useFundingRate, useFundingRateHistory, useFundingRates, useGetClaimed, useGetEnv, useGetReferralCode, useHoldingStream, useIndexPrice, useKeyStore, useLazyQuery, useLeverage, useLocalStorage, useMaintenanceStatus, useMarginRatio, useMarkPrice, useMarkPriceBySymbol, useMarkPricesStream, useMarket, useMarketTradeStream, useMarkets, useMarketsStore, useMarketsStream, useMaxQty, useMediaQuery, useMutation, useNetworkInfo, useOrderEntity, useOrderEntry2 as useOrderEntry, useOrderEntry as useOrderEntry_deprecated, useOrderStore2 as useOrderStore, useOrderStream, useOrderbookStream, usePositionActions, usePositionStream, usePoster, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useRefereeHistory, useRefereeInfo, useRefereeRebateSummary, useReferralInfo, useReferralRebateSummary, useRestrictedAreas, useSessionStorage, useSettleSubscription, useSimpleDI, useStatisticsDaily, useSymbolLeverage, useSymbolPriceRange, useSymbolsInfo, useTPSLOrder, useTickerStream, useWS, useWalletConnector, useWalletRewardsHistory, useWalletSubscription, useWithdraw, useWsStatus, utils_exports as utils, version_default as version };
14558
+ export { AssetHistoryStatusEnum, DefaultLayoutConfig, DistributionId, ENVType2 as ENVType, ExtendedConfigStore, MarketsStorageKey, MarketsType, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, OrderlyTrackerProvider, StatusContext, StatusProvider, TWType, WalletConnectorContext, WsNetworkStatus, checkNotional, cleanStringStyle, parseJSON, useAccount, useAccountInfo2 as useAccountInfo, useAccountInstance, useAccountRewardsHistory, useAllBrokers, useApiKeyManager, useAssetsHistory, useBoolean, useChain, useChains, useCheckReferralCode, useCollateral, useCommission, useConfig, useCurEpochEstimate, useDaily, useDeposit, useDistribution, useDistributionHistory, useEpochInfo, useEventEmitter, useFundingFeeHistory, useFundingRate, useFundingRateHistory, useFundingRates, useGetClaimed, useGetEnv, useGetReferralCode, useHoldingStream, useIndexPrice, useKeyStore, useLazyQuery, useLeverage, useLocalStorage, useMaintenanceStatus, useMarginRatio, useMarkPrice, useMarkPriceBySymbol, useMarkPricesStream, useMarket, useMarketTradeStream, useMarkets, useMarketsStore, useMarketsStream, useMaxQty, useMediaQuery, useMutation, useNetworkInfo, useOrderEntity, useOrderEntry2 as useOrderEntry, useOrderEntry as useOrderEntry_deprecated, useOrderStore2 as useOrderStore, useOrderStream, useOrderbookStream, usePositionActions, usePositionStream, usePoster, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useRefereeHistory, useRefereeInfo, useRefereeRebateSummary, useReferralInfo, useReferralRebateSummary, useRestrictedAreas, useSessionStorage, useSettleSubscription, useSimpleDI, useStatisticsDaily, useStorageLedgerAddress, useSymbolLeverage, useSymbolPriceRange, useSymbolsInfo, useTPSLOrder, useTickerStream, useWS, useWalletConnector, useWalletRewardsHistory, useWalletSubscription, useWithdraw, useWsStatus, utils_exports as utils, version_default as version };
14544
14559
  //# sourceMappingURL=out.js.map
14545
14560
  //# sourceMappingURL=index.mjs.map