@rash2x/bridge-widget 0.4.6 → 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-kqLPlOw1.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-BG-E-qt2.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-uh5JIOC8.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,7 +23075,7 @@ 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
- if (walletId === "tronlink" && tronWalletConnect.isConnected) {
23078
+ if (walletId === "tronlink" && tronWalletConnect?.isConnected) {
23060
23079
  return acc;
23061
23080
  } else {
23062
23081
  acc.push({
@@ -23070,7 +23089,7 @@ const WalletSelectModal = () => {
23070
23089
  }
23071
23090
  return acc;
23072
23091
  }, []);
23073
- if (tronWalletConnect.isConnected && tronWalletConnect.address) {
23092
+ if (tronWalletConnect && tronWalletConnect.isConnected && tronWalletConnect.address) {
23074
23093
  connectedWallets.push({
23075
23094
  id: "tronwc",
23076
23095
  name: t2("wallets.walletConnect"),
@@ -23084,7 +23103,7 @@ const WalletSelectModal = () => {
23084
23103
  if (isEvmConnector && metaMaskWallet?.isConnected()) {
23085
23104
  return true;
23086
23105
  }
23087
- if ((walletId === "tronwc" || walletId === "tronlink") && tronWalletConnect.isConnected) {
23106
+ if ((walletId === "tronwc" || walletId === "tronlink") && tronWalletConnect?.isConnected) {
23088
23107
  return true;
23089
23108
  }
23090
23109
  return connectedWallets.some((w2) => w2.id === walletId);
@@ -23112,12 +23131,15 @@ const WalletSelectModal = () => {
23112
23131
  icon: TronLinkIcon,
23113
23132
  enabled: true
23114
23133
  },
23115
- {
23116
- id: "tronwc",
23117
- name: t2("wallets.walletConnect"),
23118
- icon: WalletConnectIcon,
23119
- enabled: true
23120
- }
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
+ ] : []
23121
23143
  ];
23122
23144
  const notConnected = (w2) => !isWalletConnected(w2.id);
23123
23145
  const categories = [
@@ -25774,7 +25796,68 @@ const useAutoSelectNetwork = ({
25774
25796
  setFromChain
25775
25797
  ]);
25776
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
+ }));
25777
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) => {
25778
25861
  const [tonConnectUI] = uiReact.useTonConnectUI();
25779
25862
  const tonAddress = uiReact.useTonAddress();
25780
25863
  const { address: evmAddress, isConnected: evmIsConnected } = wagmi.useAccount();
@@ -25788,9 +25871,9 @@ const EvaaBridgeWithProviders = (props) => {
25788
25871
  connect: tronConnect,
25789
25872
  disconnect: tronDisconnect
25790
25873
  } = tronwalletAdapterReactHooks.useWallet();
25791
- const tronWalletConnect = useTronWalletConnectContext();
25792
- const isTronConnected = tronConnected || tronWalletConnect.isConnected;
25793
- const tronWalletAddress = tronAddress || tronWalletConnect.address;
25874
+ const tronWalletConnect = useTronWalletConnectContextSafe();
25875
+ const isTronConnected = tronConnected || (tronWalletConnect?.isConnected ?? false);
25876
+ const tronWalletAddress = tronAddress || tronWalletConnect?.address || null;
25794
25877
  const { setTonConnected, setMetaMaskConnected, setTronConnected } = useConnectedWalletsStore();
25795
25878
  react.useEffect(() => {
25796
25879
  setTonConnected(!!tonAddress);
@@ -25806,7 +25889,7 @@ const EvaaBridgeWithProviders = (props) => {
25806
25889
  tronConnected: isTronConnected,
25807
25890
  evmIsConnected
25808
25891
  });
25809
- return /* @__PURE__ */ jsxRuntime.jsx(BridgeI18nProvider, { defaultLanguage: props.defaultLanguage, children: /* @__PURE__ */ jsxRuntime.jsx(
25892
+ return /* @__PURE__ */ jsxRuntime.jsx(
25810
25893
  ChainStrategyProvider,
25811
25894
  {
25812
25895
  evmWallet: {
@@ -25831,7 +25914,7 @@ const EvaaBridgeWithProviders = (props) => {
25831
25914
  tonApiKey: props.tonApiKey,
25832
25915
  children: /* @__PURE__ */ jsxRuntime.jsx(EvaaBridgeContent, { ...props })
25833
25916
  }
25834
- ) });
25917
+ );
25835
25918
  };
25836
25919
  const EvaaBridgeContent = ({
25837
25920
  className,
@@ -26101,4 +26184,4 @@ exports.useSwapModel = useSwapModel;
26101
26184
  exports.useTokensStore = useTokensStore;
26102
26185
  exports.useTransactionStore = useTransactionStore;
26103
26186
  exports.useTronWalletConnect = useTronWalletConnect;
26104
- //# sourceMappingURL=index-kqLPlOw1.cjs.map
26187
+ //# sourceMappingURL=index-BsVKYtLN.cjs.map