@bze/bze-ui-kit 1.0.2 → 1.0.4

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
@@ -3068,6 +3068,137 @@ function useConnectionType() {
3068
3068
  // src/hooks/useSigningClient.ts
3069
3069
  import { useCallback as useCallback2, useEffect, useRef, useState } from "react";
3070
3070
  import { useChain } from "@interchain-kit/react";
3071
+
3072
+ // src/utils/signing_client_setup.ts
3073
+ import {
3074
+ MsgCreateMarket,
3075
+ MsgCreateOrder,
3076
+ MsgCancelOrder,
3077
+ MsgFillOrders,
3078
+ MsgCreateLiquidityPool,
3079
+ MsgAddLiquidity,
3080
+ MsgRemoveLiquidity,
3081
+ MsgMultiSwap
3082
+ } from "@bze/bzejs/bze/tradebin/tx";
3083
+ import {
3084
+ MsgCreateStakingReward,
3085
+ MsgUpdateStakingReward,
3086
+ MsgJoinStaking,
3087
+ MsgExitStaking,
3088
+ MsgClaimStakingRewards,
3089
+ MsgCreateTradingReward,
3090
+ MsgActivateTradingReward
3091
+ } from "@bze/bzejs/bze/rewards/tx";
3092
+ import { MsgFundBurner, MsgStartRaffle, MsgJoinRaffle } from "@bze/bzejs/bze/burner/tx";
3093
+ import { MsgCreateDenom, MsgMint, MsgBurn, MsgChangeAdmin, MsgSetDenomMetadata } from "@bze/bzejs/bze/tokenfactory/tx";
3094
+ import { MsgAddArticle, MsgPayPublisherRespect, MsgAcceptDomain, MsgSavePublisher } from "@bze/bzejs/bze/cointrunk/tx";
3095
+ import { MsgSend, MsgMultiSend } from "@bze/bzejs/cosmos/bank/v1beta1/tx";
3096
+ import {
3097
+ MsgDelegate,
3098
+ MsgUndelegate,
3099
+ MsgBeginRedelegate,
3100
+ MsgCancelUnbondingDelegation
3101
+ } from "@bze/bzejs/cosmos/staking/v1beta1/tx";
3102
+ import {
3103
+ MsgSetWithdrawAddress,
3104
+ MsgWithdrawDelegatorReward,
3105
+ MsgWithdrawValidatorCommission,
3106
+ MsgFundCommunityPool
3107
+ } from "@bze/bzejs/cosmos/distribution/v1beta1/tx";
3108
+ import {
3109
+ MsgSubmitProposal,
3110
+ MsgVote,
3111
+ MsgVoteWeighted,
3112
+ MsgDeposit,
3113
+ MsgCancelProposal
3114
+ } from "@bze/bzejs/cosmos/gov/v1/tx";
3115
+ import { MsgGrant, MsgExec, MsgRevoke } from "@bze/bzejs/cosmos/authz/v1beta1/tx";
3116
+ import { MsgGrantAllowance, MsgRevokeAllowance } from "@bze/bzejs/cosmos/feegrant/v1beta1/tx";
3117
+ import { MsgTransfer } from "@bze/bzejs/ibc/applications/transfer/v1/tx";
3118
+ var toEncoder = (g) => ({
3119
+ typeUrl: g.typeUrl,
3120
+ fromPartial: g.fromPartial,
3121
+ encode: (data) => {
3122
+ const encoded = g.encode(g.fromPartial(data));
3123
+ return encoded.finish ? encoded.finish() : encoded;
3124
+ }
3125
+ });
3126
+ var toConverter = (g) => ({
3127
+ typeUrl: g.typeUrl,
3128
+ aminoType: g.aminoType,
3129
+ fromAmino: g.fromAmino,
3130
+ toAmino: g.toAmino
3131
+ });
3132
+ var ALL_MSG_TYPES = [
3133
+ // BZE tradebin
3134
+ MsgCreateMarket,
3135
+ MsgCreateOrder,
3136
+ MsgCancelOrder,
3137
+ MsgFillOrders,
3138
+ MsgCreateLiquidityPool,
3139
+ MsgAddLiquidity,
3140
+ MsgRemoveLiquidity,
3141
+ MsgMultiSwap,
3142
+ // BZE rewards
3143
+ MsgCreateStakingReward,
3144
+ MsgUpdateStakingReward,
3145
+ MsgJoinStaking,
3146
+ MsgExitStaking,
3147
+ MsgClaimStakingRewards,
3148
+ MsgCreateTradingReward,
3149
+ MsgActivateTradingReward,
3150
+ // BZE burner
3151
+ MsgFundBurner,
3152
+ MsgStartRaffle,
3153
+ MsgJoinRaffle,
3154
+ // BZE tokenfactory
3155
+ MsgCreateDenom,
3156
+ MsgMint,
3157
+ MsgBurn,
3158
+ MsgChangeAdmin,
3159
+ MsgSetDenomMetadata,
3160
+ // BZE cointrunk
3161
+ MsgAddArticle,
3162
+ MsgPayPublisherRespect,
3163
+ MsgAcceptDomain,
3164
+ MsgSavePublisher,
3165
+ // Cosmos bank
3166
+ MsgSend,
3167
+ MsgMultiSend,
3168
+ // Cosmos staking
3169
+ MsgDelegate,
3170
+ MsgUndelegate,
3171
+ MsgBeginRedelegate,
3172
+ MsgCancelUnbondingDelegation,
3173
+ // Cosmos distribution
3174
+ MsgSetWithdrawAddress,
3175
+ MsgWithdrawDelegatorReward,
3176
+ MsgWithdrawValidatorCommission,
3177
+ MsgFundCommunityPool,
3178
+ // Cosmos gov
3179
+ MsgSubmitProposal,
3180
+ MsgVote,
3181
+ MsgVoteWeighted,
3182
+ MsgDeposit,
3183
+ MsgCancelProposal,
3184
+ // Cosmos authz
3185
+ MsgGrant,
3186
+ MsgExec,
3187
+ MsgRevoke,
3188
+ // Cosmos feegrant
3189
+ MsgGrantAllowance,
3190
+ MsgRevokeAllowance,
3191
+ // IBC transfer
3192
+ MsgTransfer
3193
+ ];
3194
+ var registerBzeEncoders = (client) => {
3195
+ var _a2, _b2;
3196
+ if (!client) return;
3197
+ (_a2 = client.addEncoders) == null ? void 0 : _a2.call(client, ALL_MSG_TYPES.map(toEncoder));
3198
+ (_b2 = client.addConverters) == null ? void 0 : _b2.call(client, ALL_MSG_TYPES.map(toConverter));
3199
+ };
3200
+
3201
+ // src/hooks/useSigningClient.ts
3071
3202
  var useSigningClient = ({ chainName }) => {
3072
3203
  const { getSigningClient, signingClientError, wallet, chain } = useChain(chainName != null ? chainName : getChainName());
3073
3204
  const [signingClient, setSigningClient] = useState(null);
@@ -3083,6 +3214,7 @@ var useSigningClient = ({ chainName }) => {
3083
3214
  const load = async () => {
3084
3215
  const client = await createSigningClient();
3085
3216
  if (client) {
3217
+ registerBzeEncoders(client);
3086
3218
  setSigningClient(client);
3087
3219
  setIsSigningClientReady(true);
3088
3220
  hasInitialized.current = true;
@@ -3781,10 +3913,10 @@ var useToast = () => {
3781
3913
  };
3782
3914
 
3783
3915
  // src/hooks/useTx.tsx
3916
+ import { TxBody, SignerInfo } from "@bze/bzejs/cosmos/tx/v1beta1/tx";
3784
3917
  import { useChain as useChain2 } from "@interchain-kit/react";
3785
3918
  import BigNumber13 from "bignumber.js";
3786
3919
  import { useCallback as useCallback11, useMemo as useMemo11, useState as useState3 } from "react";
3787
- var coins2 = (amount, denom) => [{ amount: String(amount), denom }];
3788
3920
  var TxStatus = /* @__PURE__ */ ((TxStatus2) => {
3789
3921
  TxStatus2["Failed"] = "Transaction Failed";
3790
3922
  TxStatus2["Successful"] = "Transaction Successful";
@@ -3792,7 +3924,7 @@ var TxStatus = /* @__PURE__ */ ((TxStatus2) => {
3792
3924
  return TxStatus2;
3793
3925
  })(TxStatus || {});
3794
3926
  var defaultFee = {
3795
- amount: coins2(2e4, getChainNativeAssetDenom()),
3927
+ amount: coins(2e4, getChainNativeAssetDenom()),
3796
3928
  gas: "500000"
3797
3929
  };
3798
3930
  var useSDKTx = (chainName) => {
@@ -3832,13 +3964,24 @@ var useTx = (chainName) => {
3832
3964
  return isSigningClientReady;
3833
3965
  }, [isSigningClientReady, signingClientError]);
3834
3966
  const simulateFee = useCallback11(async (messages, memo) => {
3967
+ var _a2;
3835
3968
  const gasPrice = 0.02;
3836
3969
  const nativeDenom = getChainNativeAssetDenom();
3837
- const gasEstimated = await signingClient.simulate(address, messages, memo);
3970
+ const signer = signingClient;
3971
+ const encodedMessages = messages.map(({ typeUrl, value }) => {
3972
+ const encoder = signer.getEncoder(typeUrl);
3973
+ const encodedWriter = encoder.encode(value);
3974
+ const encodedValue = typeof (encodedWriter == null ? void 0 : encodedWriter.finish) === "function" ? encodedWriter.finish() : encodedWriter;
3975
+ return { typeUrl, value: encodedValue };
3976
+ });
3977
+ 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));
3838
3981
  const gasAmount = BigNumber13(gasEstimated).multipliedBy(1.5);
3839
3982
  const gasPayment = gasAmount.multipliedBy(gasPrice);
3840
3983
  const nativeFee = {
3841
- amount: coins2(gasPayment.toFixed(0).toString(), nativeDenom),
3984
+ amount: coins(gasPayment.toFixed(0).toString(), nativeDenom),
3842
3985
  gas: gasAmount.toFixed(0)
3843
3986
  };
3844
3987
  if (feeDenom === nativeDenom) {
@@ -3857,7 +4000,7 @@ var useTx = (chainName) => {
3857
4000
  expectedAmount = toBigNumber(1).dividedBy(pool.fee).integerValue(BigNumber13.ROUND_CEIL);
3858
4001
  }
3859
4002
  return {
3860
- amount: coins2(expectedAmount.toFixed(0).toString(), feeDenom),
4003
+ amount: coins(expectedAmount.toFixed(0).toString(), feeDenom),
3861
4004
  gas: gasAmount.multipliedBy(1.5).toFixed(0)
3862
4005
  };
3863
4006
  }, [signingClient, address, feeDenom, getDenomsPool]);
@@ -3895,11 +4038,14 @@ var useTx = (chainName) => {
3895
4038
  try {
3896
4039
  const fee = await getFee(msgs, options);
3897
4040
  setProgressTrack("Signing transaction");
3898
- const resp = await signingClient.signAndBroadcast(address, msgs, fee, (_a2 = options == null ? void 0 : options.memo) != null ? _a2 : DEFAULT_TX_MEMO);
3899
- if (resp.code === 0) {
4041
+ const broadcastResult = await signingClient.signAndBroadcast(address, msgs, fee, (_a2 = options == null ? void 0 : options.memo) != null ? _a2 : DEFAULT_TX_MEMO);
4042
+ setProgressTrack("Waiting for confirmation");
4043
+ const resp = await broadcastResult.wait();
4044
+ const txHash = (resp == null ? void 0 : resp.txhash) || broadcastResult.transactionHash;
4045
+ if ((resp == null ? void 0 : resp.code) === 0) {
3900
4046
  setProgressTrack("Transaction sent");
3901
4047
  toast.clickableSuccess("Transaction Successful" /* Successful */, () => {
3902
- openExternalLink(`${getChainExplorerURL(chainName != null ? chainName : defaultChainName)}/tx/${resp.transactionHash}`);
4048
+ openExternalLink(`${getChainExplorerURL(chainName != null ? chainName : defaultChainName)}/tx/${txHash}`);
3903
4049
  }, "View in Explorer");
3904
4050
  if (options == null ? void 0 : options.onSuccess) {
3905
4051
  options.onSuccess(resp);