@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.js +121 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +154 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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,10 +4158,10 @@ var useToast = () => {
|
|
|
4059
4158
|
};
|
|
4060
4159
|
|
|
4061
4160
|
// src/hooks/useTx.tsx
|
|
4161
|
+
var import_tx13 = require("@bze/bzejs/cosmos/tx/v1beta1/tx");
|
|
4062
4162
|
var import_react15 = require("@interchain-kit/react");
|
|
4063
4163
|
var import_bignumber13 = __toESM(require("bignumber.js"));
|
|
4064
4164
|
var import_react16 = require("react");
|
|
4065
|
-
var coins2 = (amount, denom) => [{ amount: String(amount), denom }];
|
|
4066
4165
|
var TxStatus = /* @__PURE__ */ ((TxStatus2) => {
|
|
4067
4166
|
TxStatus2["Failed"] = "Transaction Failed";
|
|
4068
4167
|
TxStatus2["Successful"] = "Transaction Successful";
|
|
@@ -4070,7 +4169,7 @@ var TxStatus = /* @__PURE__ */ ((TxStatus2) => {
|
|
|
4070
4169
|
return TxStatus2;
|
|
4071
4170
|
})(TxStatus || {});
|
|
4072
4171
|
var defaultFee = {
|
|
4073
|
-
amount:
|
|
4172
|
+
amount: coins(2e4, getChainNativeAssetDenom()),
|
|
4074
4173
|
gas: "500000"
|
|
4075
4174
|
};
|
|
4076
4175
|
var useSDKTx = (chainName) => {
|
|
@@ -4110,13 +4209,24 @@ var useTx = (chainName) => {
|
|
|
4110
4209
|
return isSigningClientReady;
|
|
4111
4210
|
}, [isSigningClientReady, signingClientError]);
|
|
4112
4211
|
const simulateFee = (0, import_react16.useCallback)(async (messages, memo) => {
|
|
4212
|
+
var _a2;
|
|
4113
4213
|
const gasPrice = 0.02;
|
|
4114
4214
|
const nativeDenom = getChainNativeAssetDenom();
|
|
4115
|
-
const
|
|
4215
|
+
const signer = signingClient;
|
|
4216
|
+
const encodedMessages = messages.map(({ typeUrl, value }) => {
|
|
4217
|
+
const encoder = signer.getEncoder(typeUrl);
|
|
4218
|
+
const encodedWriter = encoder.encode(value);
|
|
4219
|
+
const encodedValue = typeof (encodedWriter == null ? void 0 : encodedWriter.finish) === "function" ? encodedWriter.finish() : encodedWriter;
|
|
4220
|
+
return { typeUrl, value: encodedValue };
|
|
4221
|
+
});
|
|
4222
|
+
const txBody = import_tx13.TxBody.fromPartial({ messages: encodedMessages, memo: memo != null ? memo : "" });
|
|
4223
|
+
const signerInfo = import_tx13.SignerInfo.fromPartial({ modeInfo: { single: { mode: 1 } }, sequence: BigInt(0) });
|
|
4224
|
+
const { gasInfo } = await signer.simulateByTxBody(txBody, [signerInfo]);
|
|
4225
|
+
const gasEstimated = Number((_a2 = gasInfo == null ? void 0 : gasInfo.gasUsed) != null ? _a2 : BigInt(0));
|
|
4116
4226
|
const gasAmount = (0, import_bignumber13.default)(gasEstimated).multipliedBy(1.5);
|
|
4117
4227
|
const gasPayment = gasAmount.multipliedBy(gasPrice);
|
|
4118
4228
|
const nativeFee = {
|
|
4119
|
-
amount:
|
|
4229
|
+
amount: coins(gasPayment.toFixed(0).toString(), nativeDenom),
|
|
4120
4230
|
gas: gasAmount.toFixed(0)
|
|
4121
4231
|
};
|
|
4122
4232
|
if (feeDenom === nativeDenom) {
|
|
@@ -4135,7 +4245,7 @@ var useTx = (chainName) => {
|
|
|
4135
4245
|
expectedAmount = toBigNumber(1).dividedBy(pool.fee).integerValue(import_bignumber13.default.ROUND_CEIL);
|
|
4136
4246
|
}
|
|
4137
4247
|
return {
|
|
4138
|
-
amount:
|
|
4248
|
+
amount: coins(expectedAmount.toFixed(0).toString(), feeDenom),
|
|
4139
4249
|
gas: gasAmount.multipliedBy(1.5).toFixed(0)
|
|
4140
4250
|
};
|
|
4141
4251
|
}, [signingClient, address, feeDenom, getDenomsPool]);
|
|
@@ -4173,11 +4283,14 @@ var useTx = (chainName) => {
|
|
|
4173
4283
|
try {
|
|
4174
4284
|
const fee = await getFee(msgs, options);
|
|
4175
4285
|
setProgressTrack("Signing transaction");
|
|
4176
|
-
const
|
|
4177
|
-
|
|
4286
|
+
const broadcastResult = await signingClient.signAndBroadcast(address, msgs, fee, (_a2 = options == null ? void 0 : options.memo) != null ? _a2 : DEFAULT_TX_MEMO);
|
|
4287
|
+
setProgressTrack("Waiting for confirmation");
|
|
4288
|
+
const resp = await broadcastResult.wait();
|
|
4289
|
+
const txHash = (resp == null ? void 0 : resp.txhash) || broadcastResult.transactionHash;
|
|
4290
|
+
if ((resp == null ? void 0 : resp.code) === 0) {
|
|
4178
4291
|
setProgressTrack("Transaction sent");
|
|
4179
4292
|
toast.clickableSuccess("Transaction Successful" /* Successful */, () => {
|
|
4180
|
-
openExternalLink(`${getChainExplorerURL(chainName != null ? chainName : defaultChainName)}/tx/${
|
|
4293
|
+
openExternalLink(`${getChainExplorerURL(chainName != null ? chainName : defaultChainName)}/tx/${txHash}`);
|
|
4181
4294
|
}, "View in Explorer");
|
|
4182
4295
|
if (options == null ? void 0 : options.onSuccess) {
|
|
4183
4296
|
options.onSuccess(resp);
|