@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 CHANGED
@@ -1202,7 +1202,6 @@ interface TxOptions {
1202
1202
  onFailure?: (err: string) => void;
1203
1203
  memo?: string;
1204
1204
  progressTrackerTimeout?: number;
1205
- fallbackOnSimulate?: boolean;
1206
1205
  }
1207
1206
  declare enum TxStatus {
1208
1207
  Failed = "Transaction Failed",
package/dist/index.d.ts CHANGED
@@ -1202,7 +1202,6 @@ interface TxOptions {
1202
1202
  onFailure?: (err: string) => void;
1203
1203
  memo?: string;
1204
1204
  progressTrackerTimeout?: number;
1205
- fallbackOnSimulate?: boolean;
1206
1205
  }
1207
1206
  declare enum TxStatus {
1208
1207
  Failed = "Transaction Failed",
package/dist/index.js CHANGED
@@ -3353,6 +3353,104 @@ function useConnectionType() {
3353
3353
  // src/hooks/useSigningClient.ts
3354
3354
  var import_react3 = require("react");
3355
3355
  var import_react4 = require("@interchain-kit/react");
3356
+
3357
+ // src/utils/signing_client_setup.ts
3358
+ var import_tx = require("@bze/bzejs/bze/tradebin/tx");
3359
+ var import_tx2 = require("@bze/bzejs/bze/rewards/tx");
3360
+ var import_tx3 = require("@bze/bzejs/bze/burner/tx");
3361
+ var import_tx4 = require("@bze/bzejs/bze/tokenfactory/tx");
3362
+ var import_tx5 = require("@bze/bzejs/bze/cointrunk/tx");
3363
+ var import_tx6 = require("@bze/bzejs/cosmos/bank/v1beta1/tx");
3364
+ var import_tx7 = require("@bze/bzejs/cosmos/staking/v1beta1/tx");
3365
+ var import_tx8 = require("@bze/bzejs/cosmos/distribution/v1beta1/tx");
3366
+ var import_tx9 = require("@bze/bzejs/cosmos/gov/v1/tx");
3367
+ var import_tx10 = require("@bze/bzejs/cosmos/authz/v1beta1/tx");
3368
+ var import_tx11 = require("@bze/bzejs/cosmos/feegrant/v1beta1/tx");
3369
+ var import_tx12 = require("@bze/bzejs/ibc/applications/transfer/v1/tx");
3370
+ var toEncoder = (g) => ({
3371
+ typeUrl: g.typeUrl,
3372
+ fromPartial: g.fromPartial,
3373
+ encode: (data) => {
3374
+ const encoded = g.encode(g.fromPartial(data));
3375
+ return encoded.finish ? encoded.finish() : encoded;
3376
+ }
3377
+ });
3378
+ var toConverter = (g) => ({
3379
+ typeUrl: g.typeUrl,
3380
+ aminoType: g.aminoType,
3381
+ fromAmino: g.fromAmino,
3382
+ toAmino: g.toAmino
3383
+ });
3384
+ var ALL_MSG_TYPES = [
3385
+ // BZE tradebin
3386
+ import_tx.MsgCreateMarket,
3387
+ import_tx.MsgCreateOrder,
3388
+ import_tx.MsgCancelOrder,
3389
+ import_tx.MsgFillOrders,
3390
+ import_tx.MsgCreateLiquidityPool,
3391
+ import_tx.MsgAddLiquidity,
3392
+ import_tx.MsgRemoveLiquidity,
3393
+ import_tx.MsgMultiSwap,
3394
+ // BZE rewards
3395
+ import_tx2.MsgCreateStakingReward,
3396
+ import_tx2.MsgUpdateStakingReward,
3397
+ import_tx2.MsgJoinStaking,
3398
+ import_tx2.MsgExitStaking,
3399
+ import_tx2.MsgClaimStakingRewards,
3400
+ import_tx2.MsgCreateTradingReward,
3401
+ import_tx2.MsgActivateTradingReward,
3402
+ // BZE burner
3403
+ import_tx3.MsgFundBurner,
3404
+ import_tx3.MsgStartRaffle,
3405
+ import_tx3.MsgJoinRaffle,
3406
+ // BZE tokenfactory
3407
+ import_tx4.MsgCreateDenom,
3408
+ import_tx4.MsgMint,
3409
+ import_tx4.MsgBurn,
3410
+ import_tx4.MsgChangeAdmin,
3411
+ import_tx4.MsgSetDenomMetadata,
3412
+ // BZE cointrunk
3413
+ import_tx5.MsgAddArticle,
3414
+ import_tx5.MsgPayPublisherRespect,
3415
+ import_tx5.MsgAcceptDomain,
3416
+ import_tx5.MsgSavePublisher,
3417
+ // Cosmos bank
3418
+ import_tx6.MsgSend,
3419
+ import_tx6.MsgMultiSend,
3420
+ // Cosmos staking
3421
+ import_tx7.MsgDelegate,
3422
+ import_tx7.MsgUndelegate,
3423
+ import_tx7.MsgBeginRedelegate,
3424
+ import_tx7.MsgCancelUnbondingDelegation,
3425
+ // Cosmos distribution
3426
+ import_tx8.MsgSetWithdrawAddress,
3427
+ import_tx8.MsgWithdrawDelegatorReward,
3428
+ import_tx8.MsgWithdrawValidatorCommission,
3429
+ import_tx8.MsgFundCommunityPool,
3430
+ // Cosmos gov
3431
+ import_tx9.MsgSubmitProposal,
3432
+ import_tx9.MsgVote,
3433
+ import_tx9.MsgVoteWeighted,
3434
+ import_tx9.MsgDeposit,
3435
+ import_tx9.MsgCancelProposal,
3436
+ // Cosmos authz
3437
+ import_tx10.MsgGrant,
3438
+ import_tx10.MsgExec,
3439
+ import_tx10.MsgRevoke,
3440
+ // Cosmos feegrant
3441
+ import_tx11.MsgGrantAllowance,
3442
+ import_tx11.MsgRevokeAllowance,
3443
+ // IBC transfer
3444
+ import_tx12.MsgTransfer
3445
+ ];
3446
+ var registerBzeEncoders = (client) => {
3447
+ var _a2, _b2;
3448
+ if (!client) return;
3449
+ (_a2 = client.addEncoders) == null ? void 0 : _a2.call(client, ALL_MSG_TYPES.map(toEncoder));
3450
+ (_b2 = client.addConverters) == null ? void 0 : _b2.call(client, ALL_MSG_TYPES.map(toConverter));
3451
+ };
3452
+
3453
+ // src/hooks/useSigningClient.ts
3356
3454
  var useSigningClient = ({ chainName }) => {
3357
3455
  const { getSigningClient, signingClientError, wallet, chain } = (0, import_react4.useChain)(chainName != null ? chainName : getChainName());
3358
3456
  const [signingClient, setSigningClient] = (0, import_react3.useState)(null);
@@ -3368,6 +3466,7 @@ var useSigningClient = ({ chainName }) => {
3368
3466
  const load = async () => {
3369
3467
  const client = await createSigningClient();
3370
3468
  if (client) {
3469
+ registerBzeEncoders(client);
3371
3470
  setSigningClient(client);
3372
3471
  setIsSigningClientReady(true);
3373
3472
  hasInitialized.current = true;
@@ -4059,7 +4158,8 @@ var useToast = () => {
4059
4158
  };
4060
4159
 
4061
4160
  // src/hooks/useTx.tsx
4062
- var import_tx = require("@bze/bzejs/cosmos/tx/v1beta1/tx");
4161
+ var import_tx13 = require("@bze/bzejs/cosmos/tx/v1beta1/tx");
4162
+ var import_encoding2 = require("@interchainjs/encoding");
4063
4163
  var import_react15 = require("@interchain-kit/react");
4064
4164
  var import_bignumber13 = __toESM(require("bignumber.js"));
4065
4165
  var import_react16 = require("react");
@@ -4110,7 +4210,7 @@ var useTx = (chainName) => {
4110
4210
  return isSigningClientReady;
4111
4211
  }, [isSigningClientReady, signingClientError]);
4112
4212
  const simulateFee = (0, import_react16.useCallback)(async (messages, memo) => {
4113
- var _a2;
4213
+ var _a2, _b2;
4114
4214
  const gasPrice = 0.02;
4115
4215
  const nativeDenom = getChainNativeAssetDenom();
4116
4216
  const signer = signingClient;
@@ -4120,10 +4220,27 @@ var useTx = (chainName) => {
4120
4220
  const encodedValue = typeof (encodedWriter == null ? void 0 : encodedWriter.finish) === "function" ? encodedWriter.finish() : encodedWriter;
4121
4221
  return { typeUrl, value: encodedValue };
4122
4222
  });
4123
- const txBody = import_tx.TxBody.fromPartial({ messages: encodedMessages, memo: memo != null ? memo : "" });
4124
- const signerInfo = import_tx.SignerInfo.fromPartial({ modeInfo: { single: { mode: 1 } }, sequence: BigInt(0) });
4125
- const { gasInfo } = await signer.simulateByTxBody(txBody, [signerInfo]);
4126
- const gasEstimated = Number((_a2 = gasInfo == null ? void 0 : gasInfo.gasUsed) != null ? _a2 : BigInt(0));
4223
+ const txBody = import_tx13.TxBody.fromPartial({ messages: encodedMessages, memo: memo != null ? memo : "" });
4224
+ const authInfo = import_tx13.AuthInfo.fromPartial({
4225
+ signerInfos: [import_tx13.SignerInfo.fromPartial({ modeInfo: { single: { mode: 1 } }, sequence: BigInt(0) })],
4226
+ fee: { amount: [], gasLimit: BigInt(0), payer: "", granter: "" }
4227
+ });
4228
+ const tx2 = import_tx13.Tx.fromPartial({ body: txBody, authInfo, signatures: [new Uint8Array(0)] });
4229
+ const txBytes = import_tx13.Tx.encode(tx2).finish();
4230
+ const restEndpoint = getSettings().endpoints.restEndpoint.replace(/\/$/, "");
4231
+ const simResponse = await fetch(`${restEndpoint}/cosmos/tx/v1beta1/simulate`, {
4232
+ method: "POST",
4233
+ headers: { "Content-Type": "application/json" },
4234
+ body: JSON.stringify({ tx_bytes: (0, import_encoding2.toBase64)(txBytes) })
4235
+ });
4236
+ if (!simResponse.ok) {
4237
+ throw new Error(`Simulation request failed with status ${simResponse.status}`);
4238
+ }
4239
+ const simData = await simResponse.json();
4240
+ const gasEstimated = Number((_b2 = (_a2 = simData == null ? void 0 : simData.gas_info) == null ? void 0 : _a2.gas_used) != null ? _b2 : 0);
4241
+ if (gasEstimated === 0) {
4242
+ throw new Error("Gas simulation returned 0");
4243
+ }
4127
4244
  const gasAmount = (0, import_bignumber13.default)(gasEstimated).multipliedBy(1.5);
4128
4245
  const gasPayment = gasAmount.multipliedBy(gasPrice);
4129
4246
  const nativeFee = {
@@ -4159,12 +4276,8 @@ var useTx = (chainName) => {
4159
4276
  return await simulateFee(messages, options == null ? void 0 : options.memo);
4160
4277
  }
4161
4278
  } catch (e) {
4162
- console.error("could not get fee: ", e);
4163
- if (options == null ? void 0 : options.fallbackOnSimulate) {
4164
- return defaultFee;
4165
- } else {
4166
- throw e;
4167
- }
4279
+ console.error("could not get fee, using default fee: ", e);
4280
+ return defaultFee;
4168
4281
  }
4169
4282
  }, [simulateFee]);
4170
4283
  const tx = (0, import_react16.useCallback)(async (msgs, options) => {
@@ -4184,11 +4297,14 @@ var useTx = (chainName) => {
4184
4297
  try {
4185
4298
  const fee = await getFee(msgs, options);
4186
4299
  setProgressTrack("Signing transaction");
4187
- const resp = await signingClient.signAndBroadcast(address, msgs, fee, (_a2 = options == null ? void 0 : options.memo) != null ? _a2 : DEFAULT_TX_MEMO);
4188
- if (resp.code === 0) {
4300
+ const broadcastResult = await signingClient.signAndBroadcast(address, msgs, fee, (_a2 = options == null ? void 0 : options.memo) != null ? _a2 : DEFAULT_TX_MEMO);
4301
+ setProgressTrack("Waiting for confirmation");
4302
+ const resp = await broadcastResult.wait();
4303
+ const txHash = (resp == null ? void 0 : resp.txhash) || broadcastResult.transactionHash;
4304
+ if ((resp == null ? void 0 : resp.code) === 0) {
4189
4305
  setProgressTrack("Transaction sent");
4190
4306
  toast.clickableSuccess("Transaction Successful" /* Successful */, () => {
4191
- openExternalLink(`${getChainExplorerURL(chainName != null ? chainName : defaultChainName)}/tx/${resp.transactionHash}`);
4307
+ openExternalLink(`${getChainExplorerURL(chainName != null ? chainName : defaultChainName)}/tx/${txHash}`);
4192
4308
  }, "View in Explorer");
4193
4309
  if (options == null ? void 0 : options.onSuccess) {
4194
4310
  options.onSuccess(resp);