@bze/bze-ui-kit 1.0.1 → 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.d.mts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +50 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -719,6 +719,36 @@ var openExternalLink = (url) => {
|
|
|
719
719
|
window.open(url, "_blank", "noopener,noreferrer");
|
|
720
720
|
};
|
|
721
721
|
|
|
722
|
+
// src/utils/coins.ts
|
|
723
|
+
var coin = (amount, denom) => {
|
|
724
|
+
let outAmount;
|
|
725
|
+
if (typeof amount === "number") {
|
|
726
|
+
if (!Number.isInteger(amount) || amount < 0 || amount > Number.MAX_SAFE_INTEGER) {
|
|
727
|
+
throw new Error("Given amount is not a safe integer. Consider using a string instead to overcome the limitations of JS numbers.");
|
|
728
|
+
}
|
|
729
|
+
outAmount = String(amount);
|
|
730
|
+
} else {
|
|
731
|
+
if (!amount.match(/^[0-9]+$/)) {
|
|
732
|
+
throw new Error("Invalid unsigned integer string format");
|
|
733
|
+
}
|
|
734
|
+
outAmount = amount.replace(/^0*/, "") || "0";
|
|
735
|
+
}
|
|
736
|
+
return { amount: outAmount, denom };
|
|
737
|
+
};
|
|
738
|
+
var coins = (amount, denom) => {
|
|
739
|
+
return [coin(amount, denom)];
|
|
740
|
+
};
|
|
741
|
+
var parseCoins = (input) => {
|
|
742
|
+
return input.replace(/\s/g, "").split(",").filter(Boolean).map((part) => {
|
|
743
|
+
const match = part.match(/^([0-9]+)([a-zA-Z][a-zA-Z0-9/:._-]{2,127})$/);
|
|
744
|
+
if (!match) throw new Error("Got an invalid coin string");
|
|
745
|
+
return {
|
|
746
|
+
amount: match[1].replace(/^0+/, "") || "0",
|
|
747
|
+
denom: match[2]
|
|
748
|
+
};
|
|
749
|
+
});
|
|
750
|
+
};
|
|
751
|
+
|
|
722
752
|
// src/utils/ibc.ts
|
|
723
753
|
import BigNumber3 from "bignumber.js";
|
|
724
754
|
var canDepositFromIBC = (ibcData2) => {
|
|
@@ -3751,10 +3781,10 @@ var useToast = () => {
|
|
|
3751
3781
|
};
|
|
3752
3782
|
|
|
3753
3783
|
// src/hooks/useTx.tsx
|
|
3784
|
+
import { TxBody, SignerInfo } from "@bze/bzejs/cosmos/tx/v1beta1/tx";
|
|
3754
3785
|
import { useChain as useChain2 } from "@interchain-kit/react";
|
|
3755
3786
|
import BigNumber13 from "bignumber.js";
|
|
3756
3787
|
import { useCallback as useCallback11, useMemo as useMemo11, useState as useState3 } from "react";
|
|
3757
|
-
var coins = (amount, denom) => [{ amount: String(amount), denom }];
|
|
3758
3788
|
var TxStatus = /* @__PURE__ */ ((TxStatus2) => {
|
|
3759
3789
|
TxStatus2["Failed"] = "Transaction Failed";
|
|
3760
3790
|
TxStatus2["Successful"] = "Transaction Successful";
|
|
@@ -3802,9 +3832,20 @@ var useTx = (chainName) => {
|
|
|
3802
3832
|
return isSigningClientReady;
|
|
3803
3833
|
}, [isSigningClientReady, signingClientError]);
|
|
3804
3834
|
const simulateFee = useCallback11(async (messages, memo) => {
|
|
3835
|
+
var _a2;
|
|
3805
3836
|
const gasPrice = 0.02;
|
|
3806
3837
|
const nativeDenom = getChainNativeAssetDenom();
|
|
3807
|
-
const
|
|
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));
|
|
3808
3849
|
const gasAmount = BigNumber13(gasEstimated).multipliedBy(1.5);
|
|
3809
3850
|
const gasPayment = gasAmount.multipliedBy(gasPrice);
|
|
3810
3851
|
const nativeFee = {
|
|
@@ -4470,15 +4511,15 @@ import { WalletState } from "@interchain-kit/core";
|
|
|
4470
4511
|
import BigNumber14 from "bignumber.js";
|
|
4471
4512
|
import { cosmos } from "@bze/bzejs";
|
|
4472
4513
|
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
4473
|
-
var validateAmount = (amount,
|
|
4474
|
-
if (!
|
|
4514
|
+
var validateAmount = (amount, coin2, onError) => {
|
|
4515
|
+
if (!coin2) return;
|
|
4475
4516
|
if (amount === "") return;
|
|
4476
4517
|
const amountNumber = BigNumber14(amount);
|
|
4477
4518
|
if (amountNumber.isNaN()) {
|
|
4478
4519
|
onError("Invalid amount");
|
|
4479
4520
|
return;
|
|
4480
4521
|
}
|
|
4481
|
-
const coinBalance = uAmountToBigNumberAmount(
|
|
4522
|
+
const coinBalance = uAmountToBigNumberAmount(coin2.amount, coin2.decimals);
|
|
4482
4523
|
if (coinBalance.isLessThan(amount)) {
|
|
4483
4524
|
onError("Insufficient balance");
|
|
4484
4525
|
} else {
|
|
@@ -5121,6 +5162,7 @@ export {
|
|
|
5121
5162
|
canSendToIBC,
|
|
5122
5163
|
cancelDebounce,
|
|
5123
5164
|
checkAddressWonRaffle,
|
|
5165
|
+
coins,
|
|
5124
5166
|
convertToWebSocketUrl,
|
|
5125
5167
|
counterpartyChainForChannel,
|
|
5126
5168
|
createMarketId,
|
|
@@ -5252,6 +5294,7 @@ export {
|
|
|
5252
5294
|
keplrSuggestChain,
|
|
5253
5295
|
mapEventAttributes,
|
|
5254
5296
|
openExternalLink,
|
|
5297
|
+
parseCoins,
|
|
5255
5298
|
parseUnbondingDays,
|
|
5256
5299
|
poolIdFromPoolDenom,
|
|
5257
5300
|
prettyAmount,
|