@rash2x/bridge-widget 0.4.5 → 0.5.0

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-CqOdLtGY.cjs");
3
+ const index = require("./index-BsVKYtLN.cjs");
4
4
  exports.DEFAULT_SLIPPAGE_BPS = index.DEFAULT_SLIPPAGE_BPS;
5
5
  exports.EvaaBridge = index.EvaaBridge;
6
6
  exports.RoutePriority = index.RoutePriority;
@@ -1,4 +1,4 @@
1
- import { S, d, f, e, H, B, F, W, L, z, _, G, A, D, Y, w, s, v, r, p, q, K, a1, a8, a3, a5, x, I, y, a4, a2, a6, a7, X, V, N, Z, a0, a9, P, Q, $, J, U, t, i, u, l, m, j, n, h, k, o } from "./index-D8wi96xC.js";
1
+ import { S, d, f, e, H, B, F, W, L, z, _, G, A, D, Y, w, s, v, r, p, q, K, a1, a8, a3, a5, x, I, y, a4, a2, a6, a7, X, V, N, Z, a0, a9, P, Q, $, J, U, t, i, u, l, m, j, n, h, k, o } from "./index-C4YkGAHm.js";
2
2
  export {
3
3
  S as DEFAULT_SLIPPAGE_BPS,
4
4
  d as EvaaBridge,
@@ -22749,7 +22749,7 @@ class WalletConnectModal {
22749
22749
  }
22750
22750
  async initUi() {
22751
22751
  if (typeof window !== "undefined") {
22752
- await Promise.resolve().then(() => require("./index-9pqdx6qK.cjs"));
22752
+ await Promise.resolve().then(() => require("./index-Cg_MPp5L.cjs"));
22753
22753
  const modal = document.createElement("wcm-modal");
22754
22754
  document.body.insertAdjacentElement("beforeend", modal);
22755
22755
  OptionsCtrl.setIsUiLoaded(true);
@@ -22931,6 +22931,21 @@ function useTronWalletConnect(options) {
22931
22931
  };
22932
22932
  }
22933
22933
  const TronWalletConnectContext = react.createContext(void 0);
22934
+ function TronWalletConnectProvider({
22935
+ projectId = "",
22936
+ metadata,
22937
+ themeMode,
22938
+ themeVariables,
22939
+ children
22940
+ }) {
22941
+ const walletConnect = useTronWalletConnect({
22942
+ projectId,
22943
+ metadata,
22944
+ themeMode,
22945
+ themeVariables
22946
+ });
22947
+ return /* @__PURE__ */ jsxRuntime.jsx(TronWalletConnectContext.Provider, { value: walletConnect, children });
22948
+ }
22934
22949
  function useTronWalletConnectContext() {
22935
22950
  const context = react.useContext(TronWalletConnectContext);
22936
22951
  if (!context) {
@@ -22940,6 +22955,10 @@ function useTronWalletConnectContext() {
22940
22955
  }
22941
22956
  return context;
22942
22957
  }
22958
+ function useTronWalletConnectContextSafe() {
22959
+ const context = react.useContext(TronWalletConnectContext);
22960
+ return context || null;
22961
+ }
22943
22962
  const WalletModalButton = (props) => {
22944
22963
  const { t: t2 } = reactI18next.useTranslation();
22945
22964
  const { icon: IconComponent, name, onClose } = props;
@@ -23032,7 +23051,7 @@ const WalletSelectModal = () => {
23032
23051
  const tonWallet = chainRegistry.getStrategyByType(CHAIN_TYPES.TON);
23033
23052
  const metaMaskWallet = chainRegistry.getStrategyByType(CHAIN_TYPES.EVM);
23034
23053
  const tronWallet = chainRegistry.getStrategyByType(CHAIN_TYPES.TRON);
23035
- const tronWalletConnect = useTronWalletConnectContext();
23054
+ const tronWalletConnect = useTronWalletConnectContextSafe();
23036
23055
  const walletConfigs = [
23037
23056
  {
23038
23057
  strategy: tonWallet,
@@ -23056,17 +23075,21 @@ const WalletSelectModal = () => {
23056
23075
  const connectedWallets = walletConfigs.reduce((acc, { strategy, walletId, name, icon }) => {
23057
23076
  const account = strategy?.getAccount();
23058
23077
  if (strategy?.isConnected() && account) {
23059
- acc.push({
23060
- id: walletId,
23061
- name,
23062
- icon,
23063
- address: account,
23064
- onDisconnect: () => strategy.disconnect()
23065
- });
23078
+ if (walletId === "tronlink" && tronWalletConnect?.isConnected) {
23079
+ return acc;
23080
+ } else {
23081
+ acc.push({
23082
+ id: walletId,
23083
+ name,
23084
+ icon,
23085
+ address: account,
23086
+ onDisconnect: () => strategy.disconnect()
23087
+ });
23088
+ }
23066
23089
  }
23067
23090
  return acc;
23068
23091
  }, []);
23069
- if (tronWalletConnect.isConnected && tronWalletConnect.address) {
23092
+ if (tronWalletConnect && tronWalletConnect.isConnected && tronWalletConnect.address) {
23070
23093
  connectedWallets.push({
23071
23094
  id: "tronwc",
23072
23095
  name: t2("wallets.walletConnect"),
@@ -23080,7 +23103,7 @@ const WalletSelectModal = () => {
23080
23103
  if (isEvmConnector && metaMaskWallet?.isConnected()) {
23081
23104
  return true;
23082
23105
  }
23083
- if (walletId === "tronwc" && tronWalletConnect.isConnected) {
23106
+ if ((walletId === "tronwc" || walletId === "tronlink") && tronWalletConnect?.isConnected) {
23084
23107
  return true;
23085
23108
  }
23086
23109
  return connectedWallets.some((w2) => w2.id === walletId);
@@ -23108,12 +23131,15 @@ const WalletSelectModal = () => {
23108
23131
  icon: TronLinkIcon,
23109
23132
  enabled: true
23110
23133
  },
23111
- {
23112
- id: "tronwc",
23113
- name: t2("wallets.walletConnect"),
23114
- icon: WalletConnectIcon,
23115
- enabled: true
23116
- }
23134
+ // Only include WalletConnect if enabled
23135
+ ...tronWalletConnect ? [
23136
+ {
23137
+ id: "tronwc",
23138
+ name: t2("wallets.walletConnect"),
23139
+ icon: WalletConnectIcon,
23140
+ enabled: true
23141
+ }
23142
+ ] : []
23117
23143
  ];
23118
23144
  const notConnected = (w2) => !isWalletConnected(w2.id);
23119
23145
  const categories = [
@@ -25108,6 +25134,7 @@ function ChainStrategyProvider({
25108
25134
  () => new TronChainStrategy({
25109
25135
  tronAddress: tronWallet.address,
25110
25136
  tronConnected: tronWallet.connected,
25137
+ isWalletConnect: tronWallet.isWalletConnect,
25111
25138
  tronSelect: tronWallet.select,
25112
25139
  tronConnect: tronWallet.connect,
25113
25140
  tronDisconnect: tronWallet.disconnect
@@ -25115,6 +25142,7 @@ function ChainStrategyProvider({
25115
25142
  [
25116
25143
  tronWallet.address,
25117
25144
  tronWallet.connected,
25145
+ tronWallet.isWalletConnect,
25118
25146
  tronWallet.select,
25119
25147
  tronWallet.connect,
25120
25148
  tronWallet.disconnect
@@ -25768,7 +25796,68 @@ const useAutoSelectNetwork = ({
25768
25796
  setFromChain
25769
25797
  ]);
25770
25798
  };
25799
+ const THEME_STORAGE_KEY = "stargate-bridge-theme";
25800
+ const getInitialTheme = () => {
25801
+ try {
25802
+ const stored = localStorage.getItem(THEME_STORAGE_KEY);
25803
+ if (stored && ["light", "dark", "system"].includes(stored)) {
25804
+ return stored;
25805
+ }
25806
+ } catch (error) {
25807
+ console.error("Error reading theme from localStorage:", error);
25808
+ }
25809
+ return "system";
25810
+ };
25811
+ const getSystemTheme = () => {
25812
+ if (typeof window !== "undefined" && window.matchMedia) {
25813
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
25814
+ }
25815
+ return "light";
25816
+ };
25817
+ const getAppliedTheme = (mode) => {
25818
+ if (mode === "system") {
25819
+ return getSystemTheme();
25820
+ }
25821
+ return mode;
25822
+ };
25823
+ const useThemeStore = zustand.create((set2) => ({
25824
+ mode: getInitialTheme(),
25825
+ appliedTheme: getAppliedTheme(getInitialTheme()),
25826
+ setTheme: (mode) => {
25827
+ try {
25828
+ localStorage.setItem(THEME_STORAGE_KEY, mode);
25829
+ } catch (error) {
25830
+ console.error("Error saving theme to localStorage:", error);
25831
+ }
25832
+ const appliedTheme = getAppliedTheme(mode);
25833
+ set2({ mode, appliedTheme });
25834
+ }
25835
+ }));
25771
25836
  const EvaaBridgeWithProviders = (props) => {
25837
+ const { tronWalletConnectConfig, ...restProps } = props;
25838
+ const appliedTheme = useThemeStore((state2) => state2.appliedTheme);
25839
+ const content = /* @__PURE__ */ jsxRuntime.jsx(BridgeI18nProvider, { defaultLanguage: restProps.defaultLanguage, children: /* @__PURE__ */ jsxRuntime.jsx(
25840
+ EvaaBridgeWithWallets,
25841
+ {
25842
+ ...restProps,
25843
+ tronWalletConnectEnabled: !!tronWalletConnectConfig
25844
+ }
25845
+ ) });
25846
+ if (tronWalletConnectConfig) {
25847
+ return /* @__PURE__ */ jsxRuntime.jsx(
25848
+ TronWalletConnectProvider,
25849
+ {
25850
+ projectId: tronWalletConnectConfig.projectId,
25851
+ metadata: tronWalletConnectConfig.metadata,
25852
+ themeMode: tronWalletConnectConfig.themeMode || appliedTheme,
25853
+ themeVariables: tronWalletConnectConfig.themeVariables,
25854
+ children: content
25855
+ }
25856
+ );
25857
+ }
25858
+ return content;
25859
+ };
25860
+ const EvaaBridgeWithWallets = (props) => {
25772
25861
  const [tonConnectUI] = uiReact.useTonConnectUI();
25773
25862
  const tonAddress = uiReact.useTonAddress();
25774
25863
  const { address: evmAddress, isConnected: evmIsConnected } = wagmi.useAccount();
@@ -25782,6 +25871,9 @@ const EvaaBridgeWithProviders = (props) => {
25782
25871
  connect: tronConnect,
25783
25872
  disconnect: tronDisconnect
25784
25873
  } = tronwalletAdapterReactHooks.useWallet();
25874
+ const tronWalletConnect = useTronWalletConnectContextSafe();
25875
+ const isTronConnected = tronConnected || (tronWalletConnect?.isConnected ?? false);
25876
+ const tronWalletAddress = tronAddress || tronWalletConnect?.address || null;
25785
25877
  const { setTonConnected, setMetaMaskConnected, setTronConnected } = useConnectedWalletsStore();
25786
25878
  react.useEffect(() => {
25787
25879
  setTonConnected(!!tonAddress);
@@ -25790,14 +25882,14 @@ const EvaaBridgeWithProviders = (props) => {
25790
25882
  setMetaMaskConnected(!!evmIsConnected);
25791
25883
  }, [evmIsConnected, setMetaMaskConnected]);
25792
25884
  react.useEffect(() => {
25793
- setTronConnected(!!tronConnected);
25794
- }, [tronConnected, setTronConnected]);
25885
+ setTronConnected(!!isTronConnected);
25886
+ }, [isTronConnected, setTronConnected]);
25795
25887
  useAutoSelectNetwork({
25796
25888
  tonAddress,
25797
- tronConnected,
25889
+ tronConnected: isTronConnected,
25798
25890
  evmIsConnected
25799
25891
  });
25800
- return /* @__PURE__ */ jsxRuntime.jsx(BridgeI18nProvider, { defaultLanguage: props.defaultLanguage, children: /* @__PURE__ */ jsxRuntime.jsx(
25892
+ return /* @__PURE__ */ jsxRuntime.jsx(
25801
25893
  ChainStrategyProvider,
25802
25894
  {
25803
25895
  evmWallet: {
@@ -25812,8 +25904,8 @@ const EvaaBridgeWithProviders = (props) => {
25812
25904
  address: tonAddress
25813
25905
  },
25814
25906
  tronWallet: {
25815
- address: tronAddress,
25816
- connected: tronConnected,
25907
+ address: tronWalletAddress,
25908
+ connected: isTronConnected,
25817
25909
  select: tronSelect,
25818
25910
  connect: tronConnect,
25819
25911
  disconnect: tronDisconnect
@@ -25822,7 +25914,7 @@ const EvaaBridgeWithProviders = (props) => {
25822
25914
  tonApiKey: props.tonApiKey,
25823
25915
  children: /* @__PURE__ */ jsxRuntime.jsx(EvaaBridgeContent, { ...props })
25824
25916
  }
25825
- ) });
25917
+ );
25826
25918
  };
25827
25919
  const EvaaBridgeContent = ({
25828
25920
  className,
@@ -26092,4 +26184,4 @@ exports.useSwapModel = useSwapModel;
26092
26184
  exports.useTokensStore = useTokensStore;
26093
26185
  exports.useTransactionStore = useTransactionStore;
26094
26186
  exports.useTronWalletConnect = useTronWalletConnect;
26095
- //# sourceMappingURL=index-CqOdLtGY.cjs.map
26187
+ //# sourceMappingURL=index-BsVKYtLN.cjs.map