@bze/bze-ui-kit 1.0.2 → 1.0.3

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
@@ -3781,10 +3781,10 @@ var useToast = () => {
3781
3781
  };
3782
3782
 
3783
3783
  // src/hooks/useTx.tsx
3784
+ import { TxBody, SignerInfo } from "@bze/bzejs/cosmos/tx/v1beta1/tx";
3784
3785
  import { useChain as useChain2 } from "@interchain-kit/react";
3785
3786
  import BigNumber13 from "bignumber.js";
3786
3787
  import { useCallback as useCallback11, useMemo as useMemo11, useState as useState3 } from "react";
3787
- var coins2 = (amount, denom) => [{ amount: String(amount), denom }];
3788
3788
  var TxStatus = /* @__PURE__ */ ((TxStatus2) => {
3789
3789
  TxStatus2["Failed"] = "Transaction Failed";
3790
3790
  TxStatus2["Successful"] = "Transaction Successful";
@@ -3792,7 +3792,7 @@ var TxStatus = /* @__PURE__ */ ((TxStatus2) => {
3792
3792
  return TxStatus2;
3793
3793
  })(TxStatus || {});
3794
3794
  var defaultFee = {
3795
- amount: coins2(2e4, getChainNativeAssetDenom()),
3795
+ amount: coins(2e4, getChainNativeAssetDenom()),
3796
3796
  gas: "500000"
3797
3797
  };
3798
3798
  var useSDKTx = (chainName) => {
@@ -3832,13 +3832,24 @@ var useTx = (chainName) => {
3832
3832
  return isSigningClientReady;
3833
3833
  }, [isSigningClientReady, signingClientError]);
3834
3834
  const simulateFee = useCallback11(async (messages, memo) => {
3835
+ var _a2;
3835
3836
  const gasPrice = 0.02;
3836
3837
  const nativeDenom = getChainNativeAssetDenom();
3837
- const gasEstimated = await signingClient.simulate(address, messages, memo);
3838
+ const signer = signingClient;
3839
+ const encodedMessages = messages.map(({ typeUrl, value }) => {
3840
+ const encoder = signer.getEncoder(typeUrl);
3841
+ const encodedWriter = encoder.encode(value);
3842
+ const encodedValue = typeof (encodedWriter == null ? void 0 : encodedWriter.finish) === "function" ? encodedWriter.finish() : encodedWriter;
3843
+ return { typeUrl, value: encodedValue };
3844
+ });
3845
+ const txBody = TxBody.fromPartial({ messages: encodedMessages, memo: memo != null ? memo : "" });
3846
+ const signerInfo = SignerInfo.fromPartial({ modeInfo: { single: { mode: 1 } }, sequence: BigInt(0) });
3847
+ const { gasInfo } = await signer.simulateByTxBody(txBody, [signerInfo]);
3848
+ const gasEstimated = Number((_a2 = gasInfo == null ? void 0 : gasInfo.gasUsed) != null ? _a2 : BigInt(0));
3838
3849
  const gasAmount = BigNumber13(gasEstimated).multipliedBy(1.5);
3839
3850
  const gasPayment = gasAmount.multipliedBy(gasPrice);
3840
3851
  const nativeFee = {
3841
- amount: coins2(gasPayment.toFixed(0).toString(), nativeDenom),
3852
+ amount: coins(gasPayment.toFixed(0).toString(), nativeDenom),
3842
3853
  gas: gasAmount.toFixed(0)
3843
3854
  };
3844
3855
  if (feeDenom === nativeDenom) {
@@ -3857,7 +3868,7 @@ var useTx = (chainName) => {
3857
3868
  expectedAmount = toBigNumber(1).dividedBy(pool.fee).integerValue(BigNumber13.ROUND_CEIL);
3858
3869
  }
3859
3870
  return {
3860
- amount: coins2(expectedAmount.toFixed(0).toString(), feeDenom),
3871
+ amount: coins(expectedAmount.toFixed(0).toString(), feeDenom),
3861
3872
  gas: gasAmount.multipliedBy(1.5).toFixed(0)
3862
3873
  };
3863
3874
  }, [signingClient, address, feeDenom, getDenomsPool]);