@rash2x/bridge-widget 0.1.5 → 0.1.6

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.
@@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4
4
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
5
5
  import { useTranslation } from "react-i18next";
6
6
  import * as require$$0 from "react";
7
- import require$$0__default, { useState, useCallback, useRef, useEffect, useMemo, createContext, useContext, memo, forwardRef } from "react";
7
+ import require$$0__default, { useState, useCallback, createContext, useContext, useRef, useEffect, useMemo, memo, forwardRef } from "react";
8
8
  import { create as create$1 } from "zustand";
9
9
  import { Slot } from "@radix-ui/react-slot";
10
10
  import { cva } from "class-variance-authority";
@@ -550,6 +550,23 @@ const Button = require$$0.forwardRef(
550
550
  }
551
551
  );
552
552
  Button.displayName = "Button";
553
+ const ModalContainerContext = createContext(void 0);
554
+ const ModalContainerProvider = ({
555
+ containerId,
556
+ children
557
+ }) => {
558
+ return /* @__PURE__ */ jsx(ModalContainerContext.Provider, { value: containerId, children });
559
+ };
560
+ const useModalContainer = () => {
561
+ const containerId = useContext(ModalContainerContext);
562
+ if (typeof document === "undefined") {
563
+ return null;
564
+ }
565
+ if (!containerId) {
566
+ return document.body;
567
+ }
568
+ return document.getElementById(containerId) || document.body;
569
+ };
553
570
  const ModalContent = ({ children, className }) => {
554
571
  return /* @__PURE__ */ jsx("div", { className: cn("p-5 flex flex-col h-full", className), children });
555
572
  };
@@ -603,11 +620,11 @@ const Modal = ({
603
620
  isOpen,
604
621
  onClose,
605
622
  children,
606
- className,
607
- modalContainer
623
+ className
608
624
  }) => {
609
625
  const panelRef = useRef(null);
610
626
  const lastActiveRef = useRef(null);
627
+ const container = useModalContainer();
611
628
  useEffect(() => {
612
629
  if (!isOpen) return;
613
630
  lastActiveRef.current = document.activeElement;
@@ -629,7 +646,6 @@ const Modal = ({
629
646
  return () => window.removeEventListener("keydown", onKey);
630
647
  }, [isOpen, onClose]);
631
648
  if (typeof document === "undefined") return null;
632
- const container = modalContainer || document.body;
633
649
  return createPortal(
634
650
  /* @__PURE__ */ jsx(AnimatePresence, { children: isOpen && /* @__PURE__ */ jsx(
635
651
  motion.div,
@@ -1049,8 +1065,7 @@ const routePresets = [
1049
1065
  ];
1050
1066
  const SettingModal = ({
1051
1067
  isOpen,
1052
- onClose,
1053
- modalContainer
1068
+ onClose
1054
1069
  }) => {
1055
1070
  const { t: t2 } = useTranslation();
1056
1071
  const { toChain } = useChainsStore();
@@ -1084,7 +1099,7 @@ const SettingModal = ({
1084
1099
  );
1085
1100
  const activeBtn = "bg-settings-active hover:bg-settings-active/80 text-settings-active-foreground";
1086
1101
  const notActiveBtn = "bg-settings-button hover:bg-settings-button/80 text-settings-button-foreground";
1087
- return /* @__PURE__ */ jsx(Modal, { isOpen, onClose, modalContainer, children: /* @__PURE__ */ jsxs(ModalContent, { children: [
1102
+ return /* @__PURE__ */ jsx(Modal, { isOpen, onClose, children: /* @__PURE__ */ jsxs(ModalContent, { children: [
1088
1103
  /* @__PURE__ */ jsxs(ModalHeader, { children: [
1089
1104
  /* @__PURE__ */ jsx(ModalTitle, { children: t2("settings.title", { defaultValue: "Settings" }) }),
1090
1105
  /* @__PURE__ */ jsx(ModalClose, { className: "", onClick: onClose, children: /* @__PURE__ */ jsx(CloseIcon, { className: "size-6 p-0 [&>rect]:fill-modal-x [&>path]:stroke-modal-x-foreground" }) })
@@ -1687,8 +1702,7 @@ const TokenSelectModal = ({
1687
1702
  isOpen,
1688
1703
  onClose,
1689
1704
  items,
1690
- onChangeAsset,
1691
- modalContainer
1705
+ onChangeAsset
1692
1706
  }) => {
1693
1707
  const { t: t2 } = useTranslation();
1694
1708
  const {
@@ -1773,7 +1787,6 @@ const TokenSelectModal = ({
1773
1787
  {
1774
1788
  isOpen,
1775
1789
  onClose: handleClose,
1776
- modalContainer,
1777
1790
  children: /* @__PURE__ */ jsxs(ModalContent, { children: [
1778
1791
  /* @__PURE__ */ jsxs(ModalHeader, { children: [
1779
1792
  /* @__PURE__ */ jsx(ModalTitle, { children: t2("bridge.selectToken") }),
@@ -2031,7 +2044,7 @@ function CardFooter({ className, ...props }) {
2031
2044
  }
2032
2045
  );
2033
2046
  }
2034
- const FormHeaderComponent = ({ modalContainer }) => {
2047
+ const FormHeaderComponent = () => {
2035
2048
  const { t: t2 } = useTranslation();
2036
2049
  const { isOpen, onClose, onOpen } = useModal();
2037
2050
  const {
@@ -2047,7 +2060,7 @@ const FormHeaderComponent = ({ modalContainer }) => {
2047
2060
  const sum = selectedAssetSymbol.toUpperCase();
2048
2061
  return assets.find((a) => a.symbol.toUpperCase() === sum) ?? assets[0];
2049
2062
  }, [assets, selectedAssetSymbol]);
2050
- return /* @__PURE__ */ jsxs(CardHeader, { className: "gap-y-0", children: [
2063
+ return /* @__PURE__ */ jsxs(CardHeader, { className: "gap-y-0 flex justify-between items-center", children: [
2051
2064
  /* @__PURE__ */ jsxs(CardTitle, { className: "flex items-center gap-2.5", children: [
2052
2065
  /* @__PURE__ */ jsx("span", { className: "text-sm font-normal leading-3.5 text-muted-foreground", children: t2("bridge.selectToken") }),
2053
2066
  /* @__PURE__ */ jsx(SelectTokenButton, { token: current, onClick: onOpen })
@@ -2065,24 +2078,19 @@ const FormHeaderComponent = ({ modalContainer }) => {
2065
2078
  onChangeAsset: (symbol) => {
2066
2079
  setSelectedAssetSymbol(symbol);
2067
2080
  onClose();
2068
- },
2069
- modalContainer
2081
+ }
2070
2082
  }
2071
2083
  ),
2072
2084
  /* @__PURE__ */ jsx(
2073
2085
  SettingModal,
2074
2086
  {
2075
2087
  isOpen: isOpenSettings,
2076
- onClose: onCloseSettings,
2077
- modalContainer
2088
+ onClose: onCloseSettings
2078
2089
  }
2079
2090
  )
2080
2091
  ] });
2081
2092
  };
2082
- const FormHeader = memo(
2083
- FormHeaderComponent,
2084
- (prev, next) => prev.modalContainer === next.modalContainer
2085
- );
2093
+ const FormHeader = memo(FormHeaderComponent);
2086
2094
  async function fetchQuotes(req) {
2087
2095
  const params = {
2088
2096
  srcChainKey: req.srcChainKey,
@@ -2630,8 +2638,7 @@ const ChainSelectModal = ({
2630
2638
  onClose,
2631
2639
  items,
2632
2640
  allowedItems,
2633
- onChangeChain,
2634
- modalContainer
2641
+ onChangeChain
2635
2642
  }) => {
2636
2643
  const { t: t2 } = useTranslation();
2637
2644
  const [query, setQuery] = useState("");
@@ -2720,7 +2727,6 @@ const ChainSelectModal = ({
2720
2727
  {
2721
2728
  isOpen,
2722
2729
  onClose: handleClose,
2723
- modalContainer,
2724
2730
  children: /* @__PURE__ */ jsxs(ModalContent, { children: [
2725
2731
  /* @__PURE__ */ jsxs(ModalHeader, { children: [
2726
2732
  /* @__PURE__ */ jsx(ModalTitle, { children: t2("bridge.selectNetwork") }),
@@ -2858,8 +2864,7 @@ const SwapSection = ({
2858
2864
  disableNetworkSelect,
2859
2865
  isSource,
2860
2866
  onSelect,
2861
- onAmountChange,
2862
- modalContainer
2867
+ onAmountChange
2863
2868
  }) => {
2864
2869
  const { isOpen, onClose, onOpen } = useModal();
2865
2870
  const { assetMatrix, selectedAssetSymbol } = useTokensStore();
@@ -2892,9 +2897,9 @@ const SwapSection = ({
2892
2897
  "div",
2893
2898
  {
2894
2899
  className: cn(
2895
- "p-4 flex flex-col gap-4 transition-colors bg-muted",
2900
+ "p-4 flex flex-col gap-4 transition-colors bg-input",
2896
2901
  {
2897
- "bg-muted-focus": isSource && isFocused
2902
+ "bg-input-focus": isSource && isFocused
2898
2903
  },
2899
2904
  className
2900
2905
  ),
@@ -2954,8 +2959,7 @@ const SwapSection = ({
2954
2959
  onClose,
2955
2960
  items: chains,
2956
2961
  allowedItems: allowedChains,
2957
- onChangeChain,
2958
- modalContainer
2962
+ onChangeChain
2959
2963
  }
2960
2964
  )
2961
2965
  ] });
@@ -4041,9 +4045,7 @@ const SubmitButton = () => {
4041
4045
  function short(addr) {
4042
4046
  return addr.slice(0, 4) + "…" + addr.slice(-4);
4043
4047
  }
4044
- const WalletSelectModal = ({
4045
- modalContainer
4046
- }) => {
4048
+ const WalletSelectModal = () => {
4047
4049
  const { t: t2 } = useTranslation();
4048
4050
  const { isOpen, onClose } = useWalletSelectModal();
4049
4051
  const { connect, connectors, isPending } = useConnect();
@@ -4143,7 +4145,7 @@ const WalletSelectModal = ({
4143
4145
  console.error("Failed to connect wallet:", error);
4144
4146
  }
4145
4147
  };
4146
- return /* @__PURE__ */ jsx(Modal, { isOpen, onClose, modalContainer, children: /* @__PURE__ */ jsxs(ModalContent, { children: [
4148
+ return /* @__PURE__ */ jsx(Modal, { isOpen, onClose, children: /* @__PURE__ */ jsxs(ModalContent, { children: [
4147
4149
  /* @__PURE__ */ jsxs(ModalHeader, { children: [
4148
4150
  /* @__PURE__ */ jsx(ModalTitle, { children: t2("wallets.chooseWallet", { defaultValue: "Choose wallet" }) }),
4149
4151
  /* @__PURE__ */ jsx(ModalDescription, { children: t2("wallets.oneWalletPerEnv", {
@@ -6136,7 +6138,7 @@ const ConfirmStep = () => {
6136
6138
  /* @__PURE__ */ jsx("div", { className: "text-3xl font-black relative z-10", children: formatTime })
6137
6139
  ] }) });
6138
6140
  };
6139
- const TransactionManager = ({ modalContainer }) => {
6141
+ const TransactionManager = () => {
6140
6142
  const { current } = useTransactionStore();
6141
6143
  const status = current?.status;
6142
6144
  if (!status || status === "idle") return null;
@@ -6154,7 +6156,7 @@ const TransactionManager = ({ modalContainer }) => {
6154
6156
  step = /* @__PURE__ */ jsx(SuccessStep, {});
6155
6157
  }
6156
6158
  return /* @__PURE__ */ jsx(Modal, { isOpen: true, onClose: () => {
6157
- }, modalContainer, children: step });
6159
+ }, children: step });
6158
6160
  };
6159
6161
  const useTokensRequest = () => {
6160
6162
  const { setTokens, setSelectedToken, setSelectedAssetSymbol } = useTokensStore();
@@ -7857,7 +7859,7 @@ const EvaaBridgeWithProviders = (props) => {
7857
7859
  useEffect(() => {
7858
7860
  setTronConnected(!!tronConnected);
7859
7861
  }, [tronConnected, setTronConnected]);
7860
- return /* @__PURE__ */ jsx(
7862
+ return /* @__PURE__ */ jsx(ModalContainerProvider, { containerId: props.modalContainerId, children: /* @__PURE__ */ jsx(
7861
7863
  ChainStrategyProvider,
7862
7864
  {
7863
7865
  evmWallet: {
@@ -7882,7 +7884,7 @@ const EvaaBridgeWithProviders = (props) => {
7882
7884
  tonApiKey: props.tonApiKey,
7883
7885
  children: /* @__PURE__ */ jsx(EvaaBridgeContent, { ...props })
7884
7886
  }
7885
- );
7887
+ ) });
7886
7888
  };
7887
7889
  const EvaaBridgeContent = ({
7888
7890
  className,
@@ -7891,7 +7893,6 @@ const EvaaBridgeContent = ({
7891
7893
  onChainChange
7892
7894
  } = {}) => {
7893
7895
  const { t: t2 } = useTranslation();
7894
- const modalContainerRef = useRef(null);
7895
7896
  useTokensRequest();
7896
7897
  useChainsRequest();
7897
7898
  const [sendToAnother, setSendToAnother] = useState(false);
@@ -7990,9 +7991,8 @@ const EvaaBridgeContent = ({
7990
7991
  "max-w-md w-full mx-auto flex flex-col relative",
7991
7992
  className
7992
7993
  ),
7993
- ref: modalContainerRef,
7994
7994
  children: [
7995
- /* @__PURE__ */ jsx(FormHeader, { modalContainer: modalContainerRef.current }),
7995
+ /* @__PURE__ */ jsx(FormHeader, {}),
7996
7996
  /* @__PURE__ */ jsxs(CardContent, { className: "space-y-[1px]", children: [
7997
7997
  /* @__PURE__ */ jsx(
7998
7998
  SwapSection,
@@ -8006,8 +8006,7 @@ const EvaaBridgeContent = ({
8006
8006
  amount,
8007
8007
  isSource: true,
8008
8008
  onAmountChange: handleAmountChange,
8009
- onSelect: handleFromChainChange,
8010
- modalContainer: modalContainerRef.current || void 0
8009
+ onSelect: handleFromChainChange
8011
8010
  }
8012
8011
  ),
8013
8012
  /* @__PURE__ */ jsx(SwapButton, {}),
@@ -8021,8 +8020,7 @@ const EvaaBridgeContent = ({
8021
8020
  allowedChains: allowedToChains,
8022
8021
  amount: outputAmount,
8023
8022
  readOnlyAmount: true,
8024
- onSelect: handleToChainChange,
8025
- modalContainer: modalContainerRef.current || void 0
8023
+ onSelect: handleToChainChange
8026
8024
  }
8027
8025
  ),
8028
8026
  /* @__PURE__ */ jsx(
@@ -8038,8 +8036,8 @@ const EvaaBridgeContent = ({
8038
8036
  ]
8039
8037
  }
8040
8038
  ),
8041
- /* @__PURE__ */ jsx(WalletSelectModal, { modalContainer: modalContainerRef.current }),
8042
- /* @__PURE__ */ jsx(TransactionManager, { modalContainer: modalContainerRef.current }),
8039
+ /* @__PURE__ */ jsx(WalletSelectModal, {}),
8040
+ /* @__PURE__ */ jsx(TransactionManager, {}),
8043
8041
  /* @__PURE__ */ jsx(Toaster, { position: "top-right", richColors: true })
8044
8042
  ] });
8045
8043
  };