@rash2x/bridge-widget 0.8.6 → 0.8.9

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);
@@ -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,
@@ -5578,6 +5589,14 @@ const SuccessStep = ({
5578
5589
  const { t: t2 } = useBridgeTranslation();
5579
5590
  const metadata = current?.metadata;
5580
5591
  const srcTxHash = current?.tonTransactionHash || current?.srcTxHash;
5592
+ const srcAmount = metadata?.srcAmountHuman;
5593
+ const hasSrcAmount = Number.isFinite(srcAmount);
5594
+ const srcTokenSymbol = metadata?.srcTokenSymbol ?? "default";
5595
+ const formatSrcAmount = (value) => {
5596
+ if (value <= 0) return "0";
5597
+ if (value >= 1) return formatBalance(value, 2);
5598
+ return value.toFixed(6).replace(/\.?0+$/, "");
5599
+ };
5581
5600
  return /* @__PURE__ */ jsxs(
5582
5601
  DialogContent,
5583
5602
  {
@@ -5588,17 +5607,17 @@ const SuccessStep = ({
5588
5607
  icon,
5589
5608
  /* @__PURE__ */ jsx(DialogHeader, { className: "z-10 relative p-0", children: /* @__PURE__ */ jsx(DialogTitle, { className: "text-[28px] text-center", children: t2("transaction.success") }) }),
5590
5609
  /* @__PURE__ */ jsxs("div", { className: "w-full space-y-2 mt-5 relative z-10 pb-14", children: [
5591
- metadata?.srcAmountHuman && /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center", children: [
5610
+ hasSrcAmount && /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center", children: [
5592
5611
  /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: t2("transaction.bridged") }),
5593
5612
  /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1 font-medium", children: [
5594
- formatBalance(metadata.srcAmountHuman, 2),
5613
+ formatSrcAmount(srcAmount ?? 0),
5595
5614
  " ",
5596
- metadata?.srcTokenSymbol,
5615
+ srcTokenSymbol,
5597
5616
  /* @__PURE__ */ jsx(
5598
5617
  TokenSymbol,
5599
5618
  {
5600
5619
  className: "w-[18px] h-[18px]",
5601
- symbol: metadata?.srcTokenSymbol
5620
+ symbol: srcTokenSymbol
5602
5621
  }
5603
5622
  )
5604
5623
  ] })
@@ -5886,7 +5905,7 @@ class EvmChainStrategy {
5886
5905
  return !!this.config.evmIsConnected;
5887
5906
  }
5888
5907
  isConnecting() {
5889
- return false;
5908
+ return !!this.config.evmIsReconnecting;
5890
5909
  }
5891
5910
  getAccount() {
5892
5911
  return this.config.evmAddress || null;
@@ -5903,15 +5922,49 @@ class EvmChainStrategy {
5903
5922
  getClient() {
5904
5923
  return this.walletClient;
5905
5924
  }
5906
- async getBalances(address, tokens) {
5907
- const chainKey = tokens[0]?.chainKey;
5925
+ resolvePublicClientForChain(chainKey) {
5908
5926
  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
- }
5927
+ if (!chainKey || !this.config.getPublicClientForChain || !this.config.chainKeyToId) {
5928
+ return client;
5929
+ }
5930
+ const chainId = this.config.chainKeyToId[chainKey.toLowerCase()];
5931
+ if (!chainId) {
5932
+ return client;
5914
5933
  }
5934
+ client = this.config.getPublicClientForChain(chainId) ?? client;
5935
+ return client;
5936
+ }
5937
+ getRpcErrorDetails(error) {
5938
+ if (error instanceof Error) {
5939
+ const rpcError = error;
5940
+ return {
5941
+ code: rpcError.code,
5942
+ message: rpcError.message,
5943
+ shortMessage: rpcError.shortMessage,
5944
+ details: rpcError.details
5945
+ };
5946
+ }
5947
+ if (typeof error === "object" && error !== null) {
5948
+ const candidate = error;
5949
+ return {
5950
+ code: typeof candidate.code === "number" ? candidate.code : void 0,
5951
+ message: typeof candidate.message === "string" ? candidate.message : String(error),
5952
+ shortMessage: typeof candidate.shortMessage === "string" ? candidate.shortMessage : void 0,
5953
+ details: typeof candidate.details === "string" ? candidate.details : void 0
5954
+ };
5955
+ }
5956
+ return { message: String(error) };
5957
+ }
5958
+ logRpcWarning(context, error, extra) {
5959
+ const rpcError = this.getRpcErrorDetails(error);
5960
+ console.warn(`[evm] ${context}`, {
5961
+ ...extra,
5962
+ ...rpcError
5963
+ });
5964
+ }
5965
+ async getBalances(address, tokens) {
5966
+ const chainKey = tokens[0]?.chainKey;
5967
+ const client = this.resolvePublicClientForChain(chainKey);
5915
5968
  if (!client) {
5916
5969
  return {};
5917
5970
  }
@@ -5950,7 +6003,7 @@ class EvmChainStrategy {
5950
6003
  }
5951
6004
  }
5952
6005
  async estimateNetworkFee(steps) {
5953
- if (!this.walletClient) {
6006
+ if (!this.config.evmAddress) {
5954
6007
  return 0;
5955
6008
  }
5956
6009
  const account = this.config.evmAddress;
@@ -5967,23 +6020,67 @@ class EvmChainStrategy {
5967
6020
  return (feePerGas * scaled + 99n) / 100n;
5968
6021
  };
5969
6022
  let totalFeeWei = 0n;
5970
- for (const step of txSteps) {
6023
+ for (let i3 = 0; i3 < txSteps.length; i3++) {
6024
+ const step = txSteps[i3];
5971
6025
  const tx = step.transaction;
5972
6026
  if (!tx?.to) continue;
6027
+ const client = this.resolvePublicClientForChain(step.chainKey);
6028
+ if (!client) {
6029
+ this.logRpcWarning("Skipped network fee estimation: no public client", "no-client", {
6030
+ chainKey: step.chainKey,
6031
+ stepType: step.type,
6032
+ stepIndex: i3 + 1,
6033
+ totalSteps: txSteps.length
6034
+ });
6035
+ continue;
6036
+ }
5973
6037
  try {
5974
- const request = await this.walletClient.prepareTransactionRequest({
6038
+ const gas = await client.estimateGas({
5975
6039
  account: tx.from || account,
5976
6040
  to: tx.to,
5977
6041
  data: tx.data,
5978
- value: tx.value ? BigInt(tx.value) : void 0,
5979
- chain: this.walletClient.chain
6042
+ value: tx.value ? BigInt(tx.value) : void 0
5980
6043
  });
5981
- const gasLimit = request.gas;
5982
- const maxFeePerGas = request.maxFeePerGas ?? request.gasPrice;
5983
- if (gasLimit && maxFeePerGas) {
5984
- totalFeeWei += gasLimit * applyFeeMultiplier(maxFeePerGas);
6044
+ let feePerGas;
6045
+ try {
6046
+ const estimatedFees = await client.estimateFeesPerGas();
6047
+ feePerGas = estimatedFees.maxFeePerGas ?? estimatedFees.gasPrice;
6048
+ } catch (feeError) {
6049
+ this.logRpcWarning(
6050
+ "Failed to estimate fees per gas, falling back to gas price",
6051
+ feeError,
6052
+ {
6053
+ chainKey: step.chainKey,
6054
+ stepType: step.type,
6055
+ stepIndex: i3 + 1,
6056
+ totalSteps: txSteps.length
6057
+ }
6058
+ );
6059
+ try {
6060
+ feePerGas = await client.getGasPrice();
6061
+ } catch (gasPriceError) {
6062
+ this.logRpcWarning("Failed to get gas price for network fee estimation", gasPriceError, {
6063
+ chainKey: step.chainKey,
6064
+ stepType: step.type,
6065
+ stepIndex: i3 + 1,
6066
+ totalSteps: txSteps.length
6067
+ });
6068
+ }
5985
6069
  }
5986
- } catch {
6070
+ if (gas && feePerGas) {
6071
+ totalFeeWei += gas * applyFeeMultiplier(feePerGas);
6072
+ }
6073
+ } catch (error) {
6074
+ this.logRpcWarning("Failed to estimate gas for network fee", error, {
6075
+ chainKey: step.chainKey,
6076
+ stepType: step.type,
6077
+ stepIndex: i3 + 1,
6078
+ totalSteps: txSteps.length,
6079
+ to: tx.to,
6080
+ from: tx.from || account,
6081
+ hasData: Boolean(tx.data),
6082
+ hasValue: Boolean(tx.value)
6083
+ });
5987
6084
  }
5988
6085
  }
5989
6086
  if (totalFeeWei === 0n) {
@@ -7188,6 +7285,7 @@ function ChainStrategyProvider({
7188
7285
  () => new EvmChainStrategy({
7189
7286
  evmAddress: evmWallet.address,
7190
7287
  evmIsConnected: evmWallet.isConnected,
7288
+ evmIsReconnecting: evmWallet.isReconnecting,
7191
7289
  evmDisconnect: evmWallet.disconnect,
7192
7290
  walletClient: evmWallet.walletClient,
7193
7291
  publicClient: evmWallet.publicClient,
@@ -7197,6 +7295,7 @@ function ChainStrategyProvider({
7197
7295
  [
7198
7296
  evmWallet.address,
7199
7297
  evmWallet.isConnected,
7298
+ evmWallet.isReconnecting,
7200
7299
  evmWallet.disconnect,
7201
7300
  evmWallet.walletClient,
7202
7301
  evmWallet.publicClient,
@@ -26649,7 +26748,7 @@ class WalletConnectModal {
26649
26748
  }
26650
26749
  async initUi() {
26651
26750
  if (typeof window !== "undefined") {
26652
- await import("./index-B9_Kn_rc.js");
26751
+ await import("./index-Bl4_W_Mc.js");
26653
26752
  const modal = document.createElement("wcm-modal");
26654
26753
  document.body.insertAdjacentElement("beforeend", modal);
26655
26754
  OptionsCtrl.setIsUiLoaded(true);
@@ -26766,10 +26865,12 @@ function useTronWalletConnect(projectId) {
26766
26865
  appliedThemeRef.current = appliedTheme;
26767
26866
  useEffect(() => {
26768
26867
  if (!projectId || providerRef.current) return;
26868
+ let cancelled = false;
26769
26869
  const initProvider = async () => {
26770
26870
  try {
26771
26871
  const provider = await N.init({
26772
26872
  projectId,
26873
+ name: "evaa-bridge-tron",
26773
26874
  metadata: {
26774
26875
  name: "EVAA Bridge",
26775
26876
  description: "Cross-chain bridge powered by Stargate Protocol",
@@ -26777,6 +26878,7 @@ function useTronWalletConnect(projectId) {
26777
26878
  icons: [`${window.location.origin}/favicon.ico`]
26778
26879
  }
26779
26880
  });
26881
+ if (cancelled) return;
26780
26882
  providerRef.current = provider;
26781
26883
  if (projectId) {
26782
26884
  const modal = new WalletConnectModal({
@@ -26806,17 +26908,32 @@ function useTronWalletConnect(projectId) {
26806
26908
  console.log("TRON WalletConnect session deleted");
26807
26909
  setAddress(null);
26808
26910
  });
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
- );
26911
+ let tronAccounts = [];
26912
+ if (provider.session?.namespaces?.tron?.accounts?.length) {
26913
+ tronAccounts = provider.session.namespaces.tron.accounts;
26914
+ console.log("TRON WalletConnect: found session via provider.session");
26915
+ } else if (provider.client?.session) {
26916
+ const allSessions = provider.client.session.getAll();
26917
+ console.log("TRON WalletConnect: searching all sessions, count:", allSessions.length);
26918
+ const tronSession = allSessions.find(
26919
+ (s2) => s2.namespaces?.tron?.accounts?.length
26920
+ );
26921
+ if (tronSession) {
26922
+ tronAccounts = tronSession.namespaces.tron.accounts;
26923
+ console.log("TRON WalletConnect: found tron session in all sessions");
26924
+ }
26925
+ }
26926
+ if (tronAccounts.length > 0) {
26927
+ const extractedAddress = tronAccounts[0].split(":")[2];
26928
+ console.log(
26929
+ "TRON WalletConnect restored session:",
26930
+ extractedAddress
26931
+ );
26932
+ if (!cancelled) {
26818
26933
  setAddress(extractedAddress);
26819
26934
  }
26935
+ } else {
26936
+ console.log("TRON WalletConnect: no tron session found to restore");
26820
26937
  }
26821
26938
  } catch (error) {
26822
26939
  console.error("Failed to initialize TRON WalletConnect:", error);
@@ -26824,17 +26941,15 @@ function useTronWalletConnect(projectId) {
26824
26941
  };
26825
26942
  initProvider();
26826
26943
  return () => {
26827
- console.warn("TRON WalletConnect useEffect CLEANUP running");
26944
+ cancelled = true;
26828
26945
  if (abortControllerRef.current) {
26829
26946
  abortControllerRef.current.abort();
26830
26947
  }
26831
- if (providerRef.current) {
26832
- console.warn("TRON WalletConnect: disconnecting provider in cleanup");
26833
- providerRef.current.disconnect();
26834
- }
26835
26948
  if (modalRef.current) {
26836
26949
  modalRef.current.closeModal();
26837
26950
  }
26951
+ providerRef.current = null;
26952
+ modalRef.current = null;
26838
26953
  };
26839
26954
  }, [projectId, setAddress]);
26840
26955
  useEffect(() => {
@@ -27221,7 +27336,7 @@ function useUrlSync(options) {
27221
27336
  const EvaaBridgeWithProviders = (props) => {
27222
27337
  const [tonConnectUI] = useTonConnectUI();
27223
27338
  const tonAddress = useTonAddress();
27224
- const { address: evmAddress, isConnected: evmIsConnected } = useAccount();
27339
+ const { address: evmAddress, isConnected: evmIsConnected, isReconnecting: evmIsReconnecting } = useAccount();
27225
27340
  const wagmiConfig = useConfig();
27226
27341
  const { disconnect: evmDisconnect } = useDisconnect();
27227
27342
  const { data: walletClient } = useWalletClient();
@@ -27285,6 +27400,7 @@ const EvaaBridgeWithProviders = (props) => {
27285
27400
  evmWallet: {
27286
27401
  address: evmAddress,
27287
27402
  isConnected: evmIsConnected,
27403
+ isReconnecting: evmIsReconnecting,
27288
27404
  disconnect: evmDisconnect,
27289
27405
  walletClient,
27290
27406
  publicClient,
@@ -27556,4 +27672,4 @@ export {
27556
27672
  calculateMinReceived as y,
27557
27673
  getQuoteDetails as z
27558
27674
  };
27559
- //# sourceMappingURL=index-UBA5Oxdc.js.map
27675
+ //# sourceMappingURL=index-IZ7t2PGj.js.map