@layerswap/widget 1.0.0 → 1.0.1

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.
@@ -35,7 +35,7 @@ export const ModalContent = (props) => {
35
35
  }, [isOpen]);
36
36
  if (!isOpen)
37
37
  return null;
38
- const modalElement = (_jsxs("div", { className: clsx("absolute inset-0 z-50 bg-secondary-700 rounded-t-3xl sm:rounded-3xl flex flex-col", className), children: [(header || showCloseButton) && (_jsx("div", { className: "w-full relative", children: _jsxs("div", { className: "flex items-center w-full text-left justify-between px-4 pt-2 pb-2 gap-x-2", children: [_jsx("div", { className: "flex-1 text-lg text-secondary-text font-semibold w-full flex justify-end", children: header }), showCloseButton && (_jsx(IconButton, { onClick: closeModal, className: "active:animate-press-down", icon: _jsx(X, { strokeWidth: 3 }) }))] }) })), _jsx("div", { className: "flex flex-col w-full h-full max-h-[90dvh] px-4 styled-scroll overflow-x-hidden overflow-y-auto relative pb-3", children: typeof children === 'function' ? children({ closeModal, shouldFocus }) : children })] }));
38
+ const modalElement = (_jsxs("div", { className: clsx("absolute inset-0 z-50 bg-secondary-700 rounded-t-3xl sm:rounded-3xl flex flex-col", className), children: [(header || showCloseButton) && (_jsx("div", { className: "w-full relative", children: _jsxs("div", { className: "flex items-center w-full text-left justify-between px-4 pt-2 pb-2 gap-x-2 sm:gap-x-1", children: [_jsx("div", { className: "flex-1 text-lg text-secondary-text font-semibold w-full flex justify-end", children: header }), showCloseButton && (_jsx(IconButton, { onClick: closeModal, className: "active:animate-press-down", icon: _jsx(X, { strokeWidth: 3 }) }))] }) })), _jsx("div", { className: "flex flex-col w-full h-full max-h-[90dvh] px-4 styled-scroll overflow-x-hidden overflow-y-auto relative pb-3", children: typeof children === 'function' ? children({ closeModal, shouldFocus }) : children })] }));
39
39
  const widgetElement = document.getElementById('widget');
40
40
  if (!widgetElement) {
41
41
  console.warn('Widget element not found, modal will not render');
@@ -11,7 +11,7 @@ import { AnimatePresence, motion } from 'framer-motion';
11
11
  import { Drawer } from './vaul';
12
12
  import AppSettings from '../../lib/AppSettings';
13
13
  const Comp = ({ children, show, setShow, header, description, onClose, onAnimationEnd, className }) => {
14
- const { isMobileWithPortal: isMobile } = useWindowDimensions();
14
+ const { isMobileWithPortal: isMobile, isMobile: isMobileWithoutPortal } = useWindowDimensions();
15
15
  let [headerRef, { height }] = useMeasure();
16
16
  const { setHeaderHeight } = useSnapPoints();
17
17
  const expandRef = useRef(null);
@@ -77,7 +77,7 @@ const Comp = ({ children, show, setShow, header, description, onClose, onAnimati
77
77
  }, [isMobile]);
78
78
  if (!loaded)
79
79
  return null;
80
- const container = isMobile ? undefined : document.getElementById('widget');
80
+ const container = (isMobile && AppSettings.ThemeData?.enablePortal) ? undefined : document.getElementById('widget');
81
81
  return (_jsx(Drawer.Root, { open: show, onOpenChange: handleOpenChange, container: container, snapPoints: snapPointsHeight, activeSnapPoint: snap, setActiveSnapPoint: setSnap, fadeFromIndex: 0, onDrag: (e) => {
82
82
  if (e.movementY < 0 && !expandRef.current?.classList.contains('hidden'))
83
83
  expandRef.current?.classList.add('hidden');
@@ -86,7 +86,7 @@ const Comp = ({ children, show, setShow, header, description, onClose, onAnimati
86
86
  : _jsx(motion.div, { className: 'absolute inset-0 z-50 bg-black/50 block', initial: { opacity: 0.5 }, animate: { opacity: 1 }, exit: { opacity: 0 } }, "backdrop") }), _jsxs(Drawer.Content, { "data-testid": "content", className: clsx('absolute flex flex-col bg-secondary-700 rounded-t-3xl bottom-0 left-0 right-0 h-full z-50 pb-4 text-primary-text ring-0! outline-hidden! ', className, {
87
87
  'border-none! rounded-none!': snap === 1,
88
88
  '!fixed sm:!absolute': AppSettings.ThemeData?.enablePortal == true,
89
- }), children: [_jsxs("div", { ref: headerRef, className: 'w-full relative', children: [isMobile &&
89
+ }), children: [_jsxs("div", { ref: headerRef, className: 'w-full relative', children: [isMobileWithoutPortal &&
90
90
  _jsx("div", { className: "flex justify-center w-full mt-2 mb-[6px]", children: _jsx(Drawer.Handle, { className: '!w-12 !bg-primary-text-tertiary' }) }), _jsxs("div", { className: 'flex items-center w-full text-left justify-between px-4 sm:pt-2 pb-2', children: [_jsx(Drawer.Title, { className: "text-lg text-secondary-text font-semibold w-full", children: header }), _jsx(Drawer.Close, { asChild: true, children: _jsx("div", { children: _jsx(IconButton, { className: 'inline-flex active:animate-press-down', icon: _jsx(X, { strokeWidth: 3 }) }) }) })] }), description &&
91
91
  _jsx(Drawer.Description, { className: "text-sm mt-2 text-secondary-text px-4", children: description })] }), _jsxs("div", { className: clsx('flex flex-col w-full h-fit max-h-[90dvh] px-4 styled-scroll overflow-x-hidden relative', {
92
92
  'overflow-y-auto h-full': snap === 1,
@@ -44,19 +44,20 @@ const ExchangeForm = ({ partner }) => {
44
44
  const handleActionHover = (value) => {
45
45
  setActionTempValue(value);
46
46
  };
47
- return (_jsxs(_Fragment, { children: [_jsx(DepositMethodComponent, {}), _jsxs(Form, { className: "h-full grow flex flex-col flex-1 justify-between w-full gap-3", children: [_jsx(Widget.Content, { children: _jsx("div", { className: "w-full max-sm:min-h-[79svh] flex flex-col justify-between mt-2 sm:mt-0", children: _jsx("div", { className: 'flex-col relative flex justify-between gap-1.5 w-full leading-4', children: _jsxs("div", { className: "flex flex-col w-full space-y-4", children: [_jsxs("div", { className: "space-y-2", children: [_jsx("label", { htmlFor: "From", className: "block font-normal text-secondary-text text-base leading-5", children: "Send from" }), _jsx("div", { className: "relative", children: _jsx(CexPicker, {}) })] }), _jsxs("div", { className: "space-y-2", children: [_jsx("label", { htmlFor: "From", className: "block font-normal text-secondary-text text-base leading-5", children: "Send to" }), _jsx("div", { className: "relative group exchange-picker", children: _jsx(RoutePicker, { direction: "to", isExchange: true }) }), _jsx("div", { className: "hover:bg-secondary-300 bg-secondary-500 rounded-2xl p-3", children: _jsx(Address, { partner: partner, children: ({ addressItem }) => {
48
- const addressProviderIcon = (partner?.is_wallet && addressItem?.group === AddressGroup.FromQuery && partner?.logo) ? partner.logo : undefined;
49
- return _jsx(_Fragment, { children: addressItem ? _jsx(_Fragment, { children: _jsx(AddressButton, { address: addressItem.address, network: destination, wallet: wallet, addressProviderIcon: addressProviderIcon }) })
50
- : destination_address ? _jsx(_Fragment, { children: _jsx(AddressButton, { address: destination_address }) })
51
- :
52
- _jsxs("span", { className: "flex items-center", children: [_jsx(SelectedEchangePlaceholder, { placeholder: 'Enter destination address' }), _jsx("span", { className: "absolute right-0 px-1 pr-5 pointer-events-none text-primary-text", children: _jsx(ChevronDown, { className: "h-4 w-4 text-secondary-text", "aria-hidden": "true" }) })] }) });
53
- } }) })] }), _jsxs("div", { className: "bg-secondary-500 rounded-2xl p-3 group space-y-2", onClick: setShowQuickActions, ref: parentRef, children: [_jsxs("div", { className: "flex justify-between items-center", children: [_jsx("label", { htmlFor: "From", className: "block font-normal text-secondary-text text-base ml-2 leading-5", children: "Enter amount" }), from && fromCurrency && minAllowedAmount && maxAmountFromApi &&
54
- _jsx("div", { className: clsx({
55
- "hidden": !showQuickActions,
56
- "block": showQuickActions,
57
- }, "group-hover:block"), children: _jsx(MinMax, { from: from, fromCurrency: fromCurrency, limitsMinAmount: minAllowedAmount, limitsMaxAmount: maxAmountFromApi, onActionHover: handleActionHover, depositMethod: "deposit_address" }) })] }), _jsx("div", { className: "relative group exchange-amount-field", children: _jsx(AmountField, { className: "!pb-0 !rounded-xl", fee: quote, usdPosition: "right", actionValue: actionTempValue }) })] })] }) }) }) }), _jsxs(Widget.Footer, { showPoweredBy: true, children: [_jsxs("div", { className: "space-y-3", children: [routeValidation.message
58
- ? _jsx(ValidationError, {})
59
- : null, _jsx(QuoteDetails, { swapValues: values, quote: quote, isQuoteLoading: isQuoteLoading })] }), _jsx(FormButton, { shouldConnectWallet: false, values: values, disabled: !isValid || isSubmitting || !quote || isQuoteLoading, error: error, isSubmitting: isSubmitting, partner: partner })] })] })] }));
47
+ return (_jsxs(_Fragment, { children: [_jsx(DepositMethodComponent, {}), _jsxs(Form, { className: "h-full grow flex flex-col flex-1 justify-between w-full gap-3", children: [_jsxs(Widget.Content, { children: [_jsxs("div", { className: "space-y-2", children: [_jsx("label", { htmlFor: "From", className: "block font-normal text-secondary-text text-base leading-5", children: "Send from" }), _jsx("div", { className: "relative", children: _jsx(CexPicker, {}) })] }), _jsxs("div", { className: "space-y-2", children: [_jsx("label", { htmlFor: "From", className: "block font-normal text-secondary-text text-base leading-5", children: "Send to" }), _jsx("div", { className: "relative group exchange-picker", children: _jsx(RoutePicker, { direction: "to", isExchange: true }) }), _jsx("div", { className: "hover:bg-secondary-300 bg-secondary-500 rounded-2xl p-3", children: _jsx(Address, { partner: partner, children: ({ addressItem }) => {
48
+ const addressProviderIcon = (partner?.is_wallet && addressItem?.group === AddressGroup.FromQuery && partner?.logo) ? partner.logo : undefined;
49
+ return _jsx(_Fragment, { children: addressItem ? _jsx(_Fragment, { children: _jsx(AddressButton, { address: addressItem.address, network: destination, wallet: wallet, addressProviderIcon: addressProviderIcon }) })
50
+ : destination_address ? _jsx(_Fragment, { children: _jsx(AddressButton, { address: destination_address }) })
51
+ :
52
+ _jsxs("span", { className: "flex items-center", children: [_jsx(SelectedEchangePlaceholder, { placeholder: 'Enter destination address' }), _jsx("span", { className: "absolute right-0 px-1 pr-5 pointer-events-none text-primary-text", children: _jsx(ChevronDown, { className: "h-4 w-4 text-secondary-text", "aria-hidden": "true" }) })] }) });
53
+ } }) })] }), _jsxs("div", { className: "bg-secondary-500 rounded-2xl p-3 group space-y-2", onClick: setShowQuickActions, ref: parentRef, children: [_jsxs("div", { className: "flex justify-between items-center", children: [_jsx("label", { htmlFor: "From", className: "block font-normal text-secondary-text text-base ml-2 leading-5", children: "Enter amount" }), from && fromCurrency && minAllowedAmount && maxAmountFromApi &&
54
+ _jsx("div", { className: clsx({
55
+ "hidden": !showQuickActions,
56
+ "block": showQuickActions,
57
+ }, "group-hover:block"), children: _jsx(MinMax, { from: from, fromCurrency: fromCurrency, limitsMinAmount: minAllowedAmount, limitsMaxAmount: maxAmountFromApi, onActionHover: handleActionHover, depositMethod: "deposit_address" }) })] }), _jsx("div", { className: "relative group exchange-amount-field", children: _jsx(AmountField, { className: "pb-0! rounded-xl!", fee: quote, usdPosition: "right", actionValue: actionTempValue }) })] }), routeValidation.message
58
+ ?
59
+ _jsx(ValidationError, {})
60
+ : _jsx(_Fragment, {}), _jsx(QuoteDetails, { swapValues: values, quote: quote, isQuoteLoading: isQuoteLoading })] }), _jsx(Widget.Footer, { showPoweredBy: true, children: _jsx(FormButton, { shouldConnectWallet: false, values: values, disabled: !isValid || isSubmitting || !quote || isQuoteLoading, error: error, isSubmitting: isSubmitting, partner: partner }) })] })] }));
60
61
  };
61
62
  export default ExchangeForm;
62
63
  const AddressButton = ({ address, network, wallet, addressProviderIcon }) => {
@@ -17,6 +17,7 @@ import { Checkbox } from "../../../components/shadcn/checkbox";
17
17
  import { ImageWithFallback } from "../../../components/Common/ImageWithFallback";
18
18
  import { SearchComponent } from "../../../components/Input/Search";
19
19
  import { isMobile } from "../../../lib/wallets/utils/isMobile";
20
+ import AppSettings from "../../../lib/AppSettings";
20
21
  const ConnectorsList = ({ onFinish }) => {
21
22
  const { providers } = useWallet();
22
23
  const { setSelectedConnector, selectedProvider, setSelectedProvider, selectedConnector, selectedMultiChainConnector, setSelectedMultiChainConnector } = useConnectModal();
@@ -115,8 +116,8 @@ const ConnectorsList = ({ onFinish }) => {
115
116
  }
116
117
  return (_jsx(_Fragment, { children: _jsxs("div", { className: "text-primary-text space-y-3", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx(SearchComponent, { searchQuery: searchValue || "", setSearchQuery: setSearchValue, placeholder: allHiddenConnectors.length > 300 ? "Search through 400+ wallets..." : "Search wallet", className: "w-full" }), (!selectedProvider || selectedProvider?.isSelectedFromFilter) &&
117
118
  _jsx(ProviderPicker, { providers: filteredProviders, selectedProviderName: selectedProvider?.name, setSelectedProviderName: handleSelectProvider })] }), _jsx("div", { onScroll: handleScroll, className: clsx('overflow-y-scroll -mr-4 pr-2 scrollbar:!w-1.5 scrollbar:!h-1.5 scrollbar-thumb:bg-transparent', {
118
- 'h-[55vh]': isMobileSize,
119
- 'h-[265px]': !isMobileSize,
119
+ 'h-[55vh]': isMobileSize && AppSettings.ThemeData?.enablePortal,
120
+ 'h-[265px]': !isMobileSize || !AppSettings.ThemeData?.enablePortal,
120
121
  'styled-scroll': isScrolling
121
122
  }), children: _jsx("div", { className: 'grid grid-cols-2 gap-2', children: allConnectors.map(item => {
122
123
  const provider = featuredProviders.find(p => p.name === item.providerName);
@@ -130,19 +131,19 @@ const LoadingConnect = ({ onRetry, selectedConnector, connectionError }) => {
130
131
  const isMobilePlatform = isMobile();
131
132
  if (selectedConnector.installUrl) {
132
133
  return _jsx("div", { className: clsx('w-full flex flex-col justify-center items-center font-semibold relative', {
133
- 'h-[60vh]': isMobileSize,
134
- 'h-[360px]': !isMobileSize,
134
+ 'h-[60vh]': isMobileSize && AppSettings.ThemeData?.enablePortal,
135
+ 'h-[300px]': !isMobileSize || !AppSettings.ThemeData?.enablePortal,
135
136
  }), children: _jsxs("div", { className: "flex flex-col gap-4 items-center justify-end row-start-2 row-span-1", children: [_jsxs("div", { className: "flex-col flex items-center gap-1", children: [_jsx(ConnectorIcon, { className: "w-11 h-auto p-0.5 rounded-md bg-secondary-800" }), _jsxs("p", { className: 'text-base font-semibold', children: [_jsx("span", { children: selectedConnector?.name }), " ", _jsx("span", { children: "is not installed" })] })] }), _jsx("button", { onClick: () => window.open(selectedConnector.installUrl, '_blank'), type: "button", className: "px-3 py-1 rounded-full bg-secondary-600 text-primary-500 font-semibold text-base hover:brightness-125 transition-all duration-200", children: "INSTALL" })] }) });
136
137
  }
137
138
  return (_jsxs("div", { className: clsx('w-full flex flex-col justify-center items-center font-semibold relative', {
138
- 'h-[60vh]': isMobileSize,
139
- 'h-[360px]': !isMobileSize,
139
+ 'h-[60vh]': isMobileSize && AppSettings.ThemeData?.enablePortal,
140
+ 'h-[300px]': !isMobileSize || !AppSettings.ThemeData?.enablePortal,
140
141
  'pb-20': connectionError
141
142
  }), children: [selectedConnector &&
142
143
  _jsxs("div", { className: "flex flex-col gap-3 items-center justify-end row-start-2 row-span-1", children: [_jsx("div", { className: "flex-col flex items-center", children: _jsxs("div", { className: "grid grid-cols-3 items-center gap-2", children: [_jsx("div", { className: "p-3 bg-secondary-700 rounded-lg z-10", children: _jsx(LayerSwapLogoSmall, { className: "w-11 h-auto" }) }), connectionError ?
143
144
  _jsx(Link2Off, { className: "w-auto h-auto place-self-center" })
144
145
  :
145
- _jsx("div", { className: "loader !text-[3px] place-self-center" }), _jsx("div", { className: "p-3 bg-secondary-700 rounded-lg z-10", children: _jsx(ConnectorIcon, { className: "w-11 h-auto" }) })] }) }), !connectionError &&
146
+ _jsx("div", { className: "loader text-[3px]! place-self-center" }), _jsx("div", { className: "p-3 bg-secondary-700 rounded-lg z-10", children: _jsx(ConnectorIcon, { className: "w-11 h-auto" }) })] }) }), !connectionError &&
146
147
  _jsxs("div", { className: "py-1 text-center", children: [_jsx("p", { className: "text-base font-medium", children: isMobilePlatform ? 'Approve connection in your wallet' : 'Approve connection in your wallet pop-up' }), _jsx("p", { className: "text-sm font-normal text-secondary-text", children: isMobilePlatform ? "Don't see the request? Check your wallet app." : "Don't see a pop-up? Check your browser windows." })] })] }), connectionError &&
147
148
  _jsxs("div", { className: `bg-secondary-500 rounded-lg flex flex-col gap-1.5 items-center p-3 w-full absolute bottom-0`, children: [_jsxs("div", { className: "flex w-full gap-1 text-sm text-secondary-text justify-start", children: [_jsx(CircleX, { className: "w-5 h-5 stroke-primary-500 mr-1 mt-0.5 flex-shrink-0" }), _jsxs("div", { className: 'flex flex-col gap-1', children: [_jsx("p", { className: 'text-base text-white', children: "Failed to connect" }), _jsx("p", { className: "text-sm font-normal", children: connectionError })] })] }), _jsxs("button", { type: "button", className: "flex gap-1.5 items-center justify-center bg-secondary-400 w-full text-primary-text p-4 border-none rounded-lg cursor-pointer text-sm font-medium leading-4", onClick: onRetry, children: [_jsx(RotateCw, { className: 'h-4 w-4' }), _jsx("span", { children: "Try again" })] })] })] }));
148
149
  };
@@ -161,7 +162,7 @@ const ProviderPicker = ({ providers, selectedProviderName, setSelectedProviderNa
161
162
  };
162
163
  const MultichainConnectorPicker = ({ selectedConnector, allConnectors, providers, connect }) => {
163
164
  const Icon = resolveWalletConnectorIcon({ connector: selectedConnector, iconUrl: selectedConnector.icon });
164
- return (_jsxs("div", { children: [_jsxs("div", { className: "flex flex-col gap-4 py-15", children: [_jsx("div", { className: "flex justify-center gap-1", children: _jsx(Icon, { className: "w-14 h-auto rounded-lg" }) }), _jsxs("p", { className: "text-base text-center text-primary-text", children: [_jsx("span", { children: selectedConnector.name }), " ", _jsx("span", { children: "supports multiple network types. Please select the one you'd like to use." })] })] }), _jsx("div", { className: "flex flex-col gap-2 w-full", children: allConnectors.filter(c => c?.name === selectedConnector.name)?.map((connector, index) => {
165
+ return (_jsxs("div", { children: [_jsxs("div", { className: "flex flex-col gap-4 py-10", children: [_jsx("div", { className: "flex justify-center gap-1", children: _jsx(Icon, { className: "w-14 h-auto rounded-lg" }) }), _jsxs("p", { className: "text-base text-center text-primary-text", children: [_jsx("span", { children: selectedConnector.name }), " ", _jsx("span", { children: "supports multiple network types. Please select the one you'd like to use." })] })] }), _jsx("div", { className: "flex flex-col gap-2 w-full", children: allConnectors.filter(c => c?.name === selectedConnector.name)?.map((connector, index) => {
165
166
  const provider = providers.find(p => p.name === connector?.providerName);
166
167
  return (_jsxs("button", { type: "button", onClick: async () => {
167
168
  await connect(connector, provider);
@@ -5,10 +5,14 @@ import { default as Content } from './Content';
5
5
  import { default as Footer } from './Footer';
6
6
  import { useRef } from "react";
7
7
  import AppSettings from "../../lib/AppSettings";
8
+ import clsx from "clsx";
8
9
  const Widget = ({ children, hideMenu, goBack, contextualMenu }) => {
9
10
  const wrapper = useRef(null);
10
11
  return _jsxs("div", { className: "relative p-px", children: [AppSettings.ThemeData?.enableWideVersion &&
11
- _jsx("div", { className: "invisible sm:visible absolute inset-0 rounded-[25px] bg-gradient-to-t from-secondary-800 to-secondary-300 pointer-events-none" }), _jsxs("div", { id: "widget", style: AppSettings.ThemeData?.cardBackgroundStyle, className: "sm:pb-4 rounded-3xl w-full sm:overflow-hidden relative bg-secondary-700 max-sm:has-openpicker:min-h-svh max-sm:min-h-[99.8svh] sm:has-openpicker:min-h-[79svh] has-openwithdrawalmodal:min-h-[650px] h-full flex flex-col", children: [AppSettings.ApiVersion === 'sandbox' &&
12
+ _jsx("div", { className: "invisible sm:visible absolute inset-0 rounded-[25px] bg-gradient-to-t from-secondary-800 to-secondary-300 pointer-events-none" }), _jsxs("div", { id: "widget", style: AppSettings.ThemeData?.cardBackgroundStyle, className: clsx("sm:pb-4 rounded-3xl w-full sm:overflow-hidden relative bg-secondary-700 h-full flex flex-col", {
13
+ "max-sm:has-openpicker:min-h-svh max-sm:min-h-[99.8svh] sm:has-openpicker:min-h-[79svh]": AppSettings.ThemeData?.enableWideVersion,
14
+ "sm:has-openpicker:min-h-[650px]": !AppSettings.ThemeData?.enableWideVersion,
15
+ }), children: [AppSettings.ApiVersion === 'testnet' &&
12
16
  _jsx("div", { className: "relative z-20", children: _jsx("div", { className: "absolute -top-1 right-[calc(50%-68px)] bg-[#D95E1B] py-0.5 px-10 rounded-b-md text-xs scale-75", children: "TESTNET" }) }), !hideMenu &&
13
17
  _jsx(HeaderWithMenu, { goBack: goBack, contextualMenu: contextualMenu }), _jsx("div", { className: "relative flex-col px-4 h-full min-h-0 flex flex-1", children: _jsx("div", { className: "flex flex-col flex-1 items-start h-full min-h-0 w-full gap-3", ref: wrapper, children: children }) }), _jsx("div", { id: "widget_root" })] })] });
14
18
  };
@@ -23,7 +23,7 @@ const LayerswapProviderComponent = ({ children, callbacks, config, walletProvide
23
23
  let { apiKey, version, settings: _settings, theme: themeData, imtblPassport, initialValues } = config || {};
24
24
  const [fetchedSettings, setFetchedSettings] = useState(null);
25
25
  themeData = { ...THEME_COLORS['default'], ...config?.theme };
26
- AppSettings.ApiVersion = version;
26
+ AppSettings.ApiVersion = version || AppSettings.ApiVersion;
27
27
  AppSettings.ImtblPassportConfig = imtblPassport;
28
28
  AppSettings.WalletConnectConfig = config?.walletConnect || AppSettings.WalletConnectConfig;
29
29
  AppSettings.ThemeData = themeData;
@@ -32,7 +32,7 @@ const LayerswapProviderComponent = ({ children, callbacks, config, walletProvide
32
32
  useEffect(() => {
33
33
  if (!_settings) {
34
34
  (async () => {
35
- const fetchedSettings = await getSettings();
35
+ const fetchedSettings = await getSettings(version || AppSettings.ApiVersion);
36
36
  if (!fetchedSettings)
37
37
  throw new Error('Failed to fetch settings');
38
38
  setFetchedSettings(fetchedSettings);
@@ -6,7 +6,7 @@ export { CampaignDetails } from '../components/Pages/Campaigns/Details';
6
6
  export { WidgetLoading } from '../components/WidgetLoading';
7
7
  export { LayerSwapSettings } from '../Models/LayerSwapSettings';
8
8
  export { THEME_COLORS } from '../Models/Theme';
9
- export { getSettings } from '../helpers/getSettings';
9
+ export { getSettings, useSettings } from '../helpers/getSettings';
10
10
  export { LayerswapProvider } from '../context/LayerswapProvider';
11
11
  export { useSettingsState } from '../context/settings';
12
12
  export { resolveWalletConnectorIcon, walletIconResolver } from '../lib/wallets/utils/resolveWalletIcon';
@@ -1,6 +1,8 @@
1
+ import { useEffect, useState } from "react";
1
2
  import LayerSwapApiClient from "../lib/apiClients/layerSwapApiClient";
2
- export async function getSettings() {
3
+ export async function getSettings(apiKey) {
3
4
  const apiClient = new LayerSwapApiClient();
5
+ LayerSwapApiClient.apiKey = apiKey;
4
6
  const { data: networkData } = await apiClient.GetLSNetworksAsync();
5
7
  const { data: sourceExchangesData } = await apiClient.GetSourceExchangesAsync();
6
8
  const { data: sourceRoutes } = await apiClient.GetRoutesAsync('sources');
@@ -15,3 +17,17 @@ export async function getSettings() {
15
17
  };
16
18
  return settings;
17
19
  }
20
+ export function useSettings(apiKey) {
21
+ const [loading, setLoading] = useState(true);
22
+ const [settings, setSettings] = useState(null);
23
+ useEffect(() => {
24
+ (async () => {
25
+ const settings = await getSettings(apiKey);
26
+ if (!settings)
27
+ throw new Error('Failed to fetch settings');
28
+ setSettings(settings);
29
+ setLoading(false);
30
+ })();
31
+ }, []);
32
+ return { settings, loading };
33
+ }