@rash2x/bridge-widget 0.6.35 → 0.6.36

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.
@@ -499,6 +499,7 @@ const useTronWalletConnectStore = zustand.create(
499
499
  isConnecting: false,
500
500
  connect: null,
501
501
  disconnect: null,
502
+ cancelConnection: null,
502
503
  signTransaction: null,
503
504
  setAddress: (address) => set2({
504
505
  address,
@@ -508,6 +509,7 @@ const useTronWalletConnectStore = zustand.create(
508
509
  setActions: (actions) => set2({
509
510
  connect: actions.connect,
510
511
  disconnect: actions.disconnect,
512
+ cancelConnection: actions.cancelConnection,
511
513
  signTransaction: actions.signTransaction
512
514
  }),
513
515
  reset: () => set2({
@@ -3785,15 +3787,19 @@ function useBridgeTransaction() {
3785
3787
  txStore.setError("COMPLETION_TRACKING_FAILED");
3786
3788
  }
3787
3789
  console.error("Error tracking completion:", err);
3790
+ }).finally(() => {
3791
+ setIsProcessing(false);
3788
3792
  });
3793
+ return txResult;
3789
3794
  } else {
3795
+ setIsProcessing(false);
3790
3796
  throw new TransactionFailedError(
3791
3797
  chainKey,
3792
3798
  "Transaction hash not received from wallet"
3793
3799
  );
3794
3800
  }
3795
- return txResult;
3796
3801
  } catch (err) {
3802
+ setIsProcessing(false);
3797
3803
  if (isUserRejection(err)) {
3798
3804
  txStore.setError("TRANSACTION_REJECTED");
3799
3805
  throw new TransactionFailedError(
@@ -3809,8 +3815,6 @@ function useBridgeTransaction() {
3809
3815
  console.log(err);
3810
3816
  txStore.setError("UNKNOWN_ERROR");
3811
3817
  throw err;
3812
- } finally {
3813
- setIsProcessing(false);
3814
3818
  }
3815
3819
  };
3816
3820
  return {
@@ -6938,7 +6942,6 @@ const TokenSelectModal = ({
6938
6942
  react.useLayoutEffect(() => {
6939
6943
  const updateHeight = () => {
6940
6944
  const container2 = document.getElementById("token-select-list");
6941
- console.log("CONTAINER", container2);
6942
6945
  if (!container2) return;
6943
6946
  const height = container2.getBoundingClientRect().height;
6944
6947
  if (height > 0) {
@@ -25915,7 +25918,7 @@ class WalletConnectModal {
25915
25918
  }
25916
25919
  async initUi() {
25917
25920
  if (typeof window !== "undefined") {
25918
- await Promise.resolve().then(() => require("./index-DJbbVeMD.cjs"));
25921
+ await Promise.resolve().then(() => require("./index-B3GlyTKi.cjs"));
25919
25922
  const modal = document.createElement("wcm-modal");
25920
25923
  document.body.insertAdjacentElement("beforeend", modal);
25921
25924
  OptionsCtrl.setIsUiLoaded(true);
@@ -25960,11 +25963,13 @@ const useThemeStore = zustand.create((set2) => ({
25960
25963
  }
25961
25964
  }));
25962
25965
  const TRON_MAINNET_CHAIN_ID = "tron:0x2b6653dc";
25966
+ const CONNECTION_TIMEOUT = 6e4;
25963
25967
  function useTronWalletConnect(projectId) {
25964
25968
  const { address, isConnected, isConnecting } = useTronWalletConnectStore();
25965
25969
  const { setAddress, setIsConnecting, setActions, reset } = useTronWalletConnectStore();
25966
25970
  const providerRef = react.useRef(null);
25967
25971
  const modalRef = react.useRef(null);
25972
+ const abortControllerRef = react.useRef(null);
25968
25973
  const { onClose: closeWalletSelectModal } = useWalletSelectModal();
25969
25974
  const appliedTheme = useThemeStore((state2) => state2.appliedTheme);
25970
25975
  react.useEffect(() => {
@@ -26027,6 +26032,9 @@ function useTronWalletConnect(projectId) {
26027
26032
  };
26028
26033
  initProvider();
26029
26034
  return () => {
26035
+ if (abortControllerRef.current) {
26036
+ abortControllerRef.current.abort();
26037
+ }
26030
26038
  if (providerRef.current) {
26031
26039
  providerRef.current.disconnect();
26032
26040
  }
@@ -26053,9 +26061,14 @@ function useTronWalletConnect(projectId) {
26053
26061
  "WalletConnect not initialized. Please provide a valid project ID."
26054
26062
  );
26055
26063
  }
26064
+ if (abortControllerRef.current) {
26065
+ abortControllerRef.current.abort();
26066
+ }
26067
+ abortControllerRef.current = new AbortController();
26068
+ const abortController = abortControllerRef.current;
26056
26069
  setIsConnecting(true);
26057
26070
  try {
26058
- const session = await providerRef.current.connect({
26071
+ const connectionPromise = providerRef.current.connect({
26059
26072
  namespaces: {
26060
26073
  tron: {
26061
26074
  methods: ["tron_signTransaction", "tron_signMessage"],
@@ -26064,6 +26077,19 @@ function useTronWalletConnect(projectId) {
26064
26077
  }
26065
26078
  }
26066
26079
  });
26080
+ const timeoutPromise = new Promise((_3, reject) => {
26081
+ const timeoutId = setTimeout(() => {
26082
+ reject(new Error("Connection timeout - please try again"));
26083
+ }, CONNECTION_TIMEOUT);
26084
+ abortController.signal.addEventListener("abort", () => {
26085
+ clearTimeout(timeoutId);
26086
+ reject(new Error("Connection cancelled"));
26087
+ });
26088
+ });
26089
+ const session = await Promise.race([connectionPromise, timeoutPromise]);
26090
+ if (abortController.signal.aborted) {
26091
+ throw new Error("Connection cancelled");
26092
+ }
26067
26093
  if (session) {
26068
26094
  const accounts = session.namespaces?.tron?.accounts || [];
26069
26095
  if (accounts.length > 0) {
@@ -26088,8 +26114,18 @@ function useTronWalletConnect(projectId) {
26088
26114
  throw error;
26089
26115
  } finally {
26090
26116
  setIsConnecting(false);
26117
+ abortControllerRef.current = null;
26091
26118
  }
26092
26119
  }, [setAddress, setIsConnecting]);
26120
+ const cancelConnection = react.useCallback(() => {
26121
+ if (abortControllerRef.current) {
26122
+ abortControllerRef.current.abort();
26123
+ console.log("TRON WalletConnect connection cancelled");
26124
+ }
26125
+ if (modalRef.current) {
26126
+ modalRef.current.closeModal();
26127
+ }
26128
+ }, []);
26093
26129
  const disconnect = react.useCallback(async () => {
26094
26130
  if (!providerRef.current) return;
26095
26131
  try {
@@ -26126,15 +26162,17 @@ function useTronWalletConnect(projectId) {
26126
26162
  setActions({
26127
26163
  connect,
26128
26164
  disconnect,
26165
+ cancelConnection,
26129
26166
  signTransaction
26130
26167
  });
26131
- }, [connect, disconnect, signTransaction, setActions]);
26168
+ }, [connect, disconnect, cancelConnection, signTransaction, setActions]);
26132
26169
  return {
26133
26170
  address,
26134
26171
  isConnected,
26135
26172
  isConnecting,
26136
26173
  connect,
26137
26174
  disconnect,
26175
+ cancelConnection,
26138
26176
  signTransaction
26139
26177
  };
26140
26178
  }
@@ -26637,4 +26675,4 @@ exports.useSettingsStore = useSettingsStore;
26637
26675
  exports.useSwapModel = useSwapModel;
26638
26676
  exports.useTokensStore = useTokensStore;
26639
26677
  exports.useTransactionStore = useTransactionStore;
26640
- //# sourceMappingURL=index-BXp-N4UF.cjs.map
26678
+ //# sourceMappingURL=index-ogZzdWIQ.cjs.map