@orderly.network/hooks 2.11.0-alpha.0 → 2.11.1-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
@@ -37,7 +37,7 @@ declare global {
37
37
  };
38
38
  }
39
39
  }
40
- declare const _default: "2.11.0-alpha.0";
40
+ declare const _default: "2.11.1-alpha.0";
41
41
 
42
42
  declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
43
43
  type useQueryOptions<T> = SWRConfiguration & {
@@ -1570,7 +1570,7 @@ type DST = {
1570
1570
  };
1571
1571
  type UseDepositReturn = ReturnType<typeof useDeposit>;
1572
1572
  declare const useDeposit: (options: DepositOptions) => {
1573
- balance: string;
1573
+ balance: string | null;
1574
1574
  allowance: string;
1575
1575
  /** deposit fee, unit: wei */
1576
1576
  depositFee: bigint;
package/dist/index.d.ts CHANGED
@@ -37,7 +37,7 @@ declare global {
37
37
  };
38
38
  }
39
39
  }
40
- declare const _default: "2.11.0-alpha.0";
40
+ declare const _default: "2.11.1-alpha.0";
41
41
 
42
42
  declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
43
43
  type useQueryOptions<T> = SWRConfiguration & {
@@ -1570,7 +1570,7 @@ type DST = {
1570
1570
  };
1571
1571
  type UseDepositReturn = ReturnType<typeof useDeposit>;
1572
1572
  declare const useDeposit: (options: DepositOptions) => {
1573
- balance: string;
1573
+ balance: string | null;
1574
1574
  allowance: string;
1575
1575
  /** deposit fee, unit: wei */
1576
1576
  depositFee: bigint;
package/dist/index.js CHANGED
@@ -64,9 +64,9 @@ var __export = (target, all) => {
64
64
  // src/version.ts
65
65
  if (typeof window !== "undefined") {
66
66
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
67
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.11.0-alpha.0";
67
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.11.1-alpha.0";
68
68
  }
69
- var version_default = "2.11.0-alpha.0";
69
+ var version_default = "2.11.1-alpha.0";
70
70
  var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
71
71
  var noCacheConfig = {
72
72
  dedupingInterval: 0,
@@ -7994,7 +7994,9 @@ var useDeposit = (options) => {
7994
7994
  const depositPromise = isNativeToken ? account9.assetsManager.depositNativeToken(inputs) : account9.assetsManager.deposit(inputs);
7995
7995
  return depositPromise.then((result) => {
7996
7996
  updateAllowanceWhenTxSuccess(result.hash);
7997
- setBalance((value) => new utils.Decimal(value).sub(quantity).toString());
7997
+ setBalance(
7998
+ (value) => value ? new utils.Decimal(value).sub(quantity).toString() : "0"
7999
+ );
7998
8000
  track2(types.TrackerEventName.depositSuccess, {
7999
8001
  wallet: state?.connectWallet?.name,
8000
8002
  network: targetChain?.network_infos.name,
@@ -8046,16 +8048,16 @@ var useDeposit = (options) => {
8046
8048
  };
8047
8049
  function useBalance(options) {
8048
8050
  const { srcToken, address, decimals, account: account9, status } = options;
8049
- const [balance, setBalance] = React.useState("0");
8051
+ const [balance, setBalance] = React.useState(null);
8050
8052
  const fetchBalance = React.useCallback(
8051
8053
  async (address2, decimals2) => {
8052
8054
  try {
8053
8055
  if (types.isNativeTokenChecker(address2)) {
8054
- return account9.assetsManager.getNativeBalance({
8056
+ return await account9.assetsManager.getNativeBalance({
8055
8057
  decimals: decimals2
8056
8058
  });
8057
8059
  }
8058
- return account9.assetsManager.getBalance(address2, {
8060
+ return await account9.assetsManager.getBalance(address2, {
8059
8061
  decimals: decimals2
8060
8062
  });
8061
8063
  } catch (err) {
@@ -8104,11 +8106,13 @@ function useBalance(options) {
8104
8106
  React.useEffect(() => {
8105
8107
  if (swrBalance !== void 0) {
8106
8108
  setBalance(swrBalance || "0");
8109
+ } else {
8110
+ setBalance(null);
8107
8111
  }
8108
- }, [swrBalance]);
8112
+ }, [swrBalance, address]);
8109
8113
  return {
8110
8114
  balance,
8111
- balanceRevalidating,
8115
+ balanceRevalidating: balanceRevalidating || balance === null,
8112
8116
  setBalance,
8113
8117
  fetchBalance,
8114
8118
  fetchBalances