@lifi/widget 2.9.2 → 2.9.4

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.
package/AppProvider.js CHANGED
@@ -6,7 +6,7 @@ import { queryClient } from './config/queryClient';
6
6
  import { FormProvider, I18nProvider, SDKProvider, ThemeProvider, URLSearchParamsBuilder, WalletProvider, WidgetProvider, useWidgetConfig, } from './providers';
7
7
  import { StoreProvider } from './stores';
8
8
  export const AppProvider = ({ children, config, }) => {
9
- return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(StoreProvider, { config: config, children: _jsx(WidgetProvider, { config: config, children: _jsx(SDKProvider, { children: _jsx(ThemeProvider, { children: _jsx(I18nProvider, { children: _jsx(WalletProvider, { children: _jsx(FormProvider, { children: _jsx(AppRouter, { children: children }) }) }) }) }) }) }) }) }));
9
+ return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(WidgetProvider, { config: config, children: _jsx(SDKProvider, { children: _jsx(ThemeProvider, { children: _jsx(I18nProvider, { children: _jsx(WalletProvider, { children: _jsx(FormProvider, { children: _jsx(StoreProvider, { config: config, children: _jsx(AppRouter, { children: children }) }) }) }) }) }) }) }) }));
10
10
  };
11
11
  export const AppRouter = ({ children }) => {
12
12
  const { buildUrl } = useWidgetConfig();
@@ -9,7 +9,7 @@ const queryClient_1 = require("./config/queryClient");
9
9
  const providers_1 = require("./providers");
10
10
  const stores_1 = require("./stores");
11
11
  const AppProvider = ({ children, config, }) => {
12
- return ((0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient_1.queryClient, children: (0, jsx_runtime_1.jsx)(stores_1.StoreProvider, { config: config, children: (0, jsx_runtime_1.jsx)(providers_1.WidgetProvider, { config: config, children: (0, jsx_runtime_1.jsx)(providers_1.SDKProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.ThemeProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.I18nProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.WalletProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.FormProvider, { children: (0, jsx_runtime_1.jsx)(exports.AppRouter, { children: children }) }) }) }) }) }) }) }) }));
12
+ return ((0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient_1.queryClient, children: (0, jsx_runtime_1.jsx)(providers_1.WidgetProvider, { config: config, children: (0, jsx_runtime_1.jsx)(providers_1.SDKProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.ThemeProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.I18nProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.WalletProvider, { children: (0, jsx_runtime_1.jsx)(providers_1.FormProvider, { children: (0, jsx_runtime_1.jsx)(stores_1.StoreProvider, { config: config, children: (0, jsx_runtime_1.jsx)(exports.AppRouter, { children: children }) }) }) }) }) }) }) }) }));
13
13
  };
14
14
  exports.AppProvider = AppProvider;
15
15
  const AppRouter = ({ children }) => {
@@ -2,7 +2,7 @@
2
2
  export declare const CardLabel: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
3
3
  ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
4
4
  }, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
5
- type?: "active" | "insurance" | "insurance-icon" | undefined;
5
+ type?: "insurance" | "active" | "insurance-icon" | undefined;
6
6
  }, {}, {}>;
7
7
  export declare const CardLabelTypography: import("@emotion/styled").StyledComponent<import("@mui/material").TypographyOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
8
8
  ref?: ((instance: HTMLSpanElement | null) => void) | import("react").RefObject<HTMLSpanElement> | null | undefined;
@@ -5,6 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_router_dom_1 = require("react-router-dom");
6
6
  const hooks_1 = require("../../hooks");
7
7
  const providers_1 = require("../../providers");
8
+ const types_1 = require("../../types");
8
9
  const utils_1 = require("../../utils");
9
10
  const Header_style_1 = require("./Header.style");
10
11
  const NavigationHeader_1 = require("./NavigationHeader");
@@ -16,7 +17,9 @@ const HeaderContainer = ({ children }) => {
16
17
  };
17
18
  exports.HeaderContainer = HeaderContainer;
18
19
  const Header = () => {
19
- const { walletManagement, subvariant } = (0, providers_1.useWidgetConfig)();
20
- return ((0, jsx_runtime_1.jsxs)(exports.HeaderContainer, { children: [!walletManagement && subvariant !== 'split' ? (0, jsx_runtime_1.jsx)(WalletHeader_1.WalletHeader, {}) : null, (0, jsx_runtime_1.jsx)(NavigationHeader_1.NavigationHeader, {})] }));
20
+ const { walletManagement, subvariant, hiddenUI } = (0, providers_1.useWidgetConfig)();
21
+ return ((0, jsx_runtime_1.jsxs)(exports.HeaderContainer, { children: [!walletManagement &&
22
+ subvariant !== 'split' &&
23
+ !hiddenUI?.includes(types_1.HiddenUI.WalletMenu) ? ((0, jsx_runtime_1.jsx)(WalletHeader_1.WalletHeader, {})) : null, (0, jsx_runtime_1.jsx)(NavigationHeader_1.NavigationHeader, {})] }));
21
24
  };
22
25
  exports.Header = Header;
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "2.9.2";
2
+ export declare const version = "2.9.4";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = exports.name = void 0;
4
4
  exports.name = '@lifi/widget';
5
- exports.version = '2.9.2';
5
+ exports.version = '2.9.4';
@@ -3,38 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useChains = void 0;
4
4
  const react_query_1 = require("@tanstack/react-query");
5
5
  const react_1 = require("react");
6
- const react_hook_form_1 = require("react-hook-form");
7
6
  const providers_1 = require("../providers");
8
- const stores_1 = require("../stores");
9
7
  const useChains = () => {
10
- const { chains, keyPrefix } = (0, providers_1.useWidgetConfig)();
8
+ const { chains } = (0, providers_1.useWidgetConfig)();
11
9
  const lifi = (0, providers_1.useLiFi)();
12
- const { getValues, setValue } = (0, react_hook_form_1.useFormContext)();
13
- const initializeChains = (0, stores_1.useChainOrderStore)((state) => state.initializeChains);
14
10
  const { data: availableChains, isLoading: isLoadingAvailableChains } = (0, react_query_1.useQuery)(['chains'], async () => lifi.getChains(), {
15
11
  refetchInterval: 300000,
16
12
  staleTime: 300000,
17
13
  });
18
- const { data: filteredChains, isLoading: isLoadingFilteredChains } = (0, react_query_1.useQuery)(['filtered-chains', availableChains?.length, keyPrefix], async () => {
19
- if (!availableChains) {
20
- return;
21
- }
22
- const filteredChains = availableChains.filter((chain) => (0, providers_1.isItemAllowed)(chain.id, chains));
23
- const chainOrder = initializeChains(filteredChains.map((chain) => chain.id));
24
- const [fromChainValue, toChainValue] = getValues([
25
- providers_1.FormKey.FromChain,
26
- providers_1.FormKey.ToChain,
27
- ]);
28
- if (!fromChainValue) {
29
- setValue(providers_1.FormKey.FromChain, chainOrder[0]);
30
- }
31
- if (!toChainValue) {
32
- setValue(providers_1.FormKey.ToChain, chainOrder[0]);
33
- }
14
+ const filteredChains = (0, react_1.useMemo)(() => {
15
+ const filteredChains = availableChains?.filter((chain) => (0, providers_1.isItemAllowed)(chain.id, chains));
34
16
  return filteredChains;
35
- }, {
36
- enabled: Boolean(availableChains),
37
- });
17
+ }, [availableChains, chains]);
38
18
  const getChainById = (0, react_1.useCallback)((chainId) => {
39
19
  const chain = availableChains?.find((chain) => chain.id === chainId);
40
20
  // if (!chain) {
@@ -45,7 +25,7 @@ const useChains = () => {
45
25
  return {
46
26
  chains: filteredChains,
47
27
  getChainById,
48
- isLoading: isLoadingAvailableChains || isLoadingFilteredChains,
28
+ isLoading: isLoadingAvailableChains,
49
29
  };
50
30
  };
51
31
  exports.useChains = useChains;
@@ -1,3 +1,3 @@
1
1
  import type { FC } from 'react';
2
- import type { FormTypeProps } from '../../providers';
2
+ import { type FormTypeProps } from '../../providers';
3
3
  export declare const SelectTokenPage: FC<FormTypeProps>;
@@ -16,8 +16,11 @@ const FormUpdater = ({ defaultValues }) => {
16
16
  const previousDefaultValues = (0, react_1.useRef)(defaultValues);
17
17
  // Set wallet chain as default if no chains are provided by config and if they were not changed during widget usage
18
18
  (0, react_1.useEffect)(() => {
19
- const chainAllowed = account.chainId && (0, WidgetProvider_1.isItemAllowed)(account.chainId, chains);
20
- if (!account.isActive || !account.chainId || !chainAllowed) {
19
+ if (!account.isActive || !account.chainId) {
20
+ return;
21
+ }
22
+ const chainAllowed = (0, WidgetProvider_1.isItemAllowed)(account.chainId, chains);
23
+ if (!chainAllowed) {
21
24
  return;
22
25
  }
23
26
  const { isTouched: isFromChainTouched } = getFieldState(_1.FormKey.FromChain);
@@ -70,6 +70,7 @@ const WidgetProvider = ({ children, config: { fromChain, fromToken, toChain, toT
70
70
  fromChain,
71
71
  fromToken,
72
72
  integrator,
73
+ toAddress,
73
74
  toChain,
74
75
  toToken,
75
76
  ]);
@@ -3,13 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useChainOrderStoreContext = exports.useChainOrderStore = exports.ChainOrderStoreProvider = exports.ChainOrderStoreContext = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
+ const react_hook_form_1 = require("react-hook-form");
7
+ const hooks_1 = require("../../hooks");
8
+ const providers_1 = require("../../providers");
6
9
  const createChainOrderStore_1 = require("./createChainOrderStore");
7
10
  exports.ChainOrderStoreContext = (0, react_1.createContext)(null);
8
11
  function ChainOrderStoreProvider({ children, ...props }) {
9
12
  const storeRef = (0, react_1.useRef)();
13
+ const { chains: filteredChains } = (0, hooks_1.useChains)();
14
+ const { setValue, getValues } = (0, react_hook_form_1.useFormContext)();
10
15
  if (!storeRef.current) {
11
16
  storeRef.current = (0, createChainOrderStore_1.createChainOrderStore)(props);
12
17
  }
18
+ (0, react_1.useEffect)(() => {
19
+ if (filteredChains) {
20
+ const chainOrder = storeRef.current
21
+ ?.getState()
22
+ .initializeChains(filteredChains.map((chain) => chain.id));
23
+ if (chainOrder) {
24
+ const [fromChainValue, toChainValue] = getValues([
25
+ providers_1.FormKey.FromChain,
26
+ providers_1.FormKey.ToChain,
27
+ ]);
28
+ if (!fromChainValue) {
29
+ setValue(providers_1.FormKey.FromChain, chainOrder[0]);
30
+ }
31
+ if (!toChainValue) {
32
+ setValue(providers_1.FormKey.ToChain, chainOrder[0]);
33
+ }
34
+ }
35
+ }
36
+ }, [filteredChains, getValues, setValue]);
13
37
  return ((0, jsx_runtime_1.jsx)(exports.ChainOrderStoreContext.Provider, { value: storeRef.current, children: children }));
14
38
  }
15
39
  exports.ChainOrderStoreProvider = ChainOrderStoreProvider;
@@ -2,7 +2,7 @@
2
2
  export declare const CardLabel: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
3
3
  ref?: import("react").RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined;
4
4
  }, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
5
- type?: "active" | "insurance" | "insurance-icon" | undefined;
5
+ type?: "insurance" | "active" | "insurance-icon" | undefined;
6
6
  }, {}, {}>;
7
7
  export declare const CardLabelTypography: import("@emotion/styled").StyledComponent<import("@mui/material").TypographyOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
8
8
  ref?: ((instance: HTMLSpanElement | null) => void) | import("react").RefObject<HTMLSpanElement> | null | undefined;
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useLocation } from 'react-router-dom';
3
3
  import { useDefaultElementId } from '../../hooks';
4
4
  import { useWidgetConfig } from '../../providers';
5
+ import { HiddenUI } from '../../types';
5
6
  import { ElementId, createElementId, stickyHeaderRoutes } from '../../utils';
6
7
  import { Container } from './Header.style';
7
8
  import { NavigationHeader } from './NavigationHeader';
@@ -12,6 +13,8 @@ export const HeaderContainer = ({ children }) => {
12
13
  return (_jsx(Container, { id: createElementId(ElementId.Header, elementId), sticky: stickyHeaderRoutes.some((route) => pathname.includes(route)), children: children }));
13
14
  };
14
15
  export const Header = () => {
15
- const { walletManagement, subvariant } = useWidgetConfig();
16
- return (_jsxs(HeaderContainer, { children: [!walletManagement && subvariant !== 'split' ? _jsx(WalletHeader, {}) : null, _jsx(NavigationHeader, {})] }));
16
+ const { walletManagement, subvariant, hiddenUI } = useWidgetConfig();
17
+ return (_jsxs(HeaderContainer, { children: [!walletManagement &&
18
+ subvariant !== 'split' &&
19
+ !hiddenUI?.includes(HiddenUI.WalletMenu) ? (_jsx(WalletHeader, {})) : null, _jsx(NavigationHeader, {})] }));
17
20
  };
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "2.9.2";
2
+ export declare const version = "2.9.4";
package/config/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/widget';
2
- export const version = '2.9.2';
2
+ export const version = '2.9.4';
@@ -1,37 +1,17 @@
1
1
  import { useQuery } from '@tanstack/react-query';
2
- import { useCallback } from 'react';
3
- import { useFormContext } from 'react-hook-form';
4
- import { FormKey, isItemAllowed, useLiFi, useWidgetConfig } from '../providers';
5
- import { useChainOrderStore } from '../stores';
2
+ import { useCallback, useMemo } from 'react';
3
+ import { isItemAllowed, useLiFi, useWidgetConfig } from '../providers';
6
4
  export const useChains = () => {
7
- const { chains, keyPrefix } = useWidgetConfig();
5
+ const { chains } = useWidgetConfig();
8
6
  const lifi = useLiFi();
9
- const { getValues, setValue } = useFormContext();
10
- const initializeChains = useChainOrderStore((state) => state.initializeChains);
11
7
  const { data: availableChains, isLoading: isLoadingAvailableChains } = useQuery(['chains'], async () => lifi.getChains(), {
12
8
  refetchInterval: 300000,
13
9
  staleTime: 300000,
14
10
  });
15
- const { data: filteredChains, isLoading: isLoadingFilteredChains } = useQuery(['filtered-chains', availableChains?.length, keyPrefix], async () => {
16
- if (!availableChains) {
17
- return;
18
- }
19
- const filteredChains = availableChains.filter((chain) => isItemAllowed(chain.id, chains));
20
- const chainOrder = initializeChains(filteredChains.map((chain) => chain.id));
21
- const [fromChainValue, toChainValue] = getValues([
22
- FormKey.FromChain,
23
- FormKey.ToChain,
24
- ]);
25
- if (!fromChainValue) {
26
- setValue(FormKey.FromChain, chainOrder[0]);
27
- }
28
- if (!toChainValue) {
29
- setValue(FormKey.ToChain, chainOrder[0]);
30
- }
11
+ const filteredChains = useMemo(() => {
12
+ const filteredChains = availableChains?.filter((chain) => isItemAllowed(chain.id, chains));
31
13
  return filteredChains;
32
- }, {
33
- enabled: Boolean(availableChains),
34
- });
14
+ }, [availableChains, chains]);
35
15
  const getChainById = useCallback((chainId) => {
36
16
  const chain = availableChains?.find((chain) => chain.id === chainId);
37
17
  // if (!chain) {
@@ -42,6 +22,6 @@ export const useChains = () => {
42
22
  return {
43
23
  chains: filteredChains,
44
24
  getChainById,
45
- isLoading: isLoadingAvailableChains || isLoadingFilteredChains,
25
+ isLoading: isLoadingAvailableChains,
46
26
  };
47
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/widget",
3
- "version": "2.9.2",
3
+ "version": "2.9.4",
4
4
  "description": "LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./index.js",
@@ -1,3 +1,3 @@
1
1
  import type { FC } from 'react';
2
- import type { FormTypeProps } from '../../providers';
2
+ import { type FormTypeProps } from '../../providers';
3
3
  export declare const SelectTokenPage: FC<FormTypeProps>;
@@ -13,8 +13,11 @@ export const FormUpdater = ({ defaultValues }) => {
13
13
  const previousDefaultValues = useRef(defaultValues);
14
14
  // Set wallet chain as default if no chains are provided by config and if they were not changed during widget usage
15
15
  useEffect(() => {
16
- const chainAllowed = account.chainId && isItemAllowed(account.chainId, chains);
17
- if (!account.isActive || !account.chainId || !chainAllowed) {
16
+ if (!account.isActive || !account.chainId) {
17
+ return;
18
+ }
19
+ const chainAllowed = isItemAllowed(account.chainId, chains);
20
+ if (!chainAllowed) {
18
21
  return;
19
22
  }
20
23
  const { isTouched: isFromChainTouched } = getFieldState(FormKey.FromChain);
@@ -66,6 +66,7 @@ export const WidgetProvider = ({ children, config: { fromChain, fromToken, toCha
66
66
  fromChain,
67
67
  fromToken,
68
68
  integrator,
69
+ toAddress,
69
70
  toChain,
70
71
  toToken,
71
72
  ]);
@@ -1,12 +1,36 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useContext, useRef } from 'react';
2
+ import { createContext, useContext, useEffect, useRef } from 'react';
3
+ import { useFormContext } from 'react-hook-form';
4
+ import { useChains } from '../../hooks';
5
+ import { FormKey } from '../../providers';
3
6
  import { createChainOrderStore } from './createChainOrderStore';
4
7
  export const ChainOrderStoreContext = createContext(null);
5
8
  export function ChainOrderStoreProvider({ children, ...props }) {
6
9
  const storeRef = useRef();
10
+ const { chains: filteredChains } = useChains();
11
+ const { setValue, getValues } = useFormContext();
7
12
  if (!storeRef.current) {
8
13
  storeRef.current = createChainOrderStore(props);
9
14
  }
15
+ useEffect(() => {
16
+ if (filteredChains) {
17
+ const chainOrder = storeRef.current
18
+ ?.getState()
19
+ .initializeChains(filteredChains.map((chain) => chain.id));
20
+ if (chainOrder) {
21
+ const [fromChainValue, toChainValue] = getValues([
22
+ FormKey.FromChain,
23
+ FormKey.ToChain,
24
+ ]);
25
+ if (!fromChainValue) {
26
+ setValue(FormKey.FromChain, chainOrder[0]);
27
+ }
28
+ if (!toChainValue) {
29
+ setValue(FormKey.ToChain, chainOrder[0]);
30
+ }
31
+ }
32
+ }
33
+ }, [filteredChains, getValues, setValue]);
10
34
  return (_jsx(ChainOrderStoreContext.Provider, { value: storeRef.current, children: children }));
11
35
  }
12
36
  export function useChainOrderStore(selector, equalityFn) {