@orderly.network/hooks 0.0.52 → 0.0.53

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.js CHANGED
@@ -327,11 +327,10 @@ var useAppState = () => {
327
327
  ready
328
328
  };
329
329
  };
330
-
331
- // src/usePreloadData.ts
332
330
  var usePreLoadData = (onSuccess) => {
331
+ const { configStore } = React2.useContext(OrderlyContext);
333
332
  useSWR__default.default(
334
- "https://fi-api.woo.org/swap_support",
333
+ `${configStore.get("swapSupportApiUrl")}/swap_support`,
335
334
  (url) => fetch(url).then((res) => res.json()),
336
335
  {
337
336
  revalidateOnFocus: false,
@@ -1123,7 +1122,7 @@ var usePositionStream = (symbol, options) => {
1123
1122
  const MMR = futures.positions.MMR({
1124
1123
  baseMMR: info("base_mmr"),
1125
1124
  baseIMR: info("base_imr"),
1126
- IMRFactor: accountInfo.imr_factor[info("base")],
1125
+ IMRFactor: accountInfo.imr_factor[item.symbol],
1127
1126
  positionNotional: item.notional,
1128
1127
  IMR_factor_power: 4 / 5
1129
1128
  });
@@ -1343,7 +1342,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
1343
1342
  positionQty,
1344
1343
  buyOrdersQty,
1345
1344
  sellOrdersQty,
1346
- IMR_Factor: accountInfo.imr_factor[getSymbolInfo("base")]
1345
+ IMR_Factor: accountInfo.imr_factor[symbol]
1347
1346
  });
1348
1347
  }, [
1349
1348
  orders,
@@ -1932,42 +1931,50 @@ var useMarginRatio = () => {
1932
1931
  return { marginRatio, currentLeverage };
1933
1932
  };
1934
1933
  var useChains = (networkId, options = {}) => {
1935
- const _a = options, swrOptions = __objRest(_a, ["filter", "pick"]);
1934
+ const _a = options, { filter, pick, crossEnabled, wooSwapEnabled } = _a, swrOptions = __objRest(_a, ["filter", "pick", "crossEnabled", "wooSwapEnabled"]);
1935
+ const { configStore } = React2.useContext(OrderlyContext);
1936
1936
  const field = options == null ? void 0 : options.pick;
1937
1937
  const { data } = useSWR__default.default(
1938
- "https://fi-api.woo.org/swap_support",
1938
+ // () =>
1939
+ // wooSwapEnabled
1940
+ // ? `${configStore.get("swapSupportApiUrl")}/swap_support`
1941
+ // : null,
1942
+ `${configStore.get("swapSupportApiUrl")}/swap_support`,
1939
1943
  (url) => fetch(url).then((res) => res.json()),
1940
1944
  __spreadValues({
1941
1945
  revalidateOnFocus: false,
1942
1946
  revalidateOnReconnect: false
1943
1947
  }, swrOptions)
1944
1948
  );
1949
+ const { data: orderlyChains } = useQuery("/v1/public/token");
1945
1950
  const chains = React2.useMemo(() => {
1946
- if (!data || !data.data)
1951
+ if (!data || !data.data || !orderlyChains)
1947
1952
  return data;
1948
- let arr = [];
1953
+ let testnetArr = [];
1954
+ let mainnetArr = [];
1949
1955
  Object.keys(data.data).forEach((key) => {
1950
- const item = data.data[key];
1951
- arr.push(__spreadProps(__spreadValues({}, item), {
1952
- name: key
1953
- }));
1956
+ const item = __spreadProps(__spreadValues({}, data.data[key]), { name: key, priority: 1 });
1957
+ if (typeof (options == null ? void 0 : options.filter) === "function") {
1958
+ if (!options.filter(item))
1959
+ return;
1960
+ }
1961
+ if (item.network_infos.mainnet) {
1962
+ mainnetArr.push(field ? item[field] : item);
1963
+ } else {
1964
+ testnetArr.push(field ? item[field] : item);
1965
+ }
1954
1966
  });
1955
1967
  if (networkId === "mainnet") {
1956
- arr = arr.filter((item) => item.network_infos.mainnet);
1968
+ return mainnetArr;
1957
1969
  }
1958
1970
  if (networkId === "testnet") {
1959
- arr = arr.filter((item) => !item.network_infos.mainnet);
1960
- }
1961
- if (typeof (options == null ? void 0 : options.filter) === "function") {
1962
- arr = arr.filter(options.filter);
1971
+ return testnetArr;
1963
1972
  }
1964
- if (typeof field !== "undefined") {
1965
- return arr.map((item) => {
1966
- return item[field];
1967
- });
1968
- }
1969
- return arr;
1970
- }, [data, networkId, field, options]);
1973
+ return {
1974
+ testnet: testnetArr,
1975
+ mainnet: mainnetArr
1976
+ };
1977
+ }, [data, networkId, field, options, orderlyChains, wooSwapEnabled]);
1971
1978
  const findByChainId = React2.useCallback(
1972
1979
  (chainId) => {
1973
1980
  if (!data || !data.data)