@bze/bze-ui-kit 1.0.3 → 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.d.mts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +131 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +163 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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,7 +3913,8 @@ var useToast = () => {
|
|
|
3781
3913
|
};
|
|
3782
3914
|
|
|
3783
3915
|
// src/hooks/useTx.tsx
|
|
3784
|
-
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";
|
|
3785
3918
|
import { useChain as useChain2 } from "@interchain-kit/react";
|
|
3786
3919
|
import BigNumber13 from "bignumber.js";
|
|
3787
3920
|
import { useCallback as useCallback11, useMemo as useMemo11, useState as useState3 } from "react";
|
|
@@ -3832,7 +3965,7 @@ var useTx = (chainName) => {
|
|
|
3832
3965
|
return isSigningClientReady;
|
|
3833
3966
|
}, [isSigningClientReady, signingClientError]);
|
|
3834
3967
|
const simulateFee = useCallback11(async (messages, memo) => {
|
|
3835
|
-
var _a2;
|
|
3968
|
+
var _a2, _b2;
|
|
3836
3969
|
const gasPrice = 0.02;
|
|
3837
3970
|
const nativeDenom = getChainNativeAssetDenom();
|
|
3838
3971
|
const signer = signingClient;
|
|
@@ -3843,9 +3976,26 @@ var useTx = (chainName) => {
|
|
|
3843
3976
|
return { typeUrl, value: encodedValue };
|
|
3844
3977
|
});
|
|
3845
3978
|
const txBody = TxBody.fromPartial({ messages: encodedMessages, memo: memo != null ? memo : "" });
|
|
3846
|
-
const
|
|
3847
|
-
|
|
3848
|
-
|
|
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
|
+
}
|
|
3849
3999
|
const gasAmount = BigNumber13(gasEstimated).multipliedBy(1.5);
|
|
3850
4000
|
const gasPayment = gasAmount.multipliedBy(gasPrice);
|
|
3851
4001
|
const nativeFee = {
|
|
@@ -3881,12 +4031,8 @@ var useTx = (chainName) => {
|
|
|
3881
4031
|
return await simulateFee(messages, options == null ? void 0 : options.memo);
|
|
3882
4032
|
}
|
|
3883
4033
|
} catch (e) {
|
|
3884
|
-
console.error("could not get fee: ", e);
|
|
3885
|
-
|
|
3886
|
-
return defaultFee;
|
|
3887
|
-
} else {
|
|
3888
|
-
throw e;
|
|
3889
|
-
}
|
|
4034
|
+
console.error("could not get fee, using default fee: ", e);
|
|
4035
|
+
return defaultFee;
|
|
3890
4036
|
}
|
|
3891
4037
|
}, [simulateFee]);
|
|
3892
4038
|
const tx = useCallback11(async (msgs, options) => {
|
|
@@ -3906,11 +4052,14 @@ var useTx = (chainName) => {
|
|
|
3906
4052
|
try {
|
|
3907
4053
|
const fee = await getFee(msgs, options);
|
|
3908
4054
|
setProgressTrack("Signing transaction");
|
|
3909
|
-
const
|
|
3910
|
-
|
|
4055
|
+
const broadcastResult = await signingClient.signAndBroadcast(address, msgs, fee, (_a2 = options == null ? void 0 : options.memo) != null ? _a2 : DEFAULT_TX_MEMO);
|
|
4056
|
+
setProgressTrack("Waiting for confirmation");
|
|
4057
|
+
const resp = await broadcastResult.wait();
|
|
4058
|
+
const txHash = (resp == null ? void 0 : resp.txhash) || broadcastResult.transactionHash;
|
|
4059
|
+
if ((resp == null ? void 0 : resp.code) === 0) {
|
|
3911
4060
|
setProgressTrack("Transaction sent");
|
|
3912
4061
|
toast.clickableSuccess("Transaction Successful" /* Successful */, () => {
|
|
3913
|
-
openExternalLink(`${getChainExplorerURL(chainName != null ? chainName : defaultChainName)}/tx/${
|
|
4062
|
+
openExternalLink(`${getChainExplorerURL(chainName != null ? chainName : defaultChainName)}/tx/${txHash}`);
|
|
3914
4063
|
}, "View in Explorer");
|
|
3915
4064
|
if (options == null ? void 0 : options.onSuccess) {
|
|
3916
4065
|
options.onSuccess(resp);
|