@orderly.network/hooks 2.12.4 → 3.0.0-alpha.0

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
@@ -170,7 +170,7 @@ declare global {
170
170
  };
171
171
  }
172
172
  }
173
- declare const _default: "2.12.4";
173
+ declare const _default: "3.0.0-alpha.0";
174
174
 
175
175
  declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
176
176
  type useQueryOptions<T> = SWRConfiguration & {
@@ -180,7 +180,7 @@ declare const noCacheConfig: SWRConfiguration;
180
180
 
181
181
  /**
182
182
  * useQuery
183
- * @description for public api
183
+ * @description for public api. Injects X-Orderly-Plugin-Id when inside PluginScopeProvider.
184
184
  * @param query
185
185
  * @param options
186
186
  */
@@ -2887,6 +2887,10 @@ type OrderEntryReturn = {
2887
2887
  resetMetaState: () => void;
2888
2888
  formattedOrder: Partial<FullOrderState>;
2889
2889
  maxQty: number;
2890
+ maxQtys: {
2891
+ maxBuy: number;
2892
+ maxSell: number;
2893
+ };
2890
2894
  /**
2891
2895
  * The estimated liquidation price.
2892
2896
  */
package/dist/index.d.ts CHANGED
@@ -170,7 +170,7 @@ declare global {
170
170
  };
171
171
  }
172
172
  }
173
- declare const _default: "2.12.4";
173
+ declare const _default: "3.0.0-alpha.0";
174
174
 
175
175
  declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
176
176
  type useQueryOptions<T> = SWRConfiguration & {
@@ -180,7 +180,7 @@ declare const noCacheConfig: SWRConfiguration;
180
180
 
181
181
  /**
182
182
  * useQuery
183
- * @description for public api
183
+ * @description for public api. Injects X-Orderly-Plugin-Id when inside PluginScopeProvider.
184
184
  * @param query
185
185
  * @param options
186
186
  */
@@ -2887,6 +2887,10 @@ type OrderEntryReturn = {
2887
2887
  resetMetaState: () => void;
2888
2888
  formattedOrder: Partial<FullOrderState>;
2889
2889
  maxQty: number;
2890
+ maxQtys: {
2891
+ maxBuy: number;
2892
+ maxSell: number;
2893
+ };
2890
2894
  /**
2891
2895
  * The estimated liquidation price.
2892
2896
  */
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  var React = require('react');
4
4
  var net = require('@orderly.network/net');
5
5
  var useSWR5 = require('swr');
6
+ var pluginCore = require('@orderly.network/plugin-core');
6
7
  var types = require('@orderly.network/types');
7
8
  var utils = require('@orderly.network/utils');
8
9
  var useSWRMutation = require('swr/mutation');
@@ -75,9 +76,9 @@ function useMarketCategoriesConfig() {
75
76
  // src/version.ts
76
77
  if (typeof window !== "undefined") {
77
78
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
78
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.12.4";
79
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "3.0.0-alpha.0";
79
80
  }
80
- var version_default = "2.12.4";
81
+ var version_default = "3.0.0-alpha.0";
81
82
  var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
82
83
  var noCacheConfig = {
83
84
  dedupingInterval: 0,
@@ -110,19 +111,26 @@ function useConfig(key, defaultValue) {
110
111
  }
111
112
 
112
113
  // src/useQuery.ts
114
+ var PLUGIN_ID_HEADER = "X-Orderly-Plugin-Id";
113
115
  var useQuery = (query, options) => {
114
116
  const apiBaseUrl = useConfig("apiBaseUrl");
117
+ const pluginScope = pluginCore.usePluginScope();
115
118
  const { formatter, ...swrOptions } = options || {};
116
119
  if (typeof apiBaseUrl === "undefined") {
117
120
  throw new types.SDKError("please add OrderlyConfigProvider to your app");
118
121
  }
119
- return useSWR5__namespace.default(
120
- query,
121
- (url, init2) => fetcher(url.startsWith("http") ? url : `${apiBaseUrl}${url}`, init2, {
122
- formatter
123
- }),
124
- swrOptions
122
+ const fetcherFn = React.useCallback(
123
+ (url, init2) => {
124
+ const fullUrl = url.startsWith("http") ? url : `${apiBaseUrl}${url}`;
125
+ const headers = new Headers(init2?.headers);
126
+ if (pluginScope?.pluginId) {
127
+ headers.set(PLUGIN_ID_HEADER, pluginScope.pluginId);
128
+ }
129
+ return fetcher(fullUrl, { ...init2, headers }, { formatter });
130
+ },
131
+ [apiBaseUrl, pluginScope?.pluginId, formatter]
125
132
  );
133
+ return useSWR5__namespace.default(query, fetcherFn, swrOptions);
126
134
  };
127
135
  var timestampOffsetPromise = null;
128
136
  var timestampOffsetReady = false;
@@ -19047,12 +19055,37 @@ var useOrderEntry2 = (symbol, options = {}) => {
19047
19055
  );
19048
19056
  const bestAskBid = askAndBid.current?.[0] || [];
19049
19057
  const referencePriceFromOrder = bestAskBid.length >= 2 && formattedOrder.order_type && formattedOrder.side ? getOrderReferencePriceFromOrder(formattedOrder, bestAskBid) : null;
19050
- const maxQtyValue = useMaxQty(symbol, formattedOrder.side, {
19058
+ const maxBuyQtyValue = useMaxQty(symbol, types.OrderSide.BUY, {
19051
19059
  reduceOnly: formattedOrder.reduce_only,
19052
19060
  marginMode: effectiveMarginMode,
19053
19061
  currentOrderReferencePrice: referencePriceFromOrder && referencePriceFromOrder > 0 ? referencePriceFromOrder : void 0
19054
19062
  });
19063
+ const maxSellQtyValue = useMaxQty(symbol, types.OrderSide.SELL, {
19064
+ reduceOnly: formattedOrder.reduce_only,
19065
+ marginMode: effectiveMarginMode,
19066
+ currentOrderReferencePrice: referencePriceFromOrder && referencePriceFromOrder > 0 ? referencePriceFromOrder : void 0
19067
+ });
19068
+ const maxQtyValue = formattedOrder.side === types.OrderSide.BUY ? maxBuyQtyValue : maxSellQtyValue;
19055
19069
  const maxQty = options.maxQty ?? maxQtyValue;
19070
+ const maxQtys = React.useMemo(
19071
+ () => ({
19072
+ maxBuy: formattedOrder.side === types.OrderSide.BUY ? (
19073
+ // @ts-ignore
19074
+ options.maxQty ?? maxBuyQtyValue
19075
+ ) : maxBuyQtyValue,
19076
+ maxSell: formattedOrder.side === types.OrderSide.SELL ? (
19077
+ // @ts-ignore
19078
+ options.maxQty ?? maxSellQtyValue
19079
+ ) : maxSellQtyValue
19080
+ }),
19081
+ [
19082
+ formattedOrder.side,
19083
+ maxBuyQtyValue,
19084
+ maxSellQtyValue,
19085
+ // @ts-ignore
19086
+ options.maxQty
19087
+ ]
19088
+ );
19056
19089
  const updateOrderPrice = () => {
19057
19090
  const order_type = formattedOrder.order_type;
19058
19091
  const order_type_ext = formattedOrder.order_type_ext ?? lastOrderTypeExt.current;
@@ -19442,6 +19475,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
19442
19475
  resetMetaState,
19443
19476
  formattedOrder,
19444
19477
  maxQty,
19478
+ maxQtys,
19445
19479
  estLiqPrice,
19446
19480
  estLiqPriceDistance,
19447
19481
  currentPosition,