@rash2x/bridge-widget 0.8.6 → 0.8.8

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.
@@ -1071,6 +1071,7 @@ const useTokensStore = create((set2) => ({
1071
1071
  });
1072
1072
  }
1073
1073
  }));
1074
+ const STARGATE_API_BASE_URL = "https://stargate-archive.vercel.app/api/";
1074
1075
  const ALLOWED_TO_CHAINS = /* @__PURE__ */ new Set([
1075
1076
  "ethereum",
1076
1077
  "manta",
@@ -1115,7 +1116,7 @@ function isAllowedToChain(chainKey) {
1115
1116
  return ALLOWED_TO_CHAINS.has(chainKey);
1116
1117
  }
1117
1118
  async function getChains() {
1118
- const res = await fetch("https://stargate.finance/api/v1/chains", {
1119
+ const res = await fetch(`${STARGATE_API_BASE_URL}v1/chains`, {
1119
1120
  credentials: "same-origin"
1120
1121
  });
1121
1122
  if (!res.ok) {
@@ -1126,7 +1127,7 @@ async function getChains() {
1126
1127
  return all.filter((c2) => ALLOWED_TO_CHAINS.has(c2.chainKey));
1127
1128
  }
1128
1129
  async function getTokens() {
1129
- const res = await fetch("https://stargate.finance/api/v1/tokens", {
1130
+ const res = await fetch(`${STARGATE_API_BASE_URL}v1/tokens`, {
1130
1131
  credentials: "same-origin"
1131
1132
  });
1132
1133
  if (!res.ok) {
@@ -1137,7 +1138,7 @@ async function getTokens() {
1137
1138
  return tokens.map(normalizeTokenSymbol);
1138
1139
  }
1139
1140
  async function getDestTokens(srcChainKey, srcTokenAddr) {
1140
- const url = new URL("https://stargate.finance/api/v1/tokens");
1141
+ const url = new URL(`${STARGATE_API_BASE_URL}v1/tokens`);
1141
1142
  url.searchParams.set("srcChainKey", srcChainKey);
1142
1143
  url.searchParams.set("srcToken", srcTokenAddr);
1143
1144
  const res = await fetch(url.toString(), { credentials: "omit" });
@@ -1661,6 +1662,7 @@ const WalletInlineButton = ({
1661
1662
  const connection = chainRegistry.getStrategyByType(walletType);
1662
1663
  const account = connection?.getAccount();
1663
1664
  const isConnected = connection?.isConnected();
1665
+ const isReconnecting = connection?.isConnecting();
1664
1666
  const error = connection?.getError();
1665
1667
  const availableConnections = useMemo(
1666
1668
  () => connection?.getAvailableConnections() ?? [],
@@ -1684,10 +1686,11 @@ const WalletInlineButton = ({
1684
1686
  }, [onOpen, addressType]);
1685
1687
  const buttonText = useMemo(() => {
1686
1688
  if (isConnected && account) return formatAddress(account);
1689
+ if (isReconnecting) return t2("wallets.reconnecting") ?? "Reconnecting...";
1687
1690
  if (wallet === "ton") return t2("wallets.addTonWallet");
1688
1691
  if (wallet === "tronlink") return t2("wallets.addTronWallet");
1689
1692
  return t2("wallets.addEvmWallet");
1690
- }, [wallet, isConnected, account, t2]);
1693
+ }, [wallet, isConnected, isReconnecting, account, t2]);
1691
1694
  const connectedIcon = useMemo(() => {
1692
1695
  if (!isConnected) return null;
1693
1696
  if (walletType === "tron" && activeTronConnection) {
@@ -2258,7 +2261,7 @@ async function fetchQuotes(req) {
2258
2261
  if (req.dstNativeAmount && req.dstNativeAmount !== "0")
2259
2262
  params.dstNativeAmount = req.dstNativeAmount;
2260
2263
  if (req.slippage && req.slippage > 0) params.slippage = String(req.slippage);
2261
- const url = `https://stargate.finance/api/v1/quotes?${new URLSearchParams(
2264
+ const url = `${STARGATE_API_BASE_URL}v1/quotes?${new URLSearchParams(
2262
2265
  params
2263
2266
  ).toString()}`;
2264
2267
  const res = await fetch(url);
@@ -4464,9 +4467,9 @@ async function getDeliveryStatus(params) {
4464
4467
  if (params.dstChainKey) query.set("dstChainKey", params.dstChainKey);
4465
4468
  query.set("srcTxHash", params.srcTxHash);
4466
4469
  const bases2 = [
4467
- `https://stargate.finance/api/v1/transactions?${query.toString()}`,
4468
- `https://stargate.finance/api/v1/txStatus?${query.toString()}`,
4469
- `https://stargate.finance/api/v1/messageStatus?${query.toString()}`
4470
+ `${STARGATE_API_BASE_URL}v1/transactions?${query.toString()}`,
4471
+ `${STARGATE_API_BASE_URL}v1/txStatus?${query.toString()}`,
4472
+ `${STARGATE_API_BASE_URL}v1/messageStatus?${query.toString()}`
4470
4473
  ];
4471
4474
  for (const url of bases2) {
4472
4475
  const json = await tryFetch(url);
@@ -4623,7 +4626,7 @@ function useBridgeTransaction() {
4623
4626
  const txStore = useTransactionStore();
4624
4627
  const gas = useGasEstimate();
4625
4628
  const srcToken = useMemo(
4626
- () => resolveBridgeSourceTokenOnChainFromMatrix(
4629
+ () => resolveTokenOnChainFromMatrix$1(
4627
4630
  assetMatrix,
4628
4631
  selectedAssetSymbol,
4629
4632
  quote?.srcChainKey
@@ -4631,7 +4634,7 @@ function useBridgeTransaction() {
4631
4634
  [assetMatrix, selectedAssetSymbol, quote?.srcChainKey]
4632
4635
  );
4633
4636
  const dstToken = useMemo(
4634
- () => resolveBridgeDestinationTokenOnChainFromMatrix(
4637
+ () => resolveTokenOnChainFromMatrix$1(
4635
4638
  assetMatrix,
4636
4639
  selectedAssetSymbol,
4637
4640
  quote?.dstChainKey
@@ -5289,7 +5292,7 @@ const WalletSelectModal = () => {
5289
5292
  const { t: t2 } = useBridgeTranslation();
5290
5293
  const { isOpen, onClose } = useWalletSelectModal();
5291
5294
  const { connectors } = useConnect();
5292
- const { address: evmAddress, connector: connectedConnector } = useAccount();
5295
+ const { address: evmAddress, connector: connectedConnector, isReconnecting: evmIsReconnecting } = useAccount();
5293
5296
  const { chainRegistry } = useChainStrategies();
5294
5297
  const tonWallet = chainRegistry.getStrategyByType(CHAIN_TYPES.TON);
5295
5298
  const metaMaskWallet = chainRegistry.getStrategyByType(CHAIN_TYPES.EVM);
@@ -5333,6 +5336,14 @@ const WalletSelectModal = () => {
5333
5336
  address: evmAddress,
5334
5337
  onDisconnect: () => metaMaskWallet?.disconnect()
5335
5338
  });
5339
+ } else if (evmIsReconnecting) {
5340
+ evmConnectedWallets.push({
5341
+ id: "walletConnect",
5342
+ name: t2("wallets.reconnecting") || "Reconnecting...",
5343
+ icon: WalletConnectIcon,
5344
+ address: "...",
5345
+ onDisconnect: () => metaMaskWallet?.disconnect()
5346
+ });
5336
5347
  }
5337
5348
  const tronConnectedWallets = [];
5338
5349
  tronConnections.forEach((connection) => {
@@ -5354,7 +5365,7 @@ const WalletSelectModal = () => {
5354
5365
  enabled: true
5355
5366
  }
5356
5367
  ];
5357
- const evmWallets = evmConnectedWallets.length > 0 ? [] : connectors.filter(
5368
+ const evmWallets = evmConnectedWallets.length > 0 || evmIsReconnecting ? [] : connectors.filter(
5358
5369
  (connector) => connector.id === "walletConnect" || connector.id === "metaMaskSDK"
5359
5370
  ).map((connector) => ({
5360
5371
  id: connector.id,
@@ -5886,7 +5897,7 @@ class EvmChainStrategy {
5886
5897
  return !!this.config.evmIsConnected;
5887
5898
  }
5888
5899
  isConnecting() {
5889
- return false;
5900
+ return !!this.config.evmIsReconnecting;
5890
5901
  }
5891
5902
  getAccount() {
5892
5903
  return this.config.evmAddress || null;
@@ -5903,15 +5914,49 @@ class EvmChainStrategy {
5903
5914
  getClient() {
5904
5915
  return this.walletClient;
5905
5916
  }
5906
- async getBalances(address, tokens) {
5907
- const chainKey = tokens[0]?.chainKey;
5917
+ resolvePublicClientForChain(chainKey) {
5908
5918
  let client = this.publicClient;
5909
- if (chainKey && this.config.getPublicClientForChain && this.config.chainKeyToId) {
5910
- const chainId = this.config.chainKeyToId[chainKey.toLowerCase()];
5911
- if (chainId) {
5912
- client = this.config.getPublicClientForChain(chainId) ?? client;
5913
- }
5919
+ if (!chainKey || !this.config.getPublicClientForChain || !this.config.chainKeyToId) {
5920
+ return client;
5921
+ }
5922
+ const chainId = this.config.chainKeyToId[chainKey.toLowerCase()];
5923
+ if (!chainId) {
5924
+ return client;
5925
+ }
5926
+ client = this.config.getPublicClientForChain(chainId) ?? client;
5927
+ return client;
5928
+ }
5929
+ getRpcErrorDetails(error) {
5930
+ if (error instanceof Error) {
5931
+ const rpcError = error;
5932
+ return {
5933
+ code: rpcError.code,
5934
+ message: rpcError.message,
5935
+ shortMessage: rpcError.shortMessage,
5936
+ details: rpcError.details
5937
+ };
5938
+ }
5939
+ if (typeof error === "object" && error !== null) {
5940
+ const candidate = error;
5941
+ return {
5942
+ code: typeof candidate.code === "number" ? candidate.code : void 0,
5943
+ message: typeof candidate.message === "string" ? candidate.message : String(error),
5944
+ shortMessage: typeof candidate.shortMessage === "string" ? candidate.shortMessage : void 0,
5945
+ details: typeof candidate.details === "string" ? candidate.details : void 0
5946
+ };
5914
5947
  }
5948
+ return { message: String(error) };
5949
+ }
5950
+ logRpcWarning(context, error, extra) {
5951
+ const rpcError = this.getRpcErrorDetails(error);
5952
+ console.warn(`[evm] ${context}`, {
5953
+ ...extra,
5954
+ ...rpcError
5955
+ });
5956
+ }
5957
+ async getBalances(address, tokens) {
5958
+ const chainKey = tokens[0]?.chainKey;
5959
+ const client = this.resolvePublicClientForChain(chainKey);
5915
5960
  if (!client) {
5916
5961
  return {};
5917
5962
  }
@@ -5950,7 +5995,7 @@ class EvmChainStrategy {
5950
5995
  }
5951
5996
  }
5952
5997
  async estimateNetworkFee(steps) {
5953
- if (!this.walletClient) {
5998
+ if (!this.config.evmAddress) {
5954
5999
  return 0;
5955
6000
  }
5956
6001
  const account = this.config.evmAddress;
@@ -5967,23 +6012,67 @@ class EvmChainStrategy {
5967
6012
  return (feePerGas * scaled + 99n) / 100n;
5968
6013
  };
5969
6014
  let totalFeeWei = 0n;
5970
- for (const step of txSteps) {
6015
+ for (let i3 = 0; i3 < txSteps.length; i3++) {
6016
+ const step = txSteps[i3];
5971
6017
  const tx = step.transaction;
5972
6018
  if (!tx?.to) continue;
6019
+ const client = this.resolvePublicClientForChain(step.chainKey);
6020
+ if (!client) {
6021
+ this.logRpcWarning("Skipped network fee estimation: no public client", "no-client", {
6022
+ chainKey: step.chainKey,
6023
+ stepType: step.type,
6024
+ stepIndex: i3 + 1,
6025
+ totalSteps: txSteps.length
6026
+ });
6027
+ continue;
6028
+ }
5973
6029
  try {
5974
- const request = await this.walletClient.prepareTransactionRequest({
6030
+ const gas = await client.estimateGas({
5975
6031
  account: tx.from || account,
5976
6032
  to: tx.to,
5977
6033
  data: tx.data,
5978
- value: tx.value ? BigInt(tx.value) : void 0,
5979
- chain: this.walletClient.chain
6034
+ value: tx.value ? BigInt(tx.value) : void 0
5980
6035
  });
5981
- const gasLimit = request.gas;
5982
- const maxFeePerGas = request.maxFeePerGas ?? request.gasPrice;
5983
- if (gasLimit && maxFeePerGas) {
5984
- totalFeeWei += gasLimit * applyFeeMultiplier(maxFeePerGas);
6036
+ let feePerGas;
6037
+ try {
6038
+ const estimatedFees = await client.estimateFeesPerGas();
6039
+ feePerGas = estimatedFees.maxFeePerGas ?? estimatedFees.gasPrice;
6040
+ } catch (feeError) {
6041
+ this.logRpcWarning(
6042
+ "Failed to estimate fees per gas, falling back to gas price",
6043
+ feeError,
6044
+ {
6045
+ chainKey: step.chainKey,
6046
+ stepType: step.type,
6047
+ stepIndex: i3 + 1,
6048
+ totalSteps: txSteps.length
6049
+ }
6050
+ );
6051
+ try {
6052
+ feePerGas = await client.getGasPrice();
6053
+ } catch (gasPriceError) {
6054
+ this.logRpcWarning("Failed to get gas price for network fee estimation", gasPriceError, {
6055
+ chainKey: step.chainKey,
6056
+ stepType: step.type,
6057
+ stepIndex: i3 + 1,
6058
+ totalSteps: txSteps.length
6059
+ });
6060
+ }
5985
6061
  }
5986
- } catch {
6062
+ if (gas && feePerGas) {
6063
+ totalFeeWei += gas * applyFeeMultiplier(feePerGas);
6064
+ }
6065
+ } catch (error) {
6066
+ this.logRpcWarning("Failed to estimate gas for network fee", error, {
6067
+ chainKey: step.chainKey,
6068
+ stepType: step.type,
6069
+ stepIndex: i3 + 1,
6070
+ totalSteps: txSteps.length,
6071
+ to: tx.to,
6072
+ from: tx.from || account,
6073
+ hasData: Boolean(tx.data),
6074
+ hasValue: Boolean(tx.value)
6075
+ });
5987
6076
  }
5988
6077
  }
5989
6078
  if (totalFeeWei === 0n) {
@@ -7188,6 +7277,7 @@ function ChainStrategyProvider({
7188
7277
  () => new EvmChainStrategy({
7189
7278
  evmAddress: evmWallet.address,
7190
7279
  evmIsConnected: evmWallet.isConnected,
7280
+ evmIsReconnecting: evmWallet.isReconnecting,
7191
7281
  evmDisconnect: evmWallet.disconnect,
7192
7282
  walletClient: evmWallet.walletClient,
7193
7283
  publicClient: evmWallet.publicClient,
@@ -7197,6 +7287,7 @@ function ChainStrategyProvider({
7197
7287
  [
7198
7288
  evmWallet.address,
7199
7289
  evmWallet.isConnected,
7290
+ evmWallet.isReconnecting,
7200
7291
  evmWallet.disconnect,
7201
7292
  evmWallet.walletClient,
7202
7293
  evmWallet.publicClient,
@@ -26649,7 +26740,7 @@ class WalletConnectModal {
26649
26740
  }
26650
26741
  async initUi() {
26651
26742
  if (typeof window !== "undefined") {
26652
- await import("./index-B9_Kn_rc.js");
26743
+ await import("./index-CZGfdIKB.js");
26653
26744
  const modal = document.createElement("wcm-modal");
26654
26745
  document.body.insertAdjacentElement("beforeend", modal);
26655
26746
  OptionsCtrl.setIsUiLoaded(true);
@@ -26766,10 +26857,12 @@ function useTronWalletConnect(projectId) {
26766
26857
  appliedThemeRef.current = appliedTheme;
26767
26858
  useEffect(() => {
26768
26859
  if (!projectId || providerRef.current) return;
26860
+ let cancelled = false;
26769
26861
  const initProvider = async () => {
26770
26862
  try {
26771
26863
  const provider = await N.init({
26772
26864
  projectId,
26865
+ name: "evaa-bridge-tron",
26773
26866
  metadata: {
26774
26867
  name: "EVAA Bridge",
26775
26868
  description: "Cross-chain bridge powered by Stargate Protocol",
@@ -26777,6 +26870,7 @@ function useTronWalletConnect(projectId) {
26777
26870
  icons: [`${window.location.origin}/favicon.ico`]
26778
26871
  }
26779
26872
  });
26873
+ if (cancelled) return;
26780
26874
  providerRef.current = provider;
26781
26875
  if (projectId) {
26782
26876
  const modal = new WalletConnectModal({
@@ -26806,17 +26900,32 @@ function useTronWalletConnect(projectId) {
26806
26900
  console.log("TRON WalletConnect session deleted");
26807
26901
  setAddress(null);
26808
26902
  });
26809
- if (provider.session) {
26810
- const accounts = provider.session.namespaces?.tron?.accounts || [];
26811
- if (accounts.length > 0) {
26812
- const account = accounts[0];
26813
- const extractedAddress = account.split(":")[2];
26814
- console.log(
26815
- "TRON WalletConnect restored session:",
26816
- extractedAddress
26817
- );
26903
+ let tronAccounts = [];
26904
+ if (provider.session?.namespaces?.tron?.accounts?.length) {
26905
+ tronAccounts = provider.session.namespaces.tron.accounts;
26906
+ console.log("TRON WalletConnect: found session via provider.session");
26907
+ } else if (provider.client?.session) {
26908
+ const allSessions = provider.client.session.getAll();
26909
+ console.log("TRON WalletConnect: searching all sessions, count:", allSessions.length);
26910
+ const tronSession = allSessions.find(
26911
+ (s2) => s2.namespaces?.tron?.accounts?.length
26912
+ );
26913
+ if (tronSession) {
26914
+ tronAccounts = tronSession.namespaces.tron.accounts;
26915
+ console.log("TRON WalletConnect: found tron session in all sessions");
26916
+ }
26917
+ }
26918
+ if (tronAccounts.length > 0) {
26919
+ const extractedAddress = tronAccounts[0].split(":")[2];
26920
+ console.log(
26921
+ "TRON WalletConnect restored session:",
26922
+ extractedAddress
26923
+ );
26924
+ if (!cancelled) {
26818
26925
  setAddress(extractedAddress);
26819
26926
  }
26927
+ } else {
26928
+ console.log("TRON WalletConnect: no tron session found to restore");
26820
26929
  }
26821
26930
  } catch (error) {
26822
26931
  console.error("Failed to initialize TRON WalletConnect:", error);
@@ -26824,17 +26933,15 @@ function useTronWalletConnect(projectId) {
26824
26933
  };
26825
26934
  initProvider();
26826
26935
  return () => {
26827
- console.warn("TRON WalletConnect useEffect CLEANUP running");
26936
+ cancelled = true;
26828
26937
  if (abortControllerRef.current) {
26829
26938
  abortControllerRef.current.abort();
26830
26939
  }
26831
- if (providerRef.current) {
26832
- console.warn("TRON WalletConnect: disconnecting provider in cleanup");
26833
- providerRef.current.disconnect();
26834
- }
26835
26940
  if (modalRef.current) {
26836
26941
  modalRef.current.closeModal();
26837
26942
  }
26943
+ providerRef.current = null;
26944
+ modalRef.current = null;
26838
26945
  };
26839
26946
  }, [projectId, setAddress]);
26840
26947
  useEffect(() => {
@@ -27221,7 +27328,7 @@ function useUrlSync(options) {
27221
27328
  const EvaaBridgeWithProviders = (props) => {
27222
27329
  const [tonConnectUI] = useTonConnectUI();
27223
27330
  const tonAddress = useTonAddress();
27224
- const { address: evmAddress, isConnected: evmIsConnected } = useAccount();
27331
+ const { address: evmAddress, isConnected: evmIsConnected, isReconnecting: evmIsReconnecting } = useAccount();
27225
27332
  const wagmiConfig = useConfig();
27226
27333
  const { disconnect: evmDisconnect } = useDisconnect();
27227
27334
  const { data: walletClient } = useWalletClient();
@@ -27285,6 +27392,7 @@ const EvaaBridgeWithProviders = (props) => {
27285
27392
  evmWallet: {
27286
27393
  address: evmAddress,
27287
27394
  isConnected: evmIsConnected,
27395
+ isReconnecting: evmIsReconnecting,
27288
27396
  disconnect: evmDisconnect,
27289
27397
  walletClient,
27290
27398
  publicClient,
@@ -27556,4 +27664,4 @@ export {
27556
27664
  calculateMinReceived as y,
27557
27665
  getQuoteDetails as z
27558
27666
  };
27559
- //# sourceMappingURL=index-UBA5Oxdc.js.map
27667
+ //# sourceMappingURL=index-JmSrX7Hz.js.map