@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.
@@ -22748,7 +22748,7 @@ class WalletConnectModal {
22748
22748
  }
22749
22749
  async initUi() {
22750
22750
  if (typeof window !== "undefined") {
22751
- await import("./index-Byi5_0tY.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,17 +23074,21 @@ 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
- acc.push({
23059
- id: walletId,
23060
- name,
23061
- icon,
23062
- address: account,
23063
- onDisconnect: () => strategy.disconnect()
23064
- });
23077
+ if (walletId === "tronlink" && tronWalletConnect?.isConnected) {
23078
+ return acc;
23079
+ } else {
23080
+ acc.push({
23081
+ id: walletId,
23082
+ name,
23083
+ icon,
23084
+ address: account,
23085
+ onDisconnect: () => strategy.disconnect()
23086
+ });
23087
+ }
23065
23088
  }
23066
23089
  return acc;
23067
23090
  }, []);
23068
- if (tronWalletConnect.isConnected && tronWalletConnect.address) {
23091
+ if (tronWalletConnect && tronWalletConnect.isConnected && tronWalletConnect.address) {
23069
23092
  connectedWallets.push({
23070
23093
  id: "tronwc",
23071
23094
  name: t2("wallets.walletConnect"),
@@ -23079,7 +23102,7 @@ const WalletSelectModal = () => {
23079
23102
  if (isEvmConnector && metaMaskWallet?.isConnected()) {
23080
23103
  return true;
23081
23104
  }
23082
- if (walletId === "tronwc" && tronWalletConnect.isConnected) {
23105
+ if ((walletId === "tronwc" || walletId === "tronlink") && tronWalletConnect?.isConnected) {
23083
23106
  return true;
23084
23107
  }
23085
23108
  return connectedWallets.some((w2) => w2.id === walletId);
@@ -23107,12 +23130,15 @@ const WalletSelectModal = () => {
23107
23130
  icon: TronLinkIcon,
23108
23131
  enabled: true
23109
23132
  },
23110
- {
23111
- id: "tronwc",
23112
- name: t2("wallets.walletConnect"),
23113
- icon: WalletConnectIcon,
23114
- enabled: true
23115
- }
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
+ ] : []
23116
23142
  ];
23117
23143
  const notConnected = (w2) => !isWalletConnected(w2.id);
23118
23144
  const categories = [
@@ -25107,6 +25133,7 @@ function ChainStrategyProvider({
25107
25133
  () => new TronChainStrategy({
25108
25134
  tronAddress: tronWallet.address,
25109
25135
  tronConnected: tronWallet.connected,
25136
+ isWalletConnect: tronWallet.isWalletConnect,
25110
25137
  tronSelect: tronWallet.select,
25111
25138
  tronConnect: tronWallet.connect,
25112
25139
  tronDisconnect: tronWallet.disconnect
@@ -25114,6 +25141,7 @@ function ChainStrategyProvider({
25114
25141
  [
25115
25142
  tronWallet.address,
25116
25143
  tronWallet.connected,
25144
+ tronWallet.isWalletConnect,
25117
25145
  tronWallet.select,
25118
25146
  tronWallet.connect,
25119
25147
  tronWallet.disconnect
@@ -25767,7 +25795,68 @@ const useAutoSelectNetwork = ({
25767
25795
  setFromChain
25768
25796
  ]);
25769
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
+ }));
25770
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) => {
25771
25860
  const [tonConnectUI] = useTonConnectUI();
25772
25861
  const tonAddress = useTonAddress();
25773
25862
  const { address: evmAddress, isConnected: evmIsConnected } = useAccount();
@@ -25781,6 +25870,9 @@ const EvaaBridgeWithProviders = (props) => {
25781
25870
  connect: tronConnect,
25782
25871
  disconnect: tronDisconnect
25783
25872
  } = useWallet();
25873
+ const tronWalletConnect = useTronWalletConnectContextSafe();
25874
+ const isTronConnected = tronConnected || (tronWalletConnect?.isConnected ?? false);
25875
+ const tronWalletAddress = tronAddress || tronWalletConnect?.address || null;
25784
25876
  const { setTonConnected, setMetaMaskConnected, setTronConnected } = useConnectedWalletsStore();
25785
25877
  useEffect(() => {
25786
25878
  setTonConnected(!!tonAddress);
@@ -25789,14 +25881,14 @@ const EvaaBridgeWithProviders = (props) => {
25789
25881
  setMetaMaskConnected(!!evmIsConnected);
25790
25882
  }, [evmIsConnected, setMetaMaskConnected]);
25791
25883
  useEffect(() => {
25792
- setTronConnected(!!tronConnected);
25793
- }, [tronConnected, setTronConnected]);
25884
+ setTronConnected(!!isTronConnected);
25885
+ }, [isTronConnected, setTronConnected]);
25794
25886
  useAutoSelectNetwork({
25795
25887
  tonAddress,
25796
- tronConnected,
25888
+ tronConnected: isTronConnected,
25797
25889
  evmIsConnected
25798
25890
  });
25799
- return /* @__PURE__ */ jsx(BridgeI18nProvider, { defaultLanguage: props.defaultLanguage, children: /* @__PURE__ */ jsx(
25891
+ return /* @__PURE__ */ jsx(
25800
25892
  ChainStrategyProvider,
25801
25893
  {
25802
25894
  evmWallet: {
@@ -25811,8 +25903,8 @@ const EvaaBridgeWithProviders = (props) => {
25811
25903
  address: tonAddress
25812
25904
  },
25813
25905
  tronWallet: {
25814
- address: tronAddress,
25815
- connected: tronConnected,
25906
+ address: tronWalletAddress,
25907
+ connected: isTronConnected,
25816
25908
  select: tronSelect,
25817
25909
  connect: tronConnect,
25818
25910
  disconnect: tronDisconnect
@@ -25821,7 +25913,7 @@ const EvaaBridgeWithProviders = (props) => {
25821
25913
  tonApiKey: props.tonApiKey,
25822
25914
  children: /* @__PURE__ */ jsx(EvaaBridgeContent, { ...props })
25823
25915
  }
25824
- ) });
25916
+ );
25825
25917
  };
25826
25918
  const EvaaBridgeContent = ({
25827
25919
  className,
@@ -26093,4 +26185,4 @@ export {
26093
26185
  getQuoteFees as y,
26094
26186
  calculateMinReceived as z
26095
26187
  };
26096
- //# sourceMappingURL=index-D8wi96xC.js.map
26188
+ //# sourceMappingURL=index-C4YkGAHm.js.map