@orderly.network/hooks 2.8.3 → 2.8.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
@@ -38,9 +38,9 @@ var __export = (target, all) => {
38
38
  // src/version.ts
39
39
  if (typeof window !== "undefined") {
40
40
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
41
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.3";
41
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.4";
42
42
  }
43
- var version_default = "2.8.3";
43
+ var version_default = "2.8.4";
44
44
  var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
45
45
  var noCacheConfig = {
46
46
  dedupingInterval: 0,
@@ -2510,8 +2510,10 @@ var adaptToStateStorage = (indexedDBStorage) => ({
2510
2510
  try {
2511
2511
  const parsed = JSON.parse(value);
2512
2512
  const stateData = pathOr$1([], ["state"], parsed);
2513
- if (Array.isArray(stateData) && stateData.length > 0) {
2513
+ if (Array.isArray(stateData)) {
2514
2514
  await indexedDBStorage.setItem(stateData);
2515
+ } else if (stateData === null) {
2516
+ await indexedDBStorage.removeItem();
2515
2517
  }
2516
2518
  } catch (error) {
2517
2519
  }
@@ -2550,33 +2552,37 @@ var createDataStore = (config) => {
2550
2552
  } = config;
2551
2553
  return create(
2552
2554
  persistIndexedDB(
2553
- (set) => ({
2554
- name: storeName,
2555
- data: typeof initData === "undefined" ? [] : initData,
2556
- loading: false,
2557
- error: null,
2558
- fetchData: async (dynamicBaseUrl, options) => {
2559
- try {
2560
- set({ loading: true });
2561
- const brokerIdQuery = typeof options?.brokerId === "string" && options?.brokerId !== "orderly" ? `?broker_id=${options?.brokerId}` : "";
2562
- const url = `${dynamicBaseUrl || baseUrl || ""}${endpoint}${brokerIdQuery}`;
2563
- const data = await fetcher(url, {}, { formatter });
2564
- const dataWithBrokerId = data.map((item) => ({
2565
- ...item,
2566
- broker_id: options?.brokerId
2567
- }));
2568
- set({
2569
- data: dataWithBrokerId,
2570
- loading: false,
2571
- error: null
2572
- });
2573
- return dataWithBrokerId;
2574
- } catch (error) {
2575
- set({ error, loading: false });
2576
- return null;
2555
+ (set) => {
2556
+ const store = {
2557
+ name: storeName,
2558
+ data: typeof initData === "undefined" ? [] : initData,
2559
+ loading: false,
2560
+ error: null,
2561
+ hydrated: false,
2562
+ fetchData: async (dynamicBaseUrl, options) => {
2563
+ try {
2564
+ set({ loading: true });
2565
+ const brokerIdQuery = typeof options?.brokerId === "string" && options?.brokerId !== "orderly" ? `?broker_id=${options?.brokerId}` : "";
2566
+ const url = `${dynamicBaseUrl || baseUrl || ""}${endpoint}${brokerIdQuery}`;
2567
+ const data = await fetcher(url, {}, { formatter });
2568
+ const dataWithBrokerId = data.map((item) => ({
2569
+ ...item,
2570
+ broker_id: options?.brokerId
2571
+ }));
2572
+ set({
2573
+ data: dataWithBrokerId,
2574
+ loading: false,
2575
+ error: null
2576
+ });
2577
+ return dataWithBrokerId;
2578
+ } catch (error) {
2579
+ set({ error, loading: false });
2580
+ return null;
2581
+ }
2577
2582
  }
2578
- }
2579
- }),
2583
+ };
2584
+ return store;
2585
+ },
2580
2586
  {
2581
2587
  name,
2582
2588
  indexedDBConfig: {
@@ -2590,6 +2596,15 @@ var createDataStore = (config) => {
2590
2596
  ...current,
2591
2597
  data: persisted
2592
2598
  };
2599
+ },
2600
+ /**
2601
+ * Callback executed after rehydration from IndexedDB completes
2602
+ * Sets hydrated flag to true to indicate store is ready
2603
+ */
2604
+ onRehydrateStorage: () => (state, error) => {
2605
+ if (state && !error) {
2606
+ state.hydrated = true;
2607
+ }
2593
2608
  }
2594
2609
  }
2595
2610
  )
@@ -6021,7 +6036,7 @@ var useOrderStream = (params, options) => {
6021
6036
  const total = useMemo(() => {
6022
6037
  return orders?.length || 0;
6023
6038
  }, [orders?.length]);
6024
- const cancelAlgoOrdersByTypes = (types) => {
6039
+ const cancelAlgoOrdersByTypes = (types, symbol2) => {
6025
6040
  if (!types) {
6026
6041
  throw new SDKError("Types is required");
6027
6042
  }
@@ -6030,7 +6045,10 @@ var useOrderStream = (params, options) => {
6030
6045
  }
6031
6046
  return Promise.all(
6032
6047
  types.map((type) => {
6033
- return doCancelAllAlgoOrders(null, { algo_type: type });
6048
+ return doCancelAllAlgoOrders(null, {
6049
+ algo_type: type,
6050
+ ...symbol2 && { symbol: symbol2 }
6051
+ });
6034
6052
  })
6035
6053
  );
6036
6054
  };
@@ -6043,6 +6061,9 @@ var useOrderStream = (params, options) => {
6043
6061
  })
6044
6062
  ]);
6045
6063
  }, [normalOrdersResponse.data, algoOrdersResponse.data]);
6064
+ const cancelAllPendingOrders = useCallback((symbol2) => {
6065
+ doCancelAllOrders(null, { ...symbol2 && { symbol: symbol2 } });
6066
+ }, []);
6046
6067
  const cancelPostionOrdersByTypes = useCallback(
6047
6068
  (symbol2, types) => {
6048
6069
  return doCancelAllAlgoOrders(null, {
@@ -6052,12 +6073,15 @@ var useOrderStream = (params, options) => {
6052
6073
  },
6053
6074
  [algoOrdersResponse.data]
6054
6075
  );
6055
- const cancelAllTPSLOrders = useCallback(() => {
6056
- return cancelAlgoOrdersByTypes([
6057
- AlgoOrderRootType.POSITIONAL_TP_SL,
6058
- AlgoOrderRootType.TP_SL
6059
- ]);
6060
- }, [algoOrdersResponse.data]);
6076
+ const cancelAllTPSLOrders = useCallback(
6077
+ (symbol2) => {
6078
+ return cancelAlgoOrdersByTypes(
6079
+ [AlgoOrderRootType.POSITIONAL_TP_SL, AlgoOrderRootType.TP_SL],
6080
+ symbol2
6081
+ );
6082
+ },
6083
+ [algoOrdersResponse.data]
6084
+ );
6061
6085
  const _updateOrder = useCallback(
6062
6086
  (orderId, order, type) => {
6063
6087
  switch (type) {
@@ -6167,6 +6191,7 @@ var useOrderStream = (params, options) => {
6167
6191
  refresh,
6168
6192
  loadMore,
6169
6193
  cancelAllOrders,
6194
+ cancelAllPendingOrders,
6170
6195
  cancelAllTPSLOrders,
6171
6196
  cancelAlgoOrdersByTypes,
6172
6197
  updateOrder,