@lifi/widget 1.1.2 → 1.1.3

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
@@ -1,6 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ /* eslint-disable camelcase */
3
+ /* eslint-disable react/jsx-pascal-case */
4
+ import { Fragment } from 'react';
2
5
  import { QueryClientProvider } from 'react-query';
3
- import { MemoryRouter } from 'react-router-dom';
6
+ import { MemoryRouter, useInRouterContext } from 'react-router-dom';
4
7
  import { queryClient } from './config/queryClient';
5
8
  import { SwapFormProvider } from './providers/SwapFormProvider';
6
9
  import { ThemeProvider } from './providers/ThemeProvider';
@@ -8,5 +11,7 @@ import { WalletProvider } from './providers/WalletProvider';
8
11
  import { WidgetProvider } from './providers/WidgetProvider';
9
12
  const QueryProvider = QueryClientProvider;
10
13
  export const AppProvider = ({ children, config, }) => {
11
- return (_jsx(WidgetProvider, Object.assign({ config: config }, { children: _jsx(ThemeProvider, { children: _jsx(QueryProvider, Object.assign({ client: queryClient }, { children: _jsx(MemoryRouter, { children: _jsx(WalletProvider, { children: _jsx(SwapFormProvider, { children: children }) }) }) })) }) })));
14
+ const inRouterContext = useInRouterContext();
15
+ const Router = inRouterContext ? Fragment : MemoryRouter;
16
+ return (_jsx(WidgetProvider, Object.assign({ config: config }, { children: _jsx(ThemeProvider, { children: _jsx(QueryProvider, Object.assign({ client: queryClient }, { children: _jsx(Router, { children: _jsx(WalletProvider, { children: _jsx(SwapFormProvider, { children: children }) }) }) })) }) })));
12
17
  };
@@ -12,6 +12,6 @@ const stickyHeaderRoutes = [
12
12
  ];
13
13
  const HeaderContainer = ({ children }) => {
14
14
  const { pathname } = useLocation();
15
- return (_jsx(Container, Object.assign({ id: ElementId.Header, sticky: stickyHeaderRoutes.includes(pathname) }, { children: children })));
15
+ return (_jsx(Container, Object.assign({ id: ElementId.Header, sticky: stickyHeaderRoutes.some((route) => pathname.includes(route)) }, { children: children })));
16
16
  };
17
17
  export const Header = () => (_jsxs(HeaderContainer, { children: [_jsx(WalletHeader, {}), _jsx(NavigationHeader, {})] }));
@@ -3,7 +3,7 @@ import { ArrowBack as ArrowBackIcon, Settings as SettingsIcon, } from '@mui/icon
3
3
  import { Box, IconButton, Typography } from '@mui/material';
4
4
  import { useTranslation } from 'react-i18next';
5
5
  import { Route, Routes, useLocation, useNavigate } from 'react-router-dom';
6
- import { routes } from '../../utils/routes';
6
+ import { routes, routesValues } from '../../utils/routes';
7
7
  import { SwapRoutesUpdateProgress } from '../SwapRoutes/SwapRoutesUpdateProgress';
8
8
  import { HeaderAppBar } from './Header.style';
9
9
  const backButtonRoutes = [
@@ -17,6 +17,8 @@ const backButtonRoutes = [
17
17
  export const NavigationHeader = () => {
18
18
  const { t } = useTranslation();
19
19
  const { pathname } = useLocation();
20
+ const path = pathname.substring(pathname.lastIndexOf('/') + 1);
21
+ const hasPath = routesValues.includes(path);
20
22
  const navigate = useNavigate();
21
23
  const handleSettings = () => {
22
24
  navigate(routes.settings);
@@ -25,7 +27,7 @@ export const NavigationHeader = () => {
25
27
  navigate(-1);
26
28
  };
27
29
  const handleHeaderTitle = () => {
28
- switch (pathname) {
30
+ switch (path) {
29
31
  case routes.selectWallet:
30
32
  return t(`header.selectWallet`);
31
33
  case routes.settings:
@@ -42,5 +44,5 @@ export const NavigationHeader = () => {
42
44
  return t(`header.swap`);
43
45
  }
44
46
  };
45
- return (_jsxs(HeaderAppBar, Object.assign({ elevation: 0 }, { children: [backButtonRoutes.includes(pathname) ? (_jsx(IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "start", onClick: handleBack }, { children: _jsx(ArrowBackIcon, {}) }))) : null, _jsx(Typography, Object.assign({ fontSize: pathname === '/' ? 32 : 24, align: pathname === '/' ? 'left' : 'center', fontWeight: "700", flex: 1, noWrap: true }, { children: handleHeaderTitle() })), _jsxs(Routes, { children: [_jsx(Route, { path: routes.swapRoutes, element: _jsx(SwapRoutesUpdateProgress, { size: "medium", edge: "end", sx: { marginRight: -1 } }) }), _jsx(Route, { path: routes.home, element: _jsx(IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "end", onClick: handleSettings }, { children: _jsx(SettingsIcon, {}) })) }), _jsx(Route, { path: "/:empty", element: _jsx(Box, { width: 36, height: 48 }) })] })] })));
47
+ return (_jsxs(HeaderAppBar, Object.assign({ elevation: 0 }, { children: [backButtonRoutes.includes(path) ? (_jsx(IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "start", onClick: handleBack }, { children: _jsx(ArrowBackIcon, {}) }))) : null, _jsx(Typography, Object.assign({ fontSize: hasPath ? 24 : 32, align: hasPath ? 'center' : 'left', fontWeight: "700", flex: 1, noWrap: true }, { children: handleHeaderTitle() })), _jsxs(Routes, { children: [_jsx(Route, { path: routes.swapRoutes, element: _jsx(SwapRoutesUpdateProgress, { size: "medium", edge: "end", sx: { marginRight: -1 } }) }), _jsx(Route, { path: routes.home, element: _jsx(IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "end", onClick: handleSettings }, { children: _jsx(SettingsIcon, {}) })) }), _jsx(Route, { path: "/:empty", element: _jsx(Box, { width: 28, height: 48 }) })] })] })));
46
48
  };
@@ -24,5 +24,5 @@ const ConnectButton = () => {
24
24
  const connect = () => {
25
25
  navigate(routes.selectWallet);
26
26
  };
27
- return (_jsx(IconButton, Object.assign({ size: "medium", "aria-label": "disconnect", edge: "end", onClick: pathname !== routes.selectWallet ? connect : undefined }, { children: _jsx(AccountBalanceWalletIcon, {}) })));
27
+ return (_jsx(IconButton, Object.assign({ size: "medium", "aria-label": "disconnect", edge: "end", onClick: !pathname.includes(routes.selectWallet) ? connect : undefined }, { children: _jsx(AccountBalanceWalletIcon, {}) })));
28
28
  };
@@ -1,15 +1,23 @@
1
- import { useState } from 'react';
1
+ import { useLayoutEffect, useState } from 'react';
2
2
  import { ElementId } from '../utils/elements';
3
+ const getContentHeight = () => {
4
+ const headerElement = document.getElementById(ElementId.Header);
5
+ const containerElement = document.getElementById(ElementId.ScrollableContainer);
6
+ if (!containerElement || !headerElement) {
7
+ console.warn(`Can't find ${ElementId.ScrollableContainer} or ${ElementId.Header} id.`);
8
+ return 0;
9
+ }
10
+ const { height: containerHeight } = containerElement.getBoundingClientRect();
11
+ const { height: headerHeight } = headerElement.getBoundingClientRect();
12
+ return containerHeight - headerHeight;
13
+ };
3
14
  export const useContentHeight = () => {
4
- const [contentHeight] = useState(() => {
5
- const headerElement = document.getElementById(ElementId.Header);
6
- const containerElement = document.getElementById(ElementId.ScrollableContainer);
7
- if (!containerElement || !headerElement) {
8
- throw Error(`Can't find ${ElementId.ScrollableContainer} or ${ElementId.Header} id.`);
15
+ const [contentHeight, setContentHeight] = useState(getContentHeight);
16
+ useLayoutEffect(() => {
17
+ if (!contentHeight) {
18
+ setContentHeight(getContentHeight());
9
19
  }
10
- const { height: containerHeight } = containerElement.getBoundingClientRect();
11
- const { height: headerHeight } = headerElement.getBoundingClientRect();
12
- return containerHeight - headerHeight;
13
- });
20
+ // eslint-disable-next-line react-hooks/exhaustive-deps
21
+ }, []);
14
22
  return contentHeight;
15
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/widget",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
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
  "sideEffects": false,
6
6
  "main": "./index.js",
@@ -21,5 +21,5 @@ export const ChainSelect = ({ formType }) => {
21
21
  setValue(SwapFormKeyHelper.getTokenKey(formType), '');
22
22
  setValue(SwapFormKeyHelper.getAmountKey(formType), '');
23
23
  };
24
- return !isLoading ? (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`swap.selectChain`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ labelId: "label", MenuProps: { elevation: 2 }, defaultValue: formType === 'from' ? fromChain : toChain, value: chainId, onChange: handleChain, IconComponent: KeyboardArrowDownIcon }, { children: chains === null || chains === void 0 ? void 0 : chains.map((chain) => (_jsxs(MenuItem, Object.assign({ value: chain.id }, { children: [_jsx(ListItemAvatar, { children: _jsx(Avatar, Object.assign({ src: chain.logoURI, alt: chain.key }, { children: chain.name[0] })) }), chain.name] }), chain.key))) })) }))] })) : (_jsx(Skeleton, { variant: "rectangular", width: "100%", height: 89, sx: { borderRadius: 1 } }));
24
+ return !isLoading ? (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`swap.selectChain`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ labelId: "label", MenuProps: { elevation: 2 }, defaultValue: formType === 'from' ? fromChain : toChain, value: chainId, onChange: handleChain, IconComponent: KeyboardArrowDownIcon }, { children: chains === null || chains === void 0 ? void 0 : chains.map((chain) => (_jsxs(MenuItem, Object.assign({ value: chain.id }, { children: [_jsx(ListItemAvatar, { children: _jsx(Avatar, Object.assign({ src: chain.logoURI, alt: chain.key }, { children: chain.name[0] })) }), chain.name] }), chain.key))) })) }))] })) : (_jsx(Skeleton, { variant: "rectangular", width: "100%", height: 98, sx: { borderRadius: 1 } }));
25
25
  };
package/utils/routes.d.ts CHANGED
@@ -7,4 +7,5 @@ export declare const routes: {
7
7
  swapRoutes: string;
8
8
  swap: string;
9
9
  };
10
+ export declare const routesValues: string[];
10
11
  export declare type RouteType = keyof typeof routes;
package/utils/routes.js CHANGED
@@ -1,9 +1,10 @@
1
1
  export const routes = {
2
2
  home: '/',
3
- selectWallet: '/select-wallet',
4
- settings: '/settings',
5
- fromToken: '/select-from-token',
6
- toToken: '/select-to-token',
7
- swapRoutes: '/swap-routes',
8
- swap: '/swap',
3
+ selectWallet: 'select-wallet',
4
+ settings: 'settings',
5
+ fromToken: 'select-from-token',
6
+ toToken: 'select-to-token',
7
+ swapRoutes: 'swap-routes',
8
+ swap: 'swap',
9
9
  };
10
+ export const routesValues = Object.values(routes);