@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.
@@ -592,6 +592,23 @@ const Button = require$$0__namespace.forwardRef(
592
592
  }
593
593
  );
594
594
  Button.displayName = "Button";
595
+ const ModalContainerContext = require$$0.createContext(void 0);
596
+ const ModalContainerProvider = ({
597
+ containerId,
598
+ children
599
+ }) => {
600
+ return /* @__PURE__ */ jsxRuntime.jsx(ModalContainerContext.Provider, { value: containerId, children });
601
+ };
602
+ const useModalContainer = () => {
603
+ const containerId = require$$0.useContext(ModalContainerContext);
604
+ if (typeof document === "undefined") {
605
+ return null;
606
+ }
607
+ if (!containerId) {
608
+ return document.body;
609
+ }
610
+ return document.getElementById(containerId) || document.body;
611
+ };
595
612
  const ModalContent = ({ children, className }) => {
596
613
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("p-5 flex flex-col h-full", className), children });
597
614
  };
@@ -645,11 +662,11 @@ const Modal = ({
645
662
  isOpen,
646
663
  onClose,
647
664
  children,
648
- className,
649
- modalContainer
665
+ className
650
666
  }) => {
651
667
  const panelRef = require$$0.useRef(null);
652
668
  const lastActiveRef = require$$0.useRef(null);
669
+ const container = useModalContainer();
653
670
  require$$0.useEffect(() => {
654
671
  if (!isOpen) return;
655
672
  lastActiveRef.current = document.activeElement;
@@ -671,7 +688,6 @@ const Modal = ({
671
688
  return () => window.removeEventListener("keydown", onKey);
672
689
  }, [isOpen, onClose]);
673
690
  if (typeof document === "undefined") return null;
674
- const container = modalContainer || document.body;
675
691
  return reactDom.createPortal(
676
692
  /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: isOpen && /* @__PURE__ */ jsxRuntime.jsx(
677
693
  framerMotion.motion.div,
@@ -1091,8 +1107,7 @@ const routePresets = [
1091
1107
  ];
1092
1108
  const SettingModal = ({
1093
1109
  isOpen,
1094
- onClose,
1095
- modalContainer
1110
+ onClose
1096
1111
  }) => {
1097
1112
  const { t } = reactI18next.useTranslation();
1098
1113
  const { toChain } = useChainsStore();
@@ -1126,7 +1141,7 @@ const SettingModal = ({
1126
1141
  );
1127
1142
  const activeBtn = "bg-settings-active hover:bg-settings-active/80 text-settings-active-foreground";
1128
1143
  const notActiveBtn = "bg-settings-button hover:bg-settings-button/80 text-settings-button-foreground";
1129
- return /* @__PURE__ */ jsxRuntime.jsx(Modal, { isOpen, onClose, modalContainer, children: /* @__PURE__ */ jsxRuntime.jsxs(ModalContent, { children: [
1144
+ return /* @__PURE__ */ jsxRuntime.jsx(Modal, { isOpen, onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(ModalContent, { children: [
1130
1145
  /* @__PURE__ */ jsxRuntime.jsxs(ModalHeader, { children: [
1131
1146
  /* @__PURE__ */ jsxRuntime.jsx(ModalTitle, { children: t("settings.title", { defaultValue: "Settings" }) }),
1132
1147
  /* @__PURE__ */ jsxRuntime.jsx(ModalClose, { className: "", onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, { className: "size-6 p-0 [&>rect]:fill-modal-x [&>path]:stroke-modal-x-foreground" }) })
@@ -1729,8 +1744,7 @@ const TokenSelectModal = ({
1729
1744
  isOpen,
1730
1745
  onClose,
1731
1746
  items,
1732
- onChangeAsset,
1733
- modalContainer
1747
+ onChangeAsset
1734
1748
  }) => {
1735
1749
  const { t } = reactI18next.useTranslation();
1736
1750
  const {
@@ -1815,7 +1829,6 @@ const TokenSelectModal = ({
1815
1829
  {
1816
1830
  isOpen,
1817
1831
  onClose: handleClose,
1818
- modalContainer,
1819
1832
  children: /* @__PURE__ */ jsxRuntime.jsxs(ModalContent, { children: [
1820
1833
  /* @__PURE__ */ jsxRuntime.jsxs(ModalHeader, { children: [
1821
1834
  /* @__PURE__ */ jsxRuntime.jsx(ModalTitle, { children: t("bridge.selectToken") }),
@@ -2073,7 +2086,7 @@ function CardFooter({ className, ...props }) {
2073
2086
  }
2074
2087
  );
2075
2088
  }
2076
- const FormHeaderComponent = ({ modalContainer }) => {
2089
+ const FormHeaderComponent = () => {
2077
2090
  const { t } = reactI18next.useTranslation();
2078
2091
  const { isOpen, onClose, onOpen } = useModal();
2079
2092
  const {
@@ -2089,7 +2102,7 @@ const FormHeaderComponent = ({ modalContainer }) => {
2089
2102
  const sum = selectedAssetSymbol.toUpperCase();
2090
2103
  return assets.find((a) => a.symbol.toUpperCase() === sum) ?? assets[0];
2091
2104
  }, [assets, selectedAssetSymbol]);
2092
- return /* @__PURE__ */ jsxRuntime.jsxs(CardHeader, { className: "gap-y-0", children: [
2105
+ return /* @__PURE__ */ jsxRuntime.jsxs(CardHeader, { className: "gap-y-0 flex justify-between items-center", children: [
2093
2106
  /* @__PURE__ */ jsxRuntime.jsxs(CardTitle, { className: "flex items-center gap-2.5", children: [
2094
2107
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-normal leading-3.5 text-muted-foreground", children: t("bridge.selectToken") }),
2095
2108
  /* @__PURE__ */ jsxRuntime.jsx(SelectTokenButton, { token: current, onClick: onOpen })
@@ -2107,24 +2120,19 @@ const FormHeaderComponent = ({ modalContainer }) => {
2107
2120
  onChangeAsset: (symbol) => {
2108
2121
  setSelectedAssetSymbol(symbol);
2109
2122
  onClose();
2110
- },
2111
- modalContainer
2123
+ }
2112
2124
  }
2113
2125
  ),
2114
2126
  /* @__PURE__ */ jsxRuntime.jsx(
2115
2127
  SettingModal,
2116
2128
  {
2117
2129
  isOpen: isOpenSettings,
2118
- onClose: onCloseSettings,
2119
- modalContainer
2130
+ onClose: onCloseSettings
2120
2131
  }
2121
2132
  )
2122
2133
  ] });
2123
2134
  };
2124
- const FormHeader = require$$0.memo(
2125
- FormHeaderComponent,
2126
- (prev, next) => prev.modalContainer === next.modalContainer
2127
- );
2135
+ const FormHeader = require$$0.memo(FormHeaderComponent);
2128
2136
  async function fetchQuotes(req) {
2129
2137
  const params = {
2130
2138
  srcChainKey: req.srcChainKey,
@@ -2672,8 +2680,7 @@ const ChainSelectModal = ({
2672
2680
  onClose,
2673
2681
  items,
2674
2682
  allowedItems,
2675
- onChangeChain,
2676
- modalContainer
2683
+ onChangeChain
2677
2684
  }) => {
2678
2685
  const { t } = reactI18next.useTranslation();
2679
2686
  const [query, setQuery] = require$$0.useState("");
@@ -2762,7 +2769,6 @@ const ChainSelectModal = ({
2762
2769
  {
2763
2770
  isOpen,
2764
2771
  onClose: handleClose,
2765
- modalContainer,
2766
2772
  children: /* @__PURE__ */ jsxRuntime.jsxs(ModalContent, { children: [
2767
2773
  /* @__PURE__ */ jsxRuntime.jsxs(ModalHeader, { children: [
2768
2774
  /* @__PURE__ */ jsxRuntime.jsx(ModalTitle, { children: t("bridge.selectNetwork") }),
@@ -2900,8 +2906,7 @@ const SwapSection = ({
2900
2906
  disableNetworkSelect,
2901
2907
  isSource,
2902
2908
  onSelect,
2903
- onAmountChange,
2904
- modalContainer
2909
+ onAmountChange
2905
2910
  }) => {
2906
2911
  const { isOpen, onClose, onOpen } = useModal();
2907
2912
  const { assetMatrix, selectedAssetSymbol } = useTokensStore();
@@ -2934,9 +2939,9 @@ const SwapSection = ({
2934
2939
  "div",
2935
2940
  {
2936
2941
  className: cn(
2937
- "p-4 flex flex-col gap-4 transition-colors bg-muted",
2942
+ "p-4 flex flex-col gap-4 transition-colors bg-input",
2938
2943
  {
2939
- "bg-muted-focus": isSource && isFocused
2944
+ "bg-input-focus": isSource && isFocused
2940
2945
  },
2941
2946
  className
2942
2947
  ),
@@ -2996,8 +3001,7 @@ const SwapSection = ({
2996
3001
  onClose,
2997
3002
  items: chains,
2998
3003
  allowedItems: allowedChains,
2999
- onChangeChain,
3000
- modalContainer
3004
+ onChangeChain
3001
3005
  }
3002
3006
  )
3003
3007
  ] });
@@ -4083,9 +4087,7 @@ const SubmitButton = () => {
4083
4087
  function short(addr) {
4084
4088
  return addr.slice(0, 4) + "…" + addr.slice(-4);
4085
4089
  }
4086
- const WalletSelectModal = ({
4087
- modalContainer
4088
- }) => {
4090
+ const WalletSelectModal = () => {
4089
4091
  const { t } = reactI18next.useTranslation();
4090
4092
  const { isOpen, onClose } = useWalletSelectModal();
4091
4093
  const { connect, connectors, isPending } = wagmi.useConnect();
@@ -4185,7 +4187,7 @@ const WalletSelectModal = ({
4185
4187
  console.error("Failed to connect wallet:", error);
4186
4188
  }
4187
4189
  };
4188
- return /* @__PURE__ */ jsxRuntime.jsx(Modal, { isOpen, onClose, modalContainer, children: /* @__PURE__ */ jsxRuntime.jsxs(ModalContent, { children: [
4190
+ return /* @__PURE__ */ jsxRuntime.jsx(Modal, { isOpen, onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(ModalContent, { children: [
4189
4191
  /* @__PURE__ */ jsxRuntime.jsxs(ModalHeader, { children: [
4190
4192
  /* @__PURE__ */ jsxRuntime.jsx(ModalTitle, { children: t("wallets.chooseWallet", { defaultValue: "Choose wallet" }) }),
4191
4193
  /* @__PURE__ */ jsxRuntime.jsx(ModalDescription, { children: t("wallets.oneWalletPerEnv", {
@@ -6178,7 +6180,7 @@ const ConfirmStep = () => {
6178
6180
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-3xl font-black relative z-10", children: formatTime })
6179
6181
  ] }) });
6180
6182
  };
6181
- const TransactionManager = ({ modalContainer }) => {
6183
+ const TransactionManager = () => {
6182
6184
  const { current } = useTransactionStore();
6183
6185
  const status = current?.status;
6184
6186
  if (!status || status === "idle") return null;
@@ -6196,7 +6198,7 @@ const TransactionManager = ({ modalContainer }) => {
6196
6198
  step = /* @__PURE__ */ jsxRuntime.jsx(SuccessStep, {});
6197
6199
  }
6198
6200
  return /* @__PURE__ */ jsxRuntime.jsx(Modal, { isOpen: true, onClose: () => {
6199
- }, modalContainer, children: step });
6201
+ }, children: step });
6200
6202
  };
6201
6203
  const useTokensRequest = () => {
6202
6204
  const { setTokens, setSelectedToken, setSelectedAssetSymbol } = useTokensStore();
@@ -7899,7 +7901,7 @@ const EvaaBridgeWithProviders = (props) => {
7899
7901
  require$$0.useEffect(() => {
7900
7902
  setTronConnected(!!tronConnected);
7901
7903
  }, [tronConnected, setTronConnected]);
7902
- return /* @__PURE__ */ jsxRuntime.jsx(
7904
+ return /* @__PURE__ */ jsxRuntime.jsx(ModalContainerProvider, { containerId: props.modalContainerId, children: /* @__PURE__ */ jsxRuntime.jsx(
7903
7905
  ChainStrategyProvider,
7904
7906
  {
7905
7907
  evmWallet: {
@@ -7924,7 +7926,7 @@ const EvaaBridgeWithProviders = (props) => {
7924
7926
  tonApiKey: props.tonApiKey,
7925
7927
  children: /* @__PURE__ */ jsxRuntime.jsx(EvaaBridgeContent, { ...props })
7926
7928
  }
7927
- );
7929
+ ) });
7928
7930
  };
7929
7931
  const EvaaBridgeContent = ({
7930
7932
  className,
@@ -7933,7 +7935,6 @@ const EvaaBridgeContent = ({
7933
7935
  onChainChange
7934
7936
  } = {}) => {
7935
7937
  const { t } = reactI18next.useTranslation();
7936
- const modalContainerRef = require$$0.useRef(null);
7937
7938
  useTokensRequest();
7938
7939
  useChainsRequest();
7939
7940
  const [sendToAnother, setSendToAnother] = require$$0.useState(false);
@@ -8032,9 +8033,8 @@ const EvaaBridgeContent = ({
8032
8033
  "max-w-md w-full mx-auto flex flex-col relative",
8033
8034
  className
8034
8035
  ),
8035
- ref: modalContainerRef,
8036
8036
  children: [
8037
- /* @__PURE__ */ jsxRuntime.jsx(FormHeader, { modalContainer: modalContainerRef.current }),
8037
+ /* @__PURE__ */ jsxRuntime.jsx(FormHeader, {}),
8038
8038
  /* @__PURE__ */ jsxRuntime.jsxs(CardContent, { className: "space-y-[1px]", children: [
8039
8039
  /* @__PURE__ */ jsxRuntime.jsx(
8040
8040
  SwapSection,
@@ -8048,8 +8048,7 @@ const EvaaBridgeContent = ({
8048
8048
  amount,
8049
8049
  isSource: true,
8050
8050
  onAmountChange: handleAmountChange,
8051
- onSelect: handleFromChainChange,
8052
- modalContainer: modalContainerRef.current || void 0
8051
+ onSelect: handleFromChainChange
8053
8052
  }
8054
8053
  ),
8055
8054
  /* @__PURE__ */ jsxRuntime.jsx(SwapButton, {}),
@@ -8063,8 +8062,7 @@ const EvaaBridgeContent = ({
8063
8062
  allowedChains: allowedToChains,
8064
8063
  amount: outputAmount,
8065
8064
  readOnlyAmount: true,
8066
- onSelect: handleToChainChange,
8067
- modalContainer: modalContainerRef.current || void 0
8065
+ onSelect: handleToChainChange
8068
8066
  }
8069
8067
  ),
8070
8068
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -8080,8 +8078,8 @@ const EvaaBridgeContent = ({
8080
8078
  ]
8081
8079
  }
8082
8080
  ),
8083
- /* @__PURE__ */ jsxRuntime.jsx(WalletSelectModal, { modalContainer: modalContainerRef.current }),
8084
- /* @__PURE__ */ jsxRuntime.jsx(TransactionManager, { modalContainer: modalContainerRef.current }),
8081
+ /* @__PURE__ */ jsxRuntime.jsx(WalletSelectModal, {}),
8082
+ /* @__PURE__ */ jsxRuntime.jsx(TransactionManager, {}),
8085
8083
  /* @__PURE__ */ jsxRuntime.jsx(sonner.Toaster, { position: "top-right", richColors: true })
8086
8084
  ] });
8087
8085
  };