@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.
@@ -22748,7 +22748,7 @@ class WalletConnectModal {
22748
22748
  }
22749
22749
  async initUi() {
22750
22750
  if (typeof window !== "undefined") {
22751
- await import("./index-DqeErSqM.js");
22751
+ await import("./index-CNQIX3lo.js");
22752
22752
  const modal = document.createElement("wcm-modal");
22753
22753
  document.body.insertAdjacentElement("beforeend", modal);
22754
22754
  OptionsCtrl.setIsUiLoaded(true);
@@ -22930,6 +22930,21 @@ function useTronWalletConnect(options) {
22930
22930
  };
22931
22931
  }
22932
22932
  const TronWalletConnectContext = createContext(void 0);
22933
+ function TronWalletConnectProvider({
22934
+ projectId = "",
22935
+ metadata,
22936
+ themeMode,
22937
+ themeVariables,
22938
+ children
22939
+ }) {
22940
+ const walletConnect = useTronWalletConnect({
22941
+ projectId,
22942
+ metadata,
22943
+ themeMode,
22944
+ themeVariables
22945
+ });
22946
+ return /* @__PURE__ */ jsx(TronWalletConnectContext.Provider, { value: walletConnect, children });
22947
+ }
22933
22948
  function useTronWalletConnectContext() {
22934
22949
  const context = useContext(TronWalletConnectContext);
22935
22950
  if (!context) {
@@ -22939,6 +22954,10 @@ function useTronWalletConnectContext() {
22939
22954
  }
22940
22955
  return context;
22941
22956
  }
22957
+ function useTronWalletConnectContextSafe() {
22958
+ const context = useContext(TronWalletConnectContext);
22959
+ return context || null;
22960
+ }
22942
22961
  const WalletModalButton = (props) => {
22943
22962
  const { t: t2 } = useTranslation();
22944
22963
  const { icon: IconComponent, name, onClose } = props;
@@ -23031,7 +23050,7 @@ const WalletSelectModal = () => {
23031
23050
  const tonWallet = chainRegistry.getStrategyByType(CHAIN_TYPES.TON);
23032
23051
  const metaMaskWallet = chainRegistry.getStrategyByType(CHAIN_TYPES.EVM);
23033
23052
  const tronWallet = chainRegistry.getStrategyByType(CHAIN_TYPES.TRON);
23034
- const tronWalletConnect = useTronWalletConnectContext();
23053
+ const tronWalletConnect = useTronWalletConnectContextSafe();
23035
23054
  const walletConfigs = [
23036
23055
  {
23037
23056
  strategy: tonWallet,
@@ -23055,7 +23074,7 @@ const WalletSelectModal = () => {
23055
23074
  const connectedWallets = walletConfigs.reduce((acc, { strategy, walletId, name, icon }) => {
23056
23075
  const account = strategy?.getAccount();
23057
23076
  if (strategy?.isConnected() && account) {
23058
- if (walletId === "tronlink" && tronWalletConnect.isConnected) {
23077
+ if (walletId === "tronlink" && tronWalletConnect?.isConnected) {
23059
23078
  return acc;
23060
23079
  } else {
23061
23080
  acc.push({
@@ -23069,7 +23088,7 @@ const WalletSelectModal = () => {
23069
23088
  }
23070
23089
  return acc;
23071
23090
  }, []);
23072
- if (tronWalletConnect.isConnected && tronWalletConnect.address) {
23091
+ if (tronWalletConnect && tronWalletConnect.isConnected && tronWalletConnect.address) {
23073
23092
  connectedWallets.push({
23074
23093
  id: "tronwc",
23075
23094
  name: t2("wallets.walletConnect"),
@@ -23083,7 +23102,7 @@ const WalletSelectModal = () => {
23083
23102
  if (isEvmConnector && metaMaskWallet?.isConnected()) {
23084
23103
  return true;
23085
23104
  }
23086
- if ((walletId === "tronwc" || walletId === "tronlink") && tronWalletConnect.isConnected) {
23105
+ if ((walletId === "tronwc" || walletId === "tronlink") && tronWalletConnect?.isConnected) {
23087
23106
  return true;
23088
23107
  }
23089
23108
  return connectedWallets.some((w2) => w2.id === walletId);
@@ -23111,12 +23130,15 @@ const WalletSelectModal = () => {
23111
23130
  icon: TronLinkIcon,
23112
23131
  enabled: true
23113
23132
  },
23114
- {
23115
- id: "tronwc",
23116
- name: t2("wallets.walletConnect"),
23117
- icon: WalletConnectIcon,
23118
- enabled: true
23119
- }
23133
+ // Only include WalletConnect if enabled
23134
+ ...tronWalletConnect ? [
23135
+ {
23136
+ id: "tronwc",
23137
+ name: t2("wallets.walletConnect"),
23138
+ icon: WalletConnectIcon,
23139
+ enabled: true
23140
+ }
23141
+ ] : []
23120
23142
  ];
23121
23143
  const notConnected = (w2) => !isWalletConnected(w2.id);
23122
23144
  const categories = [
@@ -25773,7 +25795,68 @@ const useAutoSelectNetwork = ({
25773
25795
  setFromChain
25774
25796
  ]);
25775
25797
  };
25798
+ const THEME_STORAGE_KEY = "stargate-bridge-theme";
25799
+ const getInitialTheme = () => {
25800
+ try {
25801
+ const stored = localStorage.getItem(THEME_STORAGE_KEY);
25802
+ if (stored && ["light", "dark", "system"].includes(stored)) {
25803
+ return stored;
25804
+ }
25805
+ } catch (error) {
25806
+ console.error("Error reading theme from localStorage:", error);
25807
+ }
25808
+ return "system";
25809
+ };
25810
+ const getSystemTheme = () => {
25811
+ if (typeof window !== "undefined" && window.matchMedia) {
25812
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
25813
+ }
25814
+ return "light";
25815
+ };
25816
+ const getAppliedTheme = (mode) => {
25817
+ if (mode === "system") {
25818
+ return getSystemTheme();
25819
+ }
25820
+ return mode;
25821
+ };
25822
+ const useThemeStore = create((set2) => ({
25823
+ mode: getInitialTheme(),
25824
+ appliedTheme: getAppliedTheme(getInitialTheme()),
25825
+ setTheme: (mode) => {
25826
+ try {
25827
+ localStorage.setItem(THEME_STORAGE_KEY, mode);
25828
+ } catch (error) {
25829
+ console.error("Error saving theme to localStorage:", error);
25830
+ }
25831
+ const appliedTheme = getAppliedTheme(mode);
25832
+ set2({ mode, appliedTheme });
25833
+ }
25834
+ }));
25776
25835
  const EvaaBridgeWithProviders = (props) => {
25836
+ const { tronWalletConnectConfig, ...restProps } = props;
25837
+ const appliedTheme = useThemeStore((state2) => state2.appliedTheme);
25838
+ const content = /* @__PURE__ */ jsx(BridgeI18nProvider, { defaultLanguage: restProps.defaultLanguage, children: /* @__PURE__ */ jsx(
25839
+ EvaaBridgeWithWallets,
25840
+ {
25841
+ ...restProps,
25842
+ tronWalletConnectEnabled: !!tronWalletConnectConfig
25843
+ }
25844
+ ) });
25845
+ if (tronWalletConnectConfig) {
25846
+ return /* @__PURE__ */ jsx(
25847
+ TronWalletConnectProvider,
25848
+ {
25849
+ projectId: tronWalletConnectConfig.projectId,
25850
+ metadata: tronWalletConnectConfig.metadata,
25851
+ themeMode: tronWalletConnectConfig.themeMode || appliedTheme,
25852
+ themeVariables: tronWalletConnectConfig.themeVariables,
25853
+ children: content
25854
+ }
25855
+ );
25856
+ }
25857
+ return content;
25858
+ };
25859
+ const EvaaBridgeWithWallets = (props) => {
25777
25860
  const [tonConnectUI] = useTonConnectUI();
25778
25861
  const tonAddress = useTonAddress();
25779
25862
  const { address: evmAddress, isConnected: evmIsConnected } = useAccount();
@@ -25787,9 +25870,9 @@ const EvaaBridgeWithProviders = (props) => {
25787
25870
  connect: tronConnect,
25788
25871
  disconnect: tronDisconnect
25789
25872
  } = useWallet();
25790
- const tronWalletConnect = useTronWalletConnectContext();
25791
- const isTronConnected = tronConnected || tronWalletConnect.isConnected;
25792
- const tronWalletAddress = tronAddress || tronWalletConnect.address;
25873
+ const tronWalletConnect = useTronWalletConnectContextSafe();
25874
+ const isTronConnected = tronConnected || (tronWalletConnect?.isConnected ?? false);
25875
+ const tronWalletAddress = tronAddress || tronWalletConnect?.address || null;
25793
25876
  const { setTonConnected, setMetaMaskConnected, setTronConnected } = useConnectedWalletsStore();
25794
25877
  useEffect(() => {
25795
25878
  setTonConnected(!!tonAddress);
@@ -25805,7 +25888,7 @@ const EvaaBridgeWithProviders = (props) => {
25805
25888
  tronConnected: isTronConnected,
25806
25889
  evmIsConnected
25807
25890
  });
25808
- return /* @__PURE__ */ jsx(BridgeI18nProvider, { defaultLanguage: props.defaultLanguage, children: /* @__PURE__ */ jsx(
25891
+ return /* @__PURE__ */ jsx(
25809
25892
  ChainStrategyProvider,
25810
25893
  {
25811
25894
  evmWallet: {
@@ -25830,7 +25913,7 @@ const EvaaBridgeWithProviders = (props) => {
25830
25913
  tonApiKey: props.tonApiKey,
25831
25914
  children: /* @__PURE__ */ jsx(EvaaBridgeContent, { ...props })
25832
25915
  }
25833
- ) });
25916
+ );
25834
25917
  };
25835
25918
  const EvaaBridgeContent = ({
25836
25919
  className,
@@ -26102,4 +26185,4 @@ export {
26102
26185
  getQuoteFees as y,
26103
26186
  calculateMinReceived as z
26104
26187
  };
26105
- //# sourceMappingURL=index-BG-E-qt2.js.map
26188
+ //# sourceMappingURL=index-C4YkGAHm.js.map