@kimafinance/kima-transaction-widget 1.3.11 → 1.3.13

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.cjs CHANGED
@@ -2750,12 +2750,14 @@ function useEvmAllowance() {
2750
2750
  const appkitAccountInfo = (0, import_react79.useAppKitAccount)();
2751
2751
  const sourceChain = (0, import_react_redux5.useSelector)(selectSourceChain);
2752
2752
  const networkOption = (0, import_react_redux5.useSelector)(selectNetworkOption);
2753
- const { totalFeeUsd, allowanceAmount, decimals } = (0, import_react_redux5.useSelector)(selectServiceFee);
2753
+ const { totalFeeUsd, allowanceAmount, submitAmount, decimals } = (0, import_react_redux5.useSelector)(selectServiceFee);
2754
2754
  const selectedCoin = (0, import_react_redux5.useSelector)(selectSourceCurrency);
2755
2755
  const tokenOptions = (0, import_react_redux5.useSelector)(selectTokenOptions);
2756
2756
  const backendUrl = (0, import_react_redux5.useSelector)(selectBackendUrl);
2757
2757
  const feeDeduct = (0, import_react_redux5.useSelector)(selectFeeDeduct);
2758
- const allowanceNumber = Number((0, import_ethers6.formatUnits)(allowanceAmount ?? "0", decimals));
2758
+ const allowanceNumber = Number(
2759
+ (0, import_ethers6.formatUnits)(feeDeduct ? submitAmount : allowanceAmount ?? "0", decimals)
2760
+ );
2759
2761
  const amount = (0, import_react_redux5.useSelector)(selectAmount);
2760
2762
  const { pools } = useGetPools_default(backendUrl, networkOption);
2761
2763
  const walletAddress = externalProvider?.signer?.address || appkitAccountInfo?.address;
@@ -3057,10 +3059,13 @@ var import_web38 = require("@solana/web3.js");
3057
3059
  var import_ethers7 = require("ethers");
3058
3060
  function useSolanaAllowance() {
3059
3061
  const sourceChain = (0, import_react_redux7.useSelector)(selectSourceChain);
3060
- const { allowanceAmount, decimals } = (0, import_react_redux7.useSelector)(selectServiceFee);
3062
+ const { allowanceAmount, submitAmount, decimals } = (0, import_react_redux7.useSelector)(selectServiceFee);
3063
+ const feeDeduct = (0, import_react_redux7.useSelector)(selectFeeDeduct);
3061
3064
  const backendUrl = (0, import_react_redux7.useSelector)(selectBackendUrl);
3062
3065
  const networkOption = (0, import_react_redux7.useSelector)(selectNetworkOption);
3063
- const allowanceNumber = Number((0, import_ethers7.formatUnits)(allowanceAmount ?? "0", decimals));
3066
+ const allowanceNumber = Number(
3067
+ (0, import_ethers7.formatUnits)(feeDeduct ? submitAmount : allowanceAmount ?? "0", decimals)
3068
+ );
3064
3069
  const { externalProvider } = useKimaContext();
3065
3070
  const { connection: internalConnection } = (0, import_wallet_adapter_react3.useConnection)();
3066
3071
  const {
@@ -3644,11 +3649,14 @@ function useTronAllowance() {
3644
3649
  const sourceChain = (0, import_react_redux11.useSelector)(selectSourceChain);
3645
3650
  const networkOption = (0, import_react_redux11.useSelector)(selectNetworkOption);
3646
3651
  const backendUrl = (0, import_react_redux11.useSelector)(selectBackendUrl);
3647
- const { allowanceAmount, decimals } = (0, import_react_redux11.useSelector)(selectServiceFee);
3652
+ const { allowanceAmount, submitAmount, decimals } = (0, import_react_redux11.useSelector)(selectServiceFee);
3648
3653
  (0, import_tronwallet_adapter_react_hooks3.useWallet)();
3649
3654
  const selectedCoin = (0, import_react_redux11.useSelector)(selectSourceCurrency);
3650
3655
  const tokenOptions = (0, import_react_redux11.useSelector)(selectTokenOptions);
3651
- const allowanceNumber = Number((0, import_ethers9.formatUnits)(allowanceAmount ?? "0", decimals));
3656
+ const feeDeduct = (0, import_react_redux11.useSelector)(selectFeeDeduct);
3657
+ const allowanceNumber = Number(
3658
+ (0, import_ethers9.formatUnits)(feeDeduct ? submitAmount : allowanceAmount ?? "0", decimals)
3659
+ );
3652
3660
  const { pools } = useGetPools_default(backendUrl, networkOption);
3653
3661
  const {
3654
3662
  address: internalUserAddress,
@@ -4762,7 +4770,13 @@ var StepBox = ({ step, errorStep, loadingStep, data }) => {
4762
4770
  },
4763
4771
  getShortenedAddress(data?.tssPullHash || "")
4764
4772
  ), /* @__PURE__ */ import_react115.default.createElement(CopyButton_default, { text: data?.tssPullHash || "" }))
4765
- ) : null, index === 3 && data?.tssReleaseHash ? /* @__PURE__ */ import_react115.default.createElement("div", { className: `info-item ${theme.colorMode} target-chain` }, /* @__PURE__ */ import_react115.default.createElement(ChainIcon, { symbol: data.targetChain }), /* @__PURE__ */ import_react115.default.createElement("p", { className: "chain-name" }, targetChain?.name, " TX ID:"), /* @__PURE__ */ import_react115.default.createElement("p", null, /* @__PURE__ */ import_react115.default.createElement(
4773
+ ) : null, index === 3 && data?.tssRefundHash ? /* @__PURE__ */ import_react115.default.createElement("div", { className: `info-item ${theme.colorMode} target-chain` }, /* @__PURE__ */ import_react115.default.createElement(ChainIcon, { symbol: data.sourceChain }), /* @__PURE__ */ import_react115.default.createElement("p", { className: "chain-name" }, sourceChain?.name, " TX ID:"), /* @__PURE__ */ import_react115.default.createElement("p", null, /* @__PURE__ */ import_react115.default.createElement(
4774
+ ExternalLink_default,
4775
+ {
4776
+ to: `${sourceChain?.blockExplorers?.default.url}/${data?.sourceChain === "TRX" /* TRON */ ? "transaction" : "tx"}/${data?.tssRefundHash}${data?.sourceChain === "SOL" /* SOLANA */ && networkOption === "testnet" /* testnet */ ? "?cluster=devnet" : ""}`
4777
+ },
4778
+ getShortenedAddress(data?.tssRefundHash || "")
4779
+ ), /* @__PURE__ */ import_react115.default.createElement(CopyButton_default, { text: data?.tssRefundHash || "" }))) : null, index === 3 && data?.tssReleaseHash ? /* @__PURE__ */ import_react115.default.createElement("div", { className: `info-item ${theme.colorMode} target-chain` }, /* @__PURE__ */ import_react115.default.createElement(ChainIcon, { symbol: data.targetChain }), /* @__PURE__ */ import_react115.default.createElement("p", { className: "chain-name" }, targetChain?.name, " TX ID:"), /* @__PURE__ */ import_react115.default.createElement("p", null, /* @__PURE__ */ import_react115.default.createElement(
4766
4780
  ExternalLink_default,
4767
4781
  {
4768
4782
  to: `${targetChain?.blockExplorers?.default.url}/${data?.targetChain === "TRX" /* TRON */ ? "transaction" : "tx"}/${data?.tssReleaseHash}${data?.targetChain === "SOL" /* SOLANA */ && networkOption === "testnet" /* testnet */ ? "?cluster=devnet" : ""}`
@@ -4848,6 +4862,7 @@ var emptyStatus = {
4848
4862
  targetChain: "",
4849
4863
  tssPullHash: "",
4850
4864
  tssReleaseHash: "",
4865
+ tssRefundHash: "",
4851
4866
  sourceSymbol: "",
4852
4867
  targetSymbol: "",
4853
4868
  amount: "",
@@ -4856,7 +4871,7 @@ var emptyStatus = {
4856
4871
  };
4857
4872
  var selectStatus = (response) => {
4858
4873
  if ("liquidity_transaction_data" in response.data) {
4859
- const data2 = response.data.liquidity_transaction_data[0];
4874
+ const data2 = response.data.liquidity_transaction_data;
4860
4875
  if (!data2) return emptyStatus;
4861
4876
  return {
4862
4877
  status: data2.txstatus,
@@ -4864,6 +4879,7 @@ var selectStatus = (response) => {
4864
4879
  targetChain: data2.chain,
4865
4880
  tssPullHash: data2.releasehash,
4866
4881
  tssReleaseHash: data2.releasehash,
4882
+ tssRefundHash: data2.refundhash,
4867
4883
  failReason: data2.failreason,
4868
4884
  amount: data2.amount,
4869
4885
  sourceSymbol: data2.symbol,
@@ -4871,7 +4887,7 @@ var selectStatus = (response) => {
4871
4887
  kimaTxHash: data2.kimahash
4872
4888
  };
4873
4889
  }
4874
- const data = response.data.transaction_data[0];
4890
+ const data = response.data.transaction_data;
4875
4891
  if (!data) return emptyStatus;
4876
4892
  return {
4877
4893
  status: data.txstatus,
@@ -4879,6 +4895,7 @@ var selectStatus = (response) => {
4879
4895
  targetChain: data.targetchain,
4880
4896
  tssPullHash: data.pullhash,
4881
4897
  tssReleaseHash: data.releasehash,
4898
+ tssRefundHash: data.refundhash,
4882
4899
  failReason: data.failreason,
4883
4900
  amount: data.amount,
4884
4901
  sourceSymbol: data.originsymbol,
@@ -4892,7 +4909,9 @@ var isFinished = (data) => {
4892
4909
  "Completed" /* COMPLETED */,
4893
4910
  "FailedToPull" /* FAILEDTOPULL */,
4894
4911
  "FailedToPay" /* FAILEDTOPAY */,
4895
- "UnAvailable" /* UNAVAILABLE */
4912
+ "UnAvailable" /* UNAVAILABLE */,
4913
+ "RefundFailed" /* REFUNDFAILED */,
4914
+ "RefundCompleted" /* REFUNDCOMPLETED */
4896
4915
  ].includes(data.status);
4897
4916
  };
4898
4917
  var getTxData = async ({
@@ -4925,6 +4944,7 @@ var POLLING_INTERVAL_MS = 1e3 * 10;
4925
4944
  var useGetTxData = (txId, dAppOption, backendUrl) => {
4926
4945
  const refPollForUpdates = (0, import_react118.useRef)(false);
4927
4946
  const isLP = dAppOption === "LPAdd" /* LPAdd */ || dAppOption === "LPDrain" /* LPDrain */;
4947
+ const validTxId = typeof txId === "number" ? txId > 0 : txId.toString().length > 0;
4928
4948
  const result = (0, import_react_query12.useQuery)({
4929
4949
  queryKey: ["txData", txId, dAppOption],
4930
4950
  queryFn: async () => await getTxData({ txId, isLP, backendUrl, refPollForUpdates }),
@@ -4932,7 +4952,7 @@ var useGetTxData = (txId, dAppOption, backendUrl) => {
4932
4952
  refetchInterval: refPollForUpdates.current ? POLLING_INTERVAL_MS : false,
4933
4953
  // 10 sec
4934
4954
  staleTime: POLLING_INTERVAL_MS,
4935
- enabled: (Number(txId) > 0 || txId.toString().length > 0) && !!dAppOption && !!backendUrl
4955
+ enabled: validTxId && !!dAppOption && !!backendUrl
4936
4956
  });
4937
4957
  return result;
4938
4958
  };
@@ -5078,12 +5098,37 @@ var TransactionWidget = ({ theme }) => {
5078
5098
  console.log(data.failReason);
5079
5099
  import_react_hot_toast3.toast.error("Unavailable", { icon: /* @__PURE__ */ import_react121.default.createElement(Error_default, null) });
5080
5100
  setErrorMessage("Unavailable");
5081
- } else if (status === "KeySigned" /* KEYSIGNED */) {
5101
+ } else if (status === "Paid" /* PAID */) {
5082
5102
  setStep(3);
5083
5103
  setLoadingStep(3);
5084
- } else if (status === "Paid" /* PAID */) {
5104
+ } else if (status === "RefundStart" /* REFUNDSTART */) {
5085
5105
  setStep(3);
5086
5106
  setLoadingStep(3);
5107
+ import_react_hot_toast3.toast.error(
5108
+ "Failed to release tokens to target! Starting refund process.",
5109
+ {
5110
+ icon: /* @__PURE__ */ import_react121.default.createElement(Error_default, null)
5111
+ }
5112
+ );
5113
+ setErrorMessage(
5114
+ "Failed to release tokens to target! Starting refund process."
5115
+ );
5116
+ } else if (status === "RefundFailed" /* REFUNDFAILED */) {
5117
+ setStep(3);
5118
+ setErrorStep(3);
5119
+ setLoadingStep(-1);
5120
+ import_react_hot_toast3.toast.error("Failed to refund tokens to source!", {
5121
+ icon: /* @__PURE__ */ import_react121.default.createElement(Error_default, null)
5122
+ });
5123
+ setErrorMessage("Failed to refund tokens to source!");
5124
+ } else if (status === "RefundCompleted" /* REFUNDCOMPLETED */) {
5125
+ setStep(4);
5126
+ setErrorStep(3);
5127
+ setLoadingStep(-1);
5128
+ import_react_hot_toast3.toast.success("Refund completed!", {
5129
+ icon: /* @__PURE__ */ import_react121.default.createElement(Error_default, null)
5130
+ });
5131
+ setErrorMessage("Refund completed!");
5087
5132
  } else if (status === "FailedToPay" /* FAILEDTOPAY */) {
5088
5133
  setStep(3);
5089
5134
  setErrorStep(3);