@lifi/widget 2.9.5 → 2.10.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.
package/App.js CHANGED
@@ -11,9 +11,9 @@ import { RoutesExpanded } from './components/Routes';
11
11
  import { useExpandableVariant } from './hooks';
12
12
  import { useWidgetConfig } from './providers';
13
13
  import { ElementId, createElementId } from './utils';
14
- export const App = forwardRef(({ elementRef, open, integrator, ...other }, ref) => {
14
+ export const App = forwardRef(({ elementRef, open, onClose, integrator, ...other }, ref) => {
15
15
  const config = useMemo(() => ({ integrator, ...other, ...other.config }), [integrator, other]);
16
- return config?.variant !== 'drawer' ? (_jsx(AppProvider, { config: config, children: _jsx(AppDefault, {}) })) : (_jsx(AppDrawer, { ref: ref, elementRef: elementRef, integrator: integrator, config: config, open: open }));
16
+ return config?.variant !== 'drawer' ? (_jsx(AppProvider, { config: config, children: _jsx(AppDefault, {}) })) : (_jsx(AppDrawer, { ref: ref, elementRef: elementRef, integrator: integrator, config: config, open: open, onClose: onClose }));
17
17
  });
18
18
  export const AppDefault = () => {
19
19
  const { elementId } = useWidgetConfig();
package/AppDrawer.js CHANGED
@@ -1,26 +1,35 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import CloseIcon from '@mui/icons-material/CloseRounded';
3
2
  import KeyboardArrowLeftIcon from '@mui/icons-material/KeyboardArrowLeft';
4
3
  import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
5
4
  import { Drawer } from '@mui/material';
6
5
  import { forwardRef, useCallback, useImperativeHandle, useMemo, useRef, useState, } from 'react';
7
6
  import { useTranslation } from 'react-i18next';
8
7
  import { AppDefault } from './App';
9
- import { CloseButtonLayout, DrawerButton, DrawerButtonTypography, } from './AppDrawer.style';
8
+ import { DrawerButton, DrawerButtonTypography } from './AppDrawer.style';
9
+ import { DrawerContext } from './AppDrawerContext';
10
10
  import { AppProvider } from './AppProvider';
11
11
  import { HiddenUI } from './types';
12
- export const AppDrawer = forwardRef(({ elementRef, open, integrator, config }, ref) => {
13
- const openRef = useRef(open);
12
+ export const AppDrawer = forwardRef(({ elementRef, open, onClose, integrator, config }, ref) => {
13
+ const openRef = useRef(Boolean(open));
14
14
  const [drawerOpen, setDrawerOpen] = useState(Boolean(open));
15
15
  const toggleDrawer = useCallback(() => {
16
- setDrawerOpen((open) => !open);
17
- }, []);
16
+ setDrawerOpen((open) => {
17
+ openRef.current = !open;
18
+ return openRef.current;
19
+ });
20
+ if (!openRef.current) {
21
+ onClose?.();
22
+ }
23
+ }, [onClose]);
18
24
  const openDrawer = useCallback(() => {
19
25
  setDrawerOpen(true);
26
+ openRef.current = true;
20
27
  }, []);
21
28
  const closeDrawer = useCallback(() => {
22
29
  setDrawerOpen(false);
23
- }, []);
30
+ openRef.current = false;
31
+ onClose?.();
32
+ }, [onClose]);
24
33
  useImperativeHandle(ref, () => ({
25
34
  isOpen: () => openRef.current,
26
35
  toggleDrawer,
@@ -35,18 +44,21 @@ export const AppDrawer = forwardRef(({ elementRef, open, integrator, config }, r
35
44
  height: '100%',
36
45
  },
37
46
  }), [config, integrator]);
38
- return (_jsxs(AppProvider, { config: widgetConfig, children: [!widgetConfig.hiddenUI?.includes(HiddenUI.DrawerButton) ? (_jsxs(DrawerButton, { variant: "contained", onClick: toggleDrawer, open: drawerOpen, drawerProps: config?.containerStyle, children: [drawerOpen ? (_jsx(KeyboardArrowRightIcon, {})) : (_jsx(KeyboardArrowLeftIcon, {})), _jsx(DrawerButtonText, { open: drawerOpen, subvariant: config?.subvariant })] })) : null, _jsxs(Drawer, { ref: elementRef, anchor: "right", open: drawerOpen, onClose: closeDrawer, BackdropProps: {
39
- sx: {
40
- backgroundColor: 'rgb(0 0 0 / 48%)',
41
- backdropFilter: 'blur(3px)',
42
- },
43
- }, PaperProps: {
44
- sx: {
45
- width: config?.containerStyle?.width ?? '100%',
46
- minWidth: config?.containerStyle?.minWidth ?? 360,
47
- maxWidth: config?.containerStyle?.maxWidth ?? 392,
48
- },
49
- }, keepMounted: true, children: [_jsx(CloseButtonLayout, { onClick: closeDrawer, edge: "end", children: _jsx(CloseIcon, {}) }), _jsx(AppDefault, {})] })] }));
47
+ const drawerContext = useMemo(() => ({
48
+ closeDrawer,
49
+ }), [closeDrawer]);
50
+ return (_jsx(DrawerContext.Provider, { value: drawerContext, children: _jsxs(AppProvider, { config: widgetConfig, children: [!widgetConfig.hiddenUI?.includes(HiddenUI.DrawerButton) ? (_jsxs(DrawerButton, { variant: "contained", onClick: toggleDrawer, open: drawerOpen, drawerProps: config?.containerStyle, children: [drawerOpen ? (_jsx(KeyboardArrowRightIcon, {})) : (_jsx(KeyboardArrowLeftIcon, {})), _jsx(DrawerButtonText, { open: drawerOpen, subvariant: config?.subvariant })] })) : null, _jsx(Drawer, { ref: elementRef, anchor: "right", open: drawerOpen, onClose: closeDrawer, BackdropProps: {
51
+ sx: {
52
+ backgroundColor: 'rgb(0 0 0 / 48%)',
53
+ backdropFilter: 'blur(3px)',
54
+ },
55
+ }, PaperProps: {
56
+ sx: {
57
+ width: config?.containerStyle?.width ?? '100%',
58
+ minWidth: config?.containerStyle?.minWidth ?? 360,
59
+ maxWidth: config?.containerStyle?.maxWidth ?? 392,
60
+ },
61
+ }, keepMounted: true, children: _jsx(AppDefault, {}) })] }) }));
50
62
  });
51
63
  export const DrawerButtonText = ({ open, subvariant, }) => {
52
64
  const { t } = useTranslation();
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export interface WidgetDrawerContext {
3
+ closeDrawer?(): void;
4
+ }
5
+ export declare const DrawerContext: import("react").Context<WidgetDrawerContext>;
6
+ export declare const useDrawer: () => WidgetDrawerContext;
@@ -0,0 +1,3 @@
1
+ import { createContext, useContext } from 'react';
2
+ export const DrawerContext = createContext({});
3
+ export const useDrawer = () => useContext(DrawerContext);
package/cjs/App.js CHANGED
@@ -14,9 +14,9 @@ const Routes_1 = require("./components/Routes");
14
14
  const hooks_1 = require("./hooks");
15
15
  const providers_1 = require("./providers");
16
16
  const utils_1 = require("./utils");
17
- exports.App = (0, react_1.forwardRef)(({ elementRef, open, integrator, ...other }, ref) => {
17
+ exports.App = (0, react_1.forwardRef)(({ elementRef, open, onClose, integrator, ...other }, ref) => {
18
18
  const config = (0, react_1.useMemo)(() => ({ integrator, ...other, ...other.config }), [integrator, other]);
19
- return config?.variant !== 'drawer' ? ((0, jsx_runtime_1.jsx)(AppProvider_1.AppProvider, { config: config, children: (0, jsx_runtime_1.jsx)(exports.AppDefault, {}) })) : ((0, jsx_runtime_1.jsx)(AppDrawer_1.AppDrawer, { ref: ref, elementRef: elementRef, integrator: integrator, config: config, open: open }));
19
+ return config?.variant !== 'drawer' ? ((0, jsx_runtime_1.jsx)(AppProvider_1.AppProvider, { config: config, children: (0, jsx_runtime_1.jsx)(exports.AppDefault, {}) })) : ((0, jsx_runtime_1.jsx)(AppDrawer_1.AppDrawer, { ref: ref, elementRef: elementRef, integrator: integrator, config: config, open: open, onClose: onClose }));
20
20
  });
21
21
  const AppDefault = () => {
22
22
  const { elementId } = (0, providers_1.useWidgetConfig)();
package/cjs/AppDrawer.js CHANGED
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DrawerButtonText = exports.AppDrawer = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- const CloseRounded_1 = require("@mui/icons-material/CloseRounded");
6
5
  const KeyboardArrowLeft_1 = require("@mui/icons-material/KeyboardArrowLeft");
7
6
  const KeyboardArrowRight_1 = require("@mui/icons-material/KeyboardArrowRight");
8
7
  const material_1 = require("@mui/material");
@@ -10,20 +9,30 @@ const react_1 = require("react");
10
9
  const react_i18next_1 = require("react-i18next");
11
10
  const App_1 = require("./App");
12
11
  const AppDrawer_style_1 = require("./AppDrawer.style");
12
+ const AppDrawerContext_1 = require("./AppDrawerContext");
13
13
  const AppProvider_1 = require("./AppProvider");
14
14
  const types_1 = require("./types");
15
- exports.AppDrawer = (0, react_1.forwardRef)(({ elementRef, open, integrator, config }, ref) => {
16
- const openRef = (0, react_1.useRef)(open);
15
+ exports.AppDrawer = (0, react_1.forwardRef)(({ elementRef, open, onClose, integrator, config }, ref) => {
16
+ const openRef = (0, react_1.useRef)(Boolean(open));
17
17
  const [drawerOpen, setDrawerOpen] = (0, react_1.useState)(Boolean(open));
18
18
  const toggleDrawer = (0, react_1.useCallback)(() => {
19
- setDrawerOpen((open) => !open);
20
- }, []);
19
+ setDrawerOpen((open) => {
20
+ openRef.current = !open;
21
+ return openRef.current;
22
+ });
23
+ if (!openRef.current) {
24
+ onClose?.();
25
+ }
26
+ }, [onClose]);
21
27
  const openDrawer = (0, react_1.useCallback)(() => {
22
28
  setDrawerOpen(true);
29
+ openRef.current = true;
23
30
  }, []);
24
31
  const closeDrawer = (0, react_1.useCallback)(() => {
25
32
  setDrawerOpen(false);
26
- }, []);
33
+ openRef.current = false;
34
+ onClose?.();
35
+ }, [onClose]);
27
36
  (0, react_1.useImperativeHandle)(ref, () => ({
28
37
  isOpen: () => openRef.current,
29
38
  toggleDrawer,
@@ -38,18 +47,21 @@ exports.AppDrawer = (0, react_1.forwardRef)(({ elementRef, open, integrator, con
38
47
  height: '100%',
39
48
  },
40
49
  }), [config, integrator]);
41
- return ((0, jsx_runtime_1.jsxs)(AppProvider_1.AppProvider, { config: widgetConfig, children: [!widgetConfig.hiddenUI?.includes(types_1.HiddenUI.DrawerButton) ? ((0, jsx_runtime_1.jsxs)(AppDrawer_style_1.DrawerButton, { variant: "contained", onClick: toggleDrawer, open: drawerOpen, drawerProps: config?.containerStyle, children: [drawerOpen ? ((0, jsx_runtime_1.jsx)(KeyboardArrowRight_1.default, {})) : ((0, jsx_runtime_1.jsx)(KeyboardArrowLeft_1.default, {})), (0, jsx_runtime_1.jsx)(exports.DrawerButtonText, { open: drawerOpen, subvariant: config?.subvariant })] })) : null, (0, jsx_runtime_1.jsxs)(material_1.Drawer, { ref: elementRef, anchor: "right", open: drawerOpen, onClose: closeDrawer, BackdropProps: {
42
- sx: {
43
- backgroundColor: 'rgb(0 0 0 / 48%)',
44
- backdropFilter: 'blur(3px)',
45
- },
46
- }, PaperProps: {
47
- sx: {
48
- width: config?.containerStyle?.width ?? '100%',
49
- minWidth: config?.containerStyle?.minWidth ?? 360,
50
- maxWidth: config?.containerStyle?.maxWidth ?? 392,
51
- },
52
- }, keepMounted: true, children: [(0, jsx_runtime_1.jsx)(AppDrawer_style_1.CloseButtonLayout, { onClick: closeDrawer, edge: "end", children: (0, jsx_runtime_1.jsx)(CloseRounded_1.default, {}) }), (0, jsx_runtime_1.jsx)(App_1.AppDefault, {})] })] }));
50
+ const drawerContext = (0, react_1.useMemo)(() => ({
51
+ closeDrawer,
52
+ }), [closeDrawer]);
53
+ return ((0, jsx_runtime_1.jsx)(AppDrawerContext_1.DrawerContext.Provider, { value: drawerContext, children: (0, jsx_runtime_1.jsxs)(AppProvider_1.AppProvider, { config: widgetConfig, children: [!widgetConfig.hiddenUI?.includes(types_1.HiddenUI.DrawerButton) ? ((0, jsx_runtime_1.jsxs)(AppDrawer_style_1.DrawerButton, { variant: "contained", onClick: toggleDrawer, open: drawerOpen, drawerProps: config?.containerStyle, children: [drawerOpen ? ((0, jsx_runtime_1.jsx)(KeyboardArrowRight_1.default, {})) : ((0, jsx_runtime_1.jsx)(KeyboardArrowLeft_1.default, {})), (0, jsx_runtime_1.jsx)(exports.DrawerButtonText, { open: drawerOpen, subvariant: config?.subvariant })] })) : null, (0, jsx_runtime_1.jsx)(material_1.Drawer, { ref: elementRef, anchor: "right", open: drawerOpen, onClose: closeDrawer, BackdropProps: {
54
+ sx: {
55
+ backgroundColor: 'rgb(0 0 0 / 48%)',
56
+ backdropFilter: 'blur(3px)',
57
+ },
58
+ }, PaperProps: {
59
+ sx: {
60
+ width: config?.containerStyle?.width ?? '100%',
61
+ minWidth: config?.containerStyle?.minWidth ?? 360,
62
+ maxWidth: config?.containerStyle?.maxWidth ?? 392,
63
+ },
64
+ }, keepMounted: true, children: (0, jsx_runtime_1.jsx)(App_1.AppDefault, {}) })] }) }));
53
65
  });
54
66
  const DrawerButtonText = ({ open, subvariant, }) => {
55
67
  const { t } = (0, react_i18next_1.useTranslation)();
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export interface WidgetDrawerContext {
3
+ closeDrawer?(): void;
4
+ }
5
+ export declare const DrawerContext: import("react").Context<WidgetDrawerContext>;
6
+ export declare const useDrawer: () => WidgetDrawerContext;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDrawer = exports.DrawerContext = void 0;
4
+ const react_1 = require("react");
5
+ exports.DrawerContext = (0, react_1.createContext)({});
6
+ const useDrawer = () => (0, react_1.useContext)(exports.DrawerContext);
7
+ exports.useDrawer = useDrawer;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { IconButtonProps } from '@mui/material/IconButton';
3
+ export declare const CloseDrawerButton: React.FC<IconButtonProps>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CloseDrawerButton = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const CloseRounded_1 = require("@mui/icons-material/CloseRounded");
6
+ const material_1 = require("@mui/material");
7
+ const IconButton_1 = require("@mui/material/IconButton");
8
+ const react_i18next_1 = require("react-i18next");
9
+ const AppDrawerContext_1 = require("../../AppDrawerContext");
10
+ const CloseDrawerButton = (props) => {
11
+ const { t } = (0, react_i18next_1.useTranslation)();
12
+ const { closeDrawer } = (0, AppDrawerContext_1.useDrawer)();
13
+ return ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: t('button.close'), enterDelay: 400, arrow: true, children: (0, jsx_runtime_1.jsx)(IconButton_1.default, { size: "medium", onClick: closeDrawer, ...props, children: (0, jsx_runtime_1.jsx)(CloseRounded_1.default, {}) }) }));
14
+ };
15
+ exports.CloseDrawerButton = CloseDrawerButton;
@@ -46,11 +46,14 @@ exports.WalletButton = (0, styles_1.styled)(material_1.Button)(({ theme }) => ({
46
46
  fontSize: '24px',
47
47
  },
48
48
  }));
49
- exports.DrawerWalletContainer = (0, styles_1.styled)(material_1.Box)(() => ({
49
+ exports.DrawerWalletContainer = (0, styles_1.styled)(material_1.Box)(({ theme }) => ({
50
50
  width: '100%',
51
51
  display: 'flex',
52
- justifyItems: 'start',
53
- '& > button': {
54
- marginLeft: '-0.5rem',
52
+ justifyContent: 'space-between',
53
+ '& button:first-of-type': {
54
+ marginLeft: theme.spacing(-1),
55
+ },
56
+ '& button:last-of-type': {
57
+ marginRight: theme.spacing(-1.25),
55
58
  },
56
59
  }));
@@ -13,6 +13,7 @@ const providers_1 = require("../../providers");
13
13
  const stores_1 = require("../../stores");
14
14
  const types_1 = require("../../types");
15
15
  const utils_1 = require("../../utils");
16
+ const CloseDrawerButton_1 = require("./CloseDrawerButton");
16
17
  const Header_style_1 = require("./Header.style");
17
18
  const NavigationTabs_1 = require("./NavigationTabs");
18
19
  const WalletHeader_1 = require("./WalletHeader");
@@ -81,8 +82,13 @@ const NavigationHeader = () => {
81
82
  }
82
83
  }
83
84
  };
84
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(Header_style_1.HeaderAppBar, { elevation: 0, children: [utils_1.backButtonRoutes.includes(path) ? ((0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "medium", edge: "start", onClick: navigateBack, children: (0, jsx_runtime_1.jsx)(ArrowBack_1.default, {}) })) : null, splitSubvariant ? ((0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1, children: !hiddenUI?.includes(types_1.HiddenUI.WalletMenu) ? ((0, jsx_runtime_1.jsx)(WalletHeader_1.WalletMenuButton, {})) : null })) : ((0, jsx_runtime_1.jsx)(material_1.Typography, { fontSize: hasPath ? 18 : 24, align: hasPath ? 'center' : 'left', fontWeight: "700", flex: 1, noWrap: true, children: title || handleHeaderTitle() })), (0, jsx_runtime_1.jsxs)(react_router_dom_1.Routes, { children: [(0, jsx_runtime_1.jsx)(react_router_dom_1.Route, { path: utils_1.navigationRoutes.home, element: (0, jsx_runtime_1.jsxs)(material_1.Box, { paddingRight: variant === 'drawer' && subvariant === 'split' ? 5 : 0, children: [account.isActive && !hiddenUI?.includes(types_1.HiddenUI.History) ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: t(`header.transactionHistory`), enterDelay: 400, arrow: true, children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "medium", edge: "start", onClick: () => navigate(utils_1.navigationRoutes.transactionHistory), children: (0, jsx_runtime_1.jsx)(ReceiptLong_1.default, {}) }) })) : null, (0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: t(`header.settings`), enterDelay: 400, arrow: true, children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "medium", onClick: () => navigate(utils_1.navigationRoutes.settings), sx: {
85
- marginRight: -1.25,
86
- }, children: (0, jsx_runtime_1.jsx)(Settings_1.default, {}) }) })] }) }), (0, jsx_runtime_1.jsx)(react_router_dom_1.Route, { path: "*", element: element || (0, jsx_runtime_1.jsx)(material_1.Box, { width: 28, height: 40 }) })] })] }), splitSubvariant ? (0, jsx_runtime_1.jsx)(NavigationTabs_1.NavigationTabs, {}) : null] }));
85
+ const showDrawerCloseButton = variant === 'drawer' &&
86
+ subvariant === 'split' &&
87
+ !hiddenUI?.includes(types_1.HiddenUI.DrawerCloseButton);
88
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(Header_style_1.HeaderAppBar, { elevation: 0, children: [utils_1.backButtonRoutes.includes(path) ? ((0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "medium", edge: "start", onClick: navigateBack, children: (0, jsx_runtime_1.jsx)(ArrowBack_1.default, {}) })) : null, splitSubvariant ? ((0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1, children: !hiddenUI?.includes(types_1.HiddenUI.WalletMenu) ? ((0, jsx_runtime_1.jsx)(WalletHeader_1.WalletMenuButton, {})) : null })) : ((0, jsx_runtime_1.jsx)(material_1.Typography, { fontSize: hasPath ? 18 : 24, align: hasPath ? 'center' : 'left', fontWeight: "700", flex: 1, noWrap: true, children: title || handleHeaderTitle() })), (0, jsx_runtime_1.jsxs)(react_router_dom_1.Routes, { children: [(0, jsx_runtime_1.jsx)(react_router_dom_1.Route, { path: utils_1.navigationRoutes.home, element: (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [account.isActive && !hiddenUI?.includes(types_1.HiddenUI.History) ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: t(`header.transactionHistory`), enterDelay: 400, arrow: true, children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "medium", edge: "start", onClick: () => navigate(utils_1.navigationRoutes.transactionHistory), children: (0, jsx_runtime_1.jsx)(ReceiptLong_1.default, {}) }) })) : null, (0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: t(`header.settings`), enterDelay: 400, arrow: true, children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "medium", onClick: () => navigate(utils_1.navigationRoutes.settings), sx: {
89
+ marginRight: showDrawerCloseButton ? 0 : -1.25,
90
+ }, children: (0, jsx_runtime_1.jsx)(Settings_1.default, {}) }) }), showDrawerCloseButton ? ((0, jsx_runtime_1.jsx)(CloseDrawerButton_1.CloseDrawerButton, { sx: {
91
+ marginRight: -1.25,
92
+ } })) : null] }) }), (0, jsx_runtime_1.jsx)(react_router_dom_1.Route, { path: "*", element: element || (0, jsx_runtime_1.jsx)(material_1.Box, { width: 28, height: 40 }) })] })] }), splitSubvariant ? (0, jsx_runtime_1.jsx)(NavigationTabs_1.NavigationTabs, {}) : null] }));
87
93
  };
88
94
  exports.NavigationHeader = NavigationHeader;
@@ -13,7 +13,9 @@ const react_i18next_1 = require("react-i18next");
13
13
  const react_router_dom_1 = require("react-router-dom");
14
14
  const hooks_1 = require("../../hooks");
15
15
  const providers_1 = require("../../providers");
16
+ const types_1 = require("../../types");
16
17
  const utils_1 = require("../../utils");
18
+ const CloseDrawerButton_1 = require("./CloseDrawerButton");
17
19
  const Header_style_1 = require("./Header.style");
18
20
  const WalletMenu_1 = require("./WalletMenu");
19
21
  const WalletHeader = () => {
@@ -22,9 +24,10 @@ const WalletHeader = () => {
22
24
  exports.WalletHeader = WalletHeader;
23
25
  const WalletMenuButton = () => {
24
26
  const { account } = (0, providers_1.useWallet)();
25
- const { variant } = (0, providers_1.useWidgetConfig)();
27
+ const { variant, subvariant, hiddenUI } = (0, providers_1.useWidgetConfig)();
26
28
  if (variant === 'drawer') {
27
- return ((0, jsx_runtime_1.jsx)(Header_style_1.DrawerWalletContainer, { children: account.isActive ? (0, jsx_runtime_1.jsx)(ConnectedButton, {}) : (0, jsx_runtime_1.jsx)(ConnectButton, {}) }));
29
+ return ((0, jsx_runtime_1.jsxs)(Header_style_1.DrawerWalletContainer, { children: [account.isActive ? (0, jsx_runtime_1.jsx)(ConnectedButton, {}) : (0, jsx_runtime_1.jsx)(ConnectButton, {}), subvariant !== 'split' &&
30
+ !hiddenUI?.includes(types_1.HiddenUI.DrawerCloseButton) ? ((0, jsx_runtime_1.jsx)(CloseDrawerButton_1.CloseDrawerButton, {})) : null] }));
28
31
  }
29
32
  return account.isActive ? (0, jsx_runtime_1.jsx)(ConnectedButton, {}) : (0, jsx_runtime_1.jsx)(ConnectButton, {});
30
33
  };
@@ -14,9 +14,15 @@ const ProgressToNextUpdate_1 = require("../ProgressToNextUpdate");
14
14
  const RouteCard_1 = require("../RouteCard");
15
15
  const RoutesExpanded_style_1 = require("./RoutesExpanded.style");
16
16
  const timeout = { enter: 225, exit: 225, appear: 0 };
17
+ const routes = [
18
+ {
19
+ path: '/',
20
+ element: true,
21
+ },
22
+ ];
17
23
  const RoutesExpanded = () => {
18
- const element = (0, react_router_dom_1.useMatch)('/');
19
- return ((0, jsx_runtime_1.jsx)(RoutesExpanded_style_1.CollapseContainer, { children: (0, jsx_runtime_1.jsx)(material_1.Collapse, { timeout: timeout, in: !!element, orientation: "horizontal", children: (0, jsx_runtime_1.jsx)(material_1.Grow, { timeout: timeout, in: !!element, mountOnEnter: true, unmountOnExit: true, children: (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(exports.RoutesExpandedElement, {}) }) }) }) }));
24
+ const match = (0, react_router_dom_1.useRoutes)(routes);
25
+ return ((0, jsx_runtime_1.jsx)(RoutesExpanded_style_1.CollapseContainer, { children: (0, jsx_runtime_1.jsx)(material_1.Collapse, { timeout: timeout, in: !!match, orientation: "horizontal", children: (0, jsx_runtime_1.jsx)(material_1.Grow, { timeout: timeout, in: !!match, mountOnEnter: true, unmountOnExit: true, children: (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(exports.RoutesExpandedElement, {}) }) }) }) }));
20
26
  };
21
27
  exports.RoutesExpanded = RoutesExpanded;
22
28
  const RoutesExpandedElement = () => {
@@ -26,7 +32,6 @@ const RoutesExpandedElement = () => {
26
32
  const { subvariant, containerStyle } = (0, providers_1.useWidgetConfig)();
27
33
  const { isValid, isValidating } = (0, react_hook_form_1.useFormState)();
28
34
  const { routes, isLoading, isFetching, isFetched, dataUpdatedAt, refetchTime, refetch, } = (0, hooks_1.useRoutes)();
29
- const currentRoute = routes?.[0];
30
35
  const handleRouteClick = (route) => {
31
36
  if (isValid && !isValidating) {
32
37
  setExecutableRoute(route);
@@ -35,6 +40,7 @@ const RoutesExpandedElement = () => {
35
40
  });
36
41
  }
37
42
  };
43
+ const currentRoute = routes?.[0];
38
44
  const expanded = Boolean(currentRoute || isLoading || isFetching || isFetched);
39
45
  const routeNotFound = !currentRoute && !isLoading && !isFetching && expanded;
40
46
  return ((0, jsx_runtime_1.jsx)(material_1.Collapse, { timeout: timeout.enter, in: expanded, orientation: "horizontal", children: (0, jsx_runtime_1.jsx)(material_1.Grow, { timeout: timeout.enter, in: expanded, mountOnEnter: true, unmountOnExit: true, children: (0, jsx_runtime_1.jsx)(RoutesExpanded_style_1.Container, { sx: containerStyle, enableColorScheme: true, children: (0, jsx_runtime_1.jsxs)(RoutesExpanded_style_1.ScrollableContainer, { children: [(0, jsx_runtime_1.jsxs)(RoutesExpanded_style_1.Header, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { fontSize: 18, fontWeight: "700", flex: 1, noWrap: true, children: subvariant === 'nft'
@@ -22,7 +22,7 @@ const TokenList = ({ formType, height, onClick, }) => {
22
22
  let filteredTokens = (tokensWithBalance ??
23
23
  chainTokens ??
24
24
  []);
25
- const searchFilter = tokenSearchFilter?.toUpperCase() ?? '';
25
+ const searchFilter = tokenSearchFilter?.replaceAll('$', '')?.toUpperCase() ?? '';
26
26
  filteredTokens = tokenSearchFilter
27
27
  ? filteredTokens.filter((token) => token.name.toUpperCase().includes(searchFilter) ||
28
28
  token.symbol.toUpperCase().includes(searchFilter) ||
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "2.9.5";
2
+ export declare const version = "2.10.1";
@@ -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.5';
5
+ exports.version = '2.10.1';
package/cjs/i18n/en.json CHANGED
@@ -13,6 +13,7 @@
13
13
  "buy": "Buy",
14
14
  "buyNow": "Buy now",
15
15
  "cancel": "Cancel",
16
+ "close": "Close",
16
17
  "connectWallet": "Connect wallet",
17
18
  "contactSupport": "Contact support",
18
19
  "continue": "Continue",
@@ -17,6 +17,7 @@ export type DisabledUIType = `${DisabledUI}`;
17
17
  export declare enum HiddenUI {
18
18
  Appearance = "appearance",
19
19
  DrawerButton = "drawerButton",
20
+ DrawerCloseButton = "drawerCloseButton",
20
21
  History = "history",
21
22
  Language = "language",
22
23
  PoweredBy = "poweredBy",
@@ -122,6 +123,10 @@ export interface WidgetConfig {
122
123
  export type WidgetDrawerProps = {
123
124
  elementRef?: RefObject<HTMLDivElement>;
124
125
  open?: boolean;
126
+ /**
127
+ * Make sure to make the onClose callback stable (e.g. using useCallback) to avoid causing re-renders of the entire widget
128
+ */
129
+ onClose?(): void;
125
130
  };
126
131
  export interface WidgetConfigProps {
127
132
  config: WidgetConfig;
@@ -12,6 +12,7 @@ var HiddenUI;
12
12
  (function (HiddenUI) {
13
13
  HiddenUI["Appearance"] = "appearance";
14
14
  HiddenUI["DrawerButton"] = "drawerButton";
15
+ HiddenUI["DrawerCloseButton"] = "drawerCloseButton";
15
16
  HiddenUI["History"] = "history";
16
17
  HiddenUI["Language"] = "language";
17
18
  HiddenUI["PoweredBy"] = "poweredBy";
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { IconButtonProps } from '@mui/material/IconButton';
3
+ export declare const CloseDrawerButton: React.FC<IconButtonProps>;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import CloseIcon from '@mui/icons-material/CloseRounded';
3
+ import { Tooltip } from '@mui/material';
4
+ import IconButton from '@mui/material/IconButton';
5
+ import { useTranslation } from 'react-i18next';
6
+ import { useDrawer } from '../../AppDrawerContext';
7
+ export const CloseDrawerButton = (props) => {
8
+ const { t } = useTranslation();
9
+ const { closeDrawer } = useDrawer();
10
+ return (_jsx(Tooltip, { title: t('button.close'), enterDelay: 400, arrow: true, children: _jsx(IconButton, { size: "medium", onClick: closeDrawer, ...props, children: _jsx(CloseIcon, {}) }) }));
11
+ };
@@ -43,11 +43,14 @@ export const WalletButton = styled(Button)(({ theme }) => ({
43
43
  fontSize: '24px',
44
44
  },
45
45
  }));
46
- export const DrawerWalletContainer = styled(Box)(() => ({
46
+ export const DrawerWalletContainer = styled(Box)(({ theme }) => ({
47
47
  width: '100%',
48
48
  display: 'flex',
49
- justifyItems: 'start',
50
- '& > button': {
51
- marginLeft: '-0.5rem',
49
+ justifyContent: 'space-between',
50
+ '& button:first-of-type': {
51
+ marginLeft: theme.spacing(-1),
52
+ },
53
+ '& button:last-of-type': {
54
+ marginRight: theme.spacing(-1.25),
52
55
  },
53
56
  }));
@@ -10,6 +10,7 @@ import { useWallet, useWidgetConfig } from '../../providers';
10
10
  import { useHeaderStore } from '../../stores';
11
11
  import { HiddenUI } from '../../types';
12
12
  import { backButtonRoutes, navigationRoutes, navigationRoutesValues, } from '../../utils';
13
+ import { CloseDrawerButton } from './CloseDrawerButton';
13
14
  import { HeaderAppBar } from './Header.style';
14
15
  import { NavigationTabs } from './NavigationTabs';
15
16
  import { WalletMenuButton } from './WalletHeader';
@@ -78,7 +79,12 @@ export const NavigationHeader = () => {
78
79
  }
79
80
  }
80
81
  };
81
- return (_jsxs(_Fragment, { children: [_jsxs(HeaderAppBar, { elevation: 0, children: [backButtonRoutes.includes(path) ? (_jsx(IconButton, { size: "medium", edge: "start", onClick: navigateBack, children: _jsx(ArrowBackIcon, {}) })) : null, splitSubvariant ? (_jsx(Box, { flex: 1, children: !hiddenUI?.includes(HiddenUI.WalletMenu) ? (_jsx(WalletMenuButton, {})) : null })) : (_jsx(Typography, { fontSize: hasPath ? 18 : 24, align: hasPath ? 'center' : 'left', fontWeight: "700", flex: 1, noWrap: true, children: title || handleHeaderTitle() })), _jsxs(Routes, { children: [_jsx(Route, { path: navigationRoutes.home, element: _jsxs(Box, { paddingRight: variant === 'drawer' && subvariant === 'split' ? 5 : 0, children: [account.isActive && !hiddenUI?.includes(HiddenUI.History) ? (_jsx(Tooltip, { title: t(`header.transactionHistory`), enterDelay: 400, arrow: true, children: _jsx(IconButton, { size: "medium", edge: "start", onClick: () => navigate(navigationRoutes.transactionHistory), children: _jsx(ReceiptLongIcon, {}) }) })) : null, _jsx(Tooltip, { title: t(`header.settings`), enterDelay: 400, arrow: true, children: _jsx(IconButton, { size: "medium", onClick: () => navigate(navigationRoutes.settings), sx: {
82
- marginRight: -1.25,
83
- }, children: _jsx(SettingsIcon, {}) }) })] }) }), _jsx(Route, { path: "*", element: element || _jsx(Box, { width: 28, height: 40 }) })] })] }), splitSubvariant ? _jsx(NavigationTabs, {}) : null] }));
82
+ const showDrawerCloseButton = variant === 'drawer' &&
83
+ subvariant === 'split' &&
84
+ !hiddenUI?.includes(HiddenUI.DrawerCloseButton);
85
+ return (_jsxs(_Fragment, { children: [_jsxs(HeaderAppBar, { elevation: 0, children: [backButtonRoutes.includes(path) ? (_jsx(IconButton, { size: "medium", edge: "start", onClick: navigateBack, children: _jsx(ArrowBackIcon, {}) })) : null, splitSubvariant ? (_jsx(Box, { flex: 1, children: !hiddenUI?.includes(HiddenUI.WalletMenu) ? (_jsx(WalletMenuButton, {})) : null })) : (_jsx(Typography, { fontSize: hasPath ? 18 : 24, align: hasPath ? 'center' : 'left', fontWeight: "700", flex: 1, noWrap: true, children: title || handleHeaderTitle() })), _jsxs(Routes, { children: [_jsx(Route, { path: navigationRoutes.home, element: _jsxs(Box, { children: [account.isActive && !hiddenUI?.includes(HiddenUI.History) ? (_jsx(Tooltip, { title: t(`header.transactionHistory`), enterDelay: 400, arrow: true, children: _jsx(IconButton, { size: "medium", edge: "start", onClick: () => navigate(navigationRoutes.transactionHistory), children: _jsx(ReceiptLongIcon, {}) }) })) : null, _jsx(Tooltip, { title: t(`header.settings`), enterDelay: 400, arrow: true, children: _jsx(IconButton, { size: "medium", onClick: () => navigate(navigationRoutes.settings), sx: {
86
+ marginRight: showDrawerCloseButton ? 0 : -1.25,
87
+ }, children: _jsx(SettingsIcon, {}) }) }), showDrawerCloseButton ? (_jsx(CloseDrawerButton, { sx: {
88
+ marginRight: -1.25,
89
+ } })) : null] }) }), _jsx(Route, { path: "*", element: element || _jsx(Box, { width: 28, height: 40 }) })] })] }), splitSubvariant ? _jsx(NavigationTabs, {}) : null] }));
84
90
  };
@@ -10,7 +10,9 @@ import { useTranslation } from 'react-i18next';
10
10
  import { useLocation, useNavigate } from 'react-router-dom';
11
11
  import { useChain } from '../../hooks';
12
12
  import { useWallet, useWidgetConfig } from '../../providers';
13
+ import { HiddenUI } from '../../types';
13
14
  import { navigationRoutes, shortenAddress } from '../../utils';
15
+ import { CloseDrawerButton } from './CloseDrawerButton';
14
16
  import { DrawerWalletContainer, HeaderAppBar, WalletButton, } from './Header.style';
15
17
  import { WalletMenu } from './WalletMenu';
16
18
  export const WalletHeader = () => {
@@ -18,9 +20,10 @@ export const WalletHeader = () => {
18
20
  };
19
21
  export const WalletMenuButton = () => {
20
22
  const { account } = useWallet();
21
- const { variant } = useWidgetConfig();
23
+ const { variant, subvariant, hiddenUI } = useWidgetConfig();
22
24
  if (variant === 'drawer') {
23
- return (_jsx(DrawerWalletContainer, { children: account.isActive ? _jsx(ConnectedButton, {}) : _jsx(ConnectButton, {}) }));
25
+ return (_jsxs(DrawerWalletContainer, { children: [account.isActive ? _jsx(ConnectedButton, {}) : _jsx(ConnectButton, {}), subvariant !== 'split' &&
26
+ !hiddenUI?.includes(HiddenUI.DrawerCloseButton) ? (_jsx(CloseDrawerButton, {})) : null] }));
24
27
  }
25
28
  return account.isActive ? _jsx(ConnectedButton, {}) : _jsx(ConnectButton, {});
26
29
  };
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Collapse, Grow, Stack, Typography } from '@mui/material';
3
3
  import { useFormState } from 'react-hook-form';
4
4
  import { useTranslation } from 'react-i18next';
5
- import { useMatch, useNavigate } from 'react-router-dom';
5
+ import { useRoutes as useDOMRoutes, useNavigate } from 'react-router-dom';
6
6
  import { useRoutes } from '../../hooks';
7
7
  import { useWidgetConfig } from '../../providers';
8
8
  import { useSetExecutableRoute } from '../../stores';
@@ -11,9 +11,15 @@ import { ProgressToNextUpdate } from '../ProgressToNextUpdate';
11
11
  import { RouteCard, RouteCardSkeleton, RouteNotFoundCard } from '../RouteCard';
12
12
  import { CollapseContainer, Container, Header, ScrollableContainer, } from './RoutesExpanded.style';
13
13
  const timeout = { enter: 225, exit: 225, appear: 0 };
14
+ const routes = [
15
+ {
16
+ path: '/',
17
+ element: true,
18
+ },
19
+ ];
14
20
  export const RoutesExpanded = () => {
15
- const element = useMatch('/');
16
- return (_jsx(CollapseContainer, { children: _jsx(Collapse, { timeout: timeout, in: !!element, orientation: "horizontal", children: _jsx(Grow, { timeout: timeout, in: !!element, mountOnEnter: true, unmountOnExit: true, children: _jsx("div", { children: _jsx(RoutesExpandedElement, {}) }) }) }) }));
21
+ const match = useDOMRoutes(routes);
22
+ return (_jsx(CollapseContainer, { children: _jsx(Collapse, { timeout: timeout, in: !!match, orientation: "horizontal", children: _jsx(Grow, { timeout: timeout, in: !!match, mountOnEnter: true, unmountOnExit: true, children: _jsx("div", { children: _jsx(RoutesExpandedElement, {}) }) }) }) }));
17
23
  };
18
24
  export const RoutesExpandedElement = () => {
19
25
  const { t } = useTranslation();
@@ -22,7 +28,6 @@ export const RoutesExpandedElement = () => {
22
28
  const { subvariant, containerStyle } = useWidgetConfig();
23
29
  const { isValid, isValidating } = useFormState();
24
30
  const { routes, isLoading, isFetching, isFetched, dataUpdatedAt, refetchTime, refetch, } = useRoutes();
25
- const currentRoute = routes?.[0];
26
31
  const handleRouteClick = (route) => {
27
32
  if (isValid && !isValidating) {
28
33
  setExecutableRoute(route);
@@ -31,6 +36,7 @@ export const RoutesExpandedElement = () => {
31
36
  });
32
37
  }
33
38
  };
39
+ const currentRoute = routes?.[0];
34
40
  const expanded = Boolean(currentRoute || isLoading || isFetching || isFetched);
35
41
  const routeNotFound = !currentRoute && !isLoading && !isFetching && expanded;
36
42
  return (_jsx(Collapse, { timeout: timeout.enter, in: expanded, orientation: "horizontal", children: _jsx(Grow, { timeout: timeout.enter, in: expanded, mountOnEnter: true, unmountOnExit: true, children: _jsx(Container, { sx: containerStyle, enableColorScheme: true, children: _jsxs(ScrollableContainer, { children: [_jsxs(Header, { children: [_jsx(Typography, { fontSize: 18, fontWeight: "700", flex: 1, noWrap: true, children: subvariant === 'nft'
@@ -19,7 +19,7 @@ export const TokenList = ({ formType, height, onClick, }) => {
19
19
  let filteredTokens = (tokensWithBalance ??
20
20
  chainTokens ??
21
21
  []);
22
- const searchFilter = tokenSearchFilter?.toUpperCase() ?? '';
22
+ const searchFilter = tokenSearchFilter?.replaceAll('$', '')?.toUpperCase() ?? '';
23
23
  filteredTokens = tokenSearchFilter
24
24
  ? filteredTokens.filter((token) => token.name.toUpperCase().includes(searchFilter) ||
25
25
  token.symbol.toUpperCase().includes(searchFilter) ||
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "2.9.5";
2
+ export declare const version = "2.10.1";
package/config/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/widget';
2
- export const version = '2.9.5';
2
+ export const version = '2.10.1';
package/i18n/en.json CHANGED
@@ -13,6 +13,7 @@
13
13
  "buy": "Buy",
14
14
  "buyNow": "Buy now",
15
15
  "cancel": "Cancel",
16
+ "close": "Close",
16
17
  "connectWallet": "Connect wallet",
17
18
  "contactSupport": "Contact support",
18
19
  "continue": "Continue",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/widget",
3
- "version": "2.9.5",
3
+ "version": "2.10.1",
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",
@@ -43,8 +43,8 @@
43
43
  "@ethersproject/address": "^5.7.0",
44
44
  "@ethersproject/experimental": "^5.7.0",
45
45
  "@ethersproject/providers": "^5.7.2",
46
- "@lifi/sdk": "^2.4.3",
47
- "@lifi/wallet-management": "^2.5.2",
46
+ "@lifi/sdk": "^2.5.0",
47
+ "@lifi/wallet-management": "^2.6.0",
48
48
  "@mui/icons-material": "^5.14.14",
49
49
  "@mui/lab": "^5.0.0-alpha.149",
50
50
  "@mui/material": "^5.14.14",