@bze/bze-ui-kit 1.0.4 → 1.0.5

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
@@ -3913,7 +3913,8 @@ var useToast = () => {
3913
3913
  };
3914
3914
 
3915
3915
  // src/hooks/useTx.tsx
3916
- import { TxBody, SignerInfo } from "@bze/bzejs/cosmos/tx/v1beta1/tx";
3916
+ import { Tx, TxBody, AuthInfo, SignerInfo } from "@bze/bzejs/cosmos/tx/v1beta1/tx";
3917
+ import { toBase64 } from "@interchainjs/encoding";
3917
3918
  import { useChain as useChain2 } from "@interchain-kit/react";
3918
3919
  import BigNumber13 from "bignumber.js";
3919
3920
  import { useCallback as useCallback11, useMemo as useMemo11, useState as useState3 } from "react";
@@ -3964,7 +3965,7 @@ var useTx = (chainName) => {
3964
3965
  return isSigningClientReady;
3965
3966
  }, [isSigningClientReady, signingClientError]);
3966
3967
  const simulateFee = useCallback11(async (messages, memo) => {
3967
- var _a2;
3968
+ var _a2, _b2;
3968
3969
  const gasPrice = 0.02;
3969
3970
  const nativeDenom = getChainNativeAssetDenom();
3970
3971
  const signer = signingClient;
@@ -3975,9 +3976,26 @@ var useTx = (chainName) => {
3975
3976
  return { typeUrl, value: encodedValue };
3976
3977
  });
3977
3978
  const txBody = TxBody.fromPartial({ messages: encodedMessages, memo: memo != null ? memo : "" });
3978
- const signerInfo = SignerInfo.fromPartial({ modeInfo: { single: { mode: 1 } }, sequence: BigInt(0) });
3979
- const { gasInfo } = await signer.simulateByTxBody(txBody, [signerInfo]);
3980
- const gasEstimated = Number((_a2 = gasInfo == null ? void 0 : gasInfo.gasUsed) != null ? _a2 : BigInt(0));
3979
+ const authInfo = AuthInfo.fromPartial({
3980
+ signerInfos: [SignerInfo.fromPartial({ modeInfo: { single: { mode: 1 } }, sequence: BigInt(0) })],
3981
+ fee: { amount: [], gasLimit: BigInt(0), payer: "", granter: "" }
3982
+ });
3983
+ const tx2 = Tx.fromPartial({ body: txBody, authInfo, signatures: [new Uint8Array(0)] });
3984
+ const txBytes = Tx.encode(tx2).finish();
3985
+ const restEndpoint = getSettings().endpoints.restEndpoint.replace(/\/$/, "");
3986
+ const simResponse = await fetch(`${restEndpoint}/cosmos/tx/v1beta1/simulate`, {
3987
+ method: "POST",
3988
+ headers: { "Content-Type": "application/json" },
3989
+ body: JSON.stringify({ tx_bytes: toBase64(txBytes) })
3990
+ });
3991
+ if (!simResponse.ok) {
3992
+ throw new Error(`Simulation request failed with status ${simResponse.status}`);
3993
+ }
3994
+ const simData = await simResponse.json();
3995
+ const gasEstimated = Number((_b2 = (_a2 = simData == null ? void 0 : simData.gas_info) == null ? void 0 : _a2.gas_used) != null ? _b2 : 0);
3996
+ if (gasEstimated === 0) {
3997
+ throw new Error("Gas simulation returned 0");
3998
+ }
3981
3999
  const gasAmount = BigNumber13(gasEstimated).multipliedBy(1.5);
3982
4000
  const gasPayment = gasAmount.multipliedBy(gasPrice);
3983
4001
  const nativeFee = {
@@ -4013,12 +4031,8 @@ var useTx = (chainName) => {
4013
4031
  return await simulateFee(messages, options == null ? void 0 : options.memo);
4014
4032
  }
4015
4033
  } catch (e) {
4016
- console.error("could not get fee: ", e);
4017
- if (options == null ? void 0 : options.fallbackOnSimulate) {
4018
- return defaultFee;
4019
- } else {
4020
- throw e;
4021
- }
4034
+ console.error("could not get fee, using default fee: ", e);
4035
+ return defaultFee;
4022
4036
  }
4023
4037
  }, [simulateFee]);
4024
4038
  const tx = useCallback11(async (msgs, options) => {