@orderly.network/hooks 0.0.51 → 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,
@@ -1120,16 +1119,10 @@ var usePositionStream = (symbol, options) => {
1120
1119
  const total = totalCollateral.toNumber();
1121
1120
  return formatedPositions[0].filter((item) => item.position_qty !== 0).map((item) => {
1122
1121
  const info = symbolInfo == null ? void 0 : symbolInfo[item.symbol];
1123
- console.log(
1124
- "info -------",
1125
- info("base"),
1126
- accountInfo.imr_factor,
1127
- accountInfo.imr_factor[info("base")]
1128
- );
1129
1122
  const MMR = futures.positions.MMR({
1130
1123
  baseMMR: info("base_mmr"),
1131
1124
  baseIMR: info("base_imr"),
1132
- IMRFactor: accountInfo.imr_factor[info("base")],
1125
+ IMRFactor: accountInfo.imr_factor[item.symbol],
1133
1126
  positionNotional: item.notional,
1134
1127
  IMR_factor_power: 4 / 5
1135
1128
  });
@@ -1938,42 +1931,50 @@ var useMarginRatio = () => {
1938
1931
  return { marginRatio, currentLeverage };
1939
1932
  };
1940
1933
  var useChains = (networkId, options = {}) => {
1941
- 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);
1942
1936
  const field = options == null ? void 0 : options.pick;
1943
1937
  const { data } = useSWR__default.default(
1944
- "https://fi-api.woo.org/swap_support",
1938
+ // () =>
1939
+ // wooSwapEnabled
1940
+ // ? `${configStore.get("swapSupportApiUrl")}/swap_support`
1941
+ // : null,
1942
+ `${configStore.get("swapSupportApiUrl")}/swap_support`,
1945
1943
  (url) => fetch(url).then((res) => res.json()),
1946
1944
  __spreadValues({
1947
1945
  revalidateOnFocus: false,
1948
1946
  revalidateOnReconnect: false
1949
1947
  }, swrOptions)
1950
1948
  );
1949
+ const { data: orderlyChains } = useQuery("/v1/public/token");
1951
1950
  const chains = React2.useMemo(() => {
1952
- if (!data || !data.data)
1951
+ if (!data || !data.data || !orderlyChains)
1953
1952
  return data;
1954
- let arr = [];
1953
+ let testnetArr = [];
1954
+ let mainnetArr = [];
1955
1955
  Object.keys(data.data).forEach((key) => {
1956
- const item = data.data[key];
1957
- arr.push(__spreadProps(__spreadValues({}, item), {
1958
- name: key
1959
- }));
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
+ }
1960
1966
  });
1961
1967
  if (networkId === "mainnet") {
1962
- arr = arr.filter((item) => item.network_infos.mainnet);
1968
+ return mainnetArr;
1963
1969
  }
1964
1970
  if (networkId === "testnet") {
1965
- arr = arr.filter((item) => !item.network_infos.mainnet);
1966
- }
1967
- if (typeof (options == null ? void 0 : options.filter) === "function") {
1968
- arr = arr.filter(options.filter);
1971
+ return testnetArr;
1969
1972
  }
1970
- if (typeof field !== "undefined") {
1971
- return arr.map((item) => {
1972
- return item[field];
1973
- });
1974
- }
1975
- return arr;
1976
- }, [data, networkId, field, options]);
1973
+ return {
1974
+ testnet: testnetArr,
1975
+ mainnet: mainnetArr
1976
+ };
1977
+ }, [data, networkId, field, options, orderlyChains, wooSwapEnabled]);
1977
1978
  const findByChainId = React2.useCallback(
1978
1979
  (chainId) => {
1979
1980
  if (!data || !data.data)