@lifi/widget 1.1.3 → 1.2.0

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.
Files changed (83) hide show
  1. package/App.js +2 -1
  2. package/components/Initializer.d.ts +2 -0
  3. package/components/Initializer.js +5 -0
  4. package/components/StepToken.js +1 -1
  5. package/components/SwapButton/SwapButton.js +5 -2
  6. package/components/SwapInProgress/SwapInProgress.js +1 -1
  7. package/components/SwapRoutes/SwapRoutes.js +2 -1
  8. package/components/TextFitter/TextFitter.js +9 -5
  9. package/hooks/index.d.ts +1 -3
  10. package/hooks/index.js +1 -3
  11. package/hooks/useHasSufficientBalance.js +1 -1
  12. package/hooks/useInitializer.d.ts +1 -0
  13. package/hooks/useInitializer.js +5 -0
  14. package/hooks/{useRouteExecution/useRouteExecution.d.ts → useRouteExecution.d.ts} +1 -1
  15. package/hooks/{useRouteExecution/useRouteExecution.js → useRouteExecution.js} +5 -5
  16. package/hooks/useSwapRoutes.js +9 -7
  17. package/hooks/useTools.d.ts +1 -0
  18. package/hooks/useTools.js +14 -0
  19. package/i18n/en/translation.json +0 -2
  20. package/i18n/index.d.ts +0 -2
  21. package/package.json +5 -5
  22. package/pages/SettingsPage/AdvancedPreferences.js +5 -4
  23. package/pages/SettingsPage/ColorSchemeButtonGroup.js +1 -1
  24. package/pages/SettingsPage/EnabledBridgesSelect.js +11 -6
  25. package/pages/SettingsPage/EnabledExchangesSelect.js +10 -6
  26. package/pages/SettingsPage/GasPriceSelect.js +4 -4
  27. package/pages/SettingsPage/RoutePrioritySelect.js +4 -4
  28. package/pages/SettingsPage/SlippageInput.js +7 -10
  29. package/pages/SwapPage/ExecutionItem.js +1 -1
  30. package/pages/SwapPage/StatusBottomSheet.d.ts +1 -1
  31. package/pages/SwapPage/StatusBottomSheet.style.d.ts +1 -1
  32. package/pages/SwapPage/StepItem.js +1 -1
  33. package/pages/SwapPage/StepTimer.js +3 -2
  34. package/pages/SwapRoutesPage/SwapRoutesPage.js +2 -1
  35. package/providers/SwapFormProvider/SwapFormProvider.d.ts +0 -3
  36. package/providers/SwapFormProvider/SwapFormProvider.js +0 -3
  37. package/providers/SwapFormProvider/types.d.ts +0 -19
  38. package/providers/SwapFormProvider/types.js +0 -9
  39. package/providers/ThemeProvider/ThemeProvider.js +1 -1
  40. package/providers/WidgetProvider/types.d.ts +2 -2
  41. package/stores/index.d.ts +2 -0
  42. package/stores/index.js +2 -0
  43. package/stores/route/index.d.ts +5 -0
  44. package/stores/route/index.js +5 -0
  45. package/{hooks/useRouteExecution → stores/route}/types.d.ts +0 -0
  46. package/{hooks/useRouteExecution → stores/route}/types.js +0 -0
  47. package/stores/route/useCurrentRoute.d.ts +2 -0
  48. package/stores/route/useCurrentRoute.js +5 -0
  49. package/stores/route/useExecutingRoutes.d.ts +1 -0
  50. package/stores/route/useExecutingRoutes.js +4 -0
  51. package/{hooks/useRouteExecution → stores/route}/useRouteStore.d.ts +3 -5
  52. package/{hooks/useRouteExecution → stores/route}/useRouteStore.js +16 -26
  53. package/stores/route/useSetExecutableRoute.d.ts +1 -0
  54. package/stores/route/useSetExecutableRoute.js +4 -0
  55. package/stores/settings/index.d.ts +5 -0
  56. package/stores/settings/index.js +5 -0
  57. package/stores/settings/types.d.ts +23 -0
  58. package/stores/settings/types.js +1 -0
  59. package/stores/settings/useAppearance.d.ts +2 -0
  60. package/stores/settings/useAppearance.js +7 -0
  61. package/stores/settings/useSetSettings.d.ts +5 -0
  62. package/stores/settings/useSetSettings.js +5 -0
  63. package/stores/settings/useSettings.d.ts +2 -0
  64. package/stores/settings/useSettings.js +8 -0
  65. package/stores/settings/useSettingsStore.d.ts +25 -0
  66. package/stores/settings/useSettingsStore.js +84 -0
  67. package/types/widget.d.ts +31 -23
  68. package/utils/format.d.ts +1 -1
  69. package/utils/format.js +1 -1
  70. package/hooks/useBridges.d.ts +0 -1
  71. package/hooks/useBridges.js +0 -12
  72. package/hooks/useExchanges.d.ts +0 -1
  73. package/hooks/useExchanges.js +0 -12
  74. package/hooks/useRouteExecution/index.d.ts +0 -3
  75. package/hooks/useRouteExecution/index.js +0 -3
  76. package/hooks/useSettings/index.d.ts +0 -2
  77. package/hooks/useSettings/index.js +0 -2
  78. package/hooks/useSettings/types.d.ts +0 -5
  79. package/hooks/useSettings/types.js +0 -1
  80. package/hooks/useSettings/useSettingsStore.d.ts +0 -13
  81. package/hooks/useSettings/useSettingsStore.js +0 -22
  82. package/pages/MainPage/SendToRecipientForm.d.ts +0 -2
  83. package/pages/MainPage/SendToRecipientForm.js +0 -20
package/App.js CHANGED
@@ -3,6 +3,7 @@ import { Route, Routes } from 'react-router-dom';
3
3
  import { AppProvider } from './AppProvider';
4
4
  import { AppContainer } from './components/AppContainer';
5
5
  import { Header } from './components/Header';
6
+ import { Initializer } from './components/Initializer';
6
7
  import { MainPage } from './pages/MainPage';
7
8
  import { SelectTokenPage } from './pages/SelectTokenPage';
8
9
  import { SelectWalletPage } from './pages/SelectWalletPage';
@@ -14,5 +15,5 @@ export const App = ({ config }) => {
14
15
  return (_jsx(AppProvider, Object.assign({ config: config }, { children: _jsx(AppDefault, {}) })));
15
16
  };
16
17
  export const AppDefault = () => {
17
- return (_jsxs(AppContainer, { children: [_jsx(Header, {}), _jsxs(Routes, { children: [_jsx(Route, { path: routes.home, element: _jsx(MainPage, {}) }), _jsx(Route, { path: routes.selectWallet, element: _jsx(SelectWalletPage, {}) }), _jsx(Route, { path: routes.settings, element: _jsx(SettingsPage, {}) }), _jsx(Route, { path: routes.fromToken, element: _jsx(SelectTokenPage, { formType: "from" }) }), _jsx(Route, { path: routes.toToken, element: _jsx(SelectTokenPage, { formType: "to" }) }), _jsx(Route, { path: routes.swapRoutes, element: _jsx(SwapRoutesPage, {}) }), _jsx(Route, { path: routes.swap, element: _jsx(SwapPage, {}) })] })] }));
18
+ return (_jsxs(AppContainer, { children: [_jsx(Header, {}), _jsxs(Routes, { children: [_jsx(Route, { path: routes.home, element: _jsx(MainPage, {}) }), _jsx(Route, { path: routes.selectWallet, element: _jsx(SelectWalletPage, {}) }), _jsx(Route, { path: routes.settings, element: _jsx(SettingsPage, {}) }), _jsx(Route, { path: routes.fromToken, element: _jsx(SelectTokenPage, { formType: "from" }) }), _jsx(Route, { path: routes.toToken, element: _jsx(SelectTokenPage, { formType: "to" }) }), _jsx(Route, { path: routes.swapRoutes, element: _jsx(SwapRoutesPage, {}) }), _jsx(Route, { path: `${routes.swapRoutes}/${routes.swap}`, element: _jsx(SwapPage, {}) }), _jsx(Route, { path: routes.swap, element: _jsx(SwapPage, {}) })] }), _jsx(Initializer, {})] }));
18
19
  };
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const Initializer: React.FC;
@@ -0,0 +1,5 @@
1
+ import { useInitializer } from '../hooks/useInitializer';
2
+ export const Initializer = () => {
3
+ useInitializer();
4
+ return null;
5
+ };
@@ -15,7 +15,7 @@ import { formatTokenAmount } from '../utils/format';
15
15
  import { TextFitter } from './TextFitter';
16
16
  export const StepToken = (_a) => {
17
17
  var { token } = _a, other = __rest(_a, ["token"]);
18
- return (_jsxs(Box, Object.assign({ flex: 1 }, other, { children: [_jsxs(Box, Object.assign({ display: "flex", flex: 1 }, { children: [_jsx(Avatar, Object.assign({ src: token.logoURI, alt: token.symbol, sx: { marginRight: 2 } }, { children: token.symbol[0] })), _jsx(TextFitter, Object.assign({ maxHeight: 32, textStyle: {
18
+ return (_jsxs(Box, Object.assign({ flex: 1 }, other, { children: [_jsxs(Box, Object.assign({ display: "flex", flex: 1 }, { children: [_jsx(Avatar, Object.assign({ src: token.logoURI, alt: token.symbol, sx: { marginRight: 2 } }, { children: token.symbol[0] })), _jsx(TextFitter, Object.assign({ height: 32, textStyle: {
19
19
  fontWeight: 700,
20
20
  } }, { children: formatTokenAmount(token.amount, token.decimals) }))] })), _jsx(Typography, Object.assign({ fontSize: 14, lineHeight: 1, fontWeight: "500", color: "text.secondary", mr: 1, ml: 6 }, { children: token.symbol }))] })));
21
21
  };
@@ -12,9 +12,10 @@ import { ChainId } from '@lifinance/sdk';
12
12
  import { useWatch } from 'react-hook-form';
13
13
  import { useTranslation } from 'react-i18next';
14
14
  import { useNavigate } from 'react-router-dom';
15
- import { useChains, useCurrentRoute, useHasSufficientBalance, useSetExecutableRoute, useSwapRoutes, } from '../../hooks';
15
+ import { useChains, useHasSufficientBalance, useSwapRoutes } from '../../hooks';
16
16
  import { SwapFormKeyHelper } from '../../providers/SwapFormProvider';
17
17
  import { useWallet } from '../../providers/WalletProvider';
18
+ import { useCurrentRoute, useSetExecutableRoute } from '../../stores';
18
19
  import { routes } from '../../utils/routes';
19
20
  import { ButtonTooltip } from './ButtonTooltip';
20
21
  import { Button } from './SwapButton.style';
@@ -43,7 +44,9 @@ export const SwapButton = () => {
43
44
  else if (currentRoute &&
44
45
  (swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.some((route) => route.id === currentRoute.id))) {
45
46
  setExecutableRoute(currentRoute);
46
- navigate(routes.swap, { state: { routeId: currentRoute.id } });
47
+ navigate(routes.swap, {
48
+ state: { routeId: currentRoute.id },
49
+ });
47
50
  }
48
51
  });
49
52
  const getButtonText = () => {
@@ -4,7 +4,7 @@ import { AvatarGroup, Box, Stack } from '@mui/material';
4
4
  import { useCallback } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { useNavigate } from 'react-router-dom';
7
- import { useExecutingRoutes } from '../../hooks';
7
+ import { useExecutingRoutes } from '../../stores';
8
8
  import { routes } from '../../utils/routes';
9
9
  import { CardTitle } from '../Card';
10
10
  import { Card, RouteAvatar, RouteCard } from './SwapInProgress.style';
@@ -5,7 +5,8 @@ import { Box, IconButton, Skeleton } from '@mui/material';
5
5
  import { useCallback } from 'react';
6
6
  import { useTranslation } from 'react-i18next';
7
7
  import { useNavigate } from 'react-router-dom';
8
- import { useCurrentRoute, useSwapRoutes } from '../../hooks';
8
+ import { useSwapRoutes } from '../../hooks';
9
+ import { useCurrentRoute } from '../../stores';
9
10
  import { routes } from '../../utils/routes';
10
11
  import { CardContainer, CardTitle } from '../Card';
11
12
  import { SwapRouteCard } from '../SwapRouteCard';
@@ -11,7 +11,7 @@ export const TextFitter = ({ children, width = '100%', height, maxHeight, preser
11
11
  const theme = useTheme();
12
12
  const textRef = useRef(null);
13
13
  const [viewBox, setViewBox] = useState(initialState);
14
- const [textRect, setTextRect] = useState(initialState);
14
+ // const [textRect, setTextRect] = useState<Partial<DOMRect>>(initialState);
15
15
  const calculateBox = useCallback(() => {
16
16
  if (!textRef.current) {
17
17
  return;
@@ -25,7 +25,7 @@ export const TextFitter = ({ children, width = '100%', height, maxHeight, preser
25
25
  box.height -= box.height * cropBottom;
26
26
  }
27
27
  setViewBox(box);
28
- setTextRect(textRef.current.getBoundingClientRect());
28
+ // setTextRect(textRef.current.getBoundingClientRect());
29
29
  onFit === null || onFit === void 0 ? void 0 : onFit();
30
30
  }, [cropBottom, cropTop, onFit]);
31
31
  useLayoutEffect(() => {
@@ -38,7 +38,11 @@ export const TextFitter = ({ children, width = '100%', height, maxHeight, preser
38
38
  });
39
39
  }
40
40
  }, [calculateBox]);
41
- return (_jsx("svg", Object.assign({ style: svgStyle, viewBox: `${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}`, width: width, height: textRect.height && maxHeight && textRect.height >= maxHeight
42
- ? maxHeight
43
- : height, preserveAspectRatio: preserveAspectRatio, fill: theme.palette.text.primary }, { children: _jsx("text", Object.assign({ x: 0, y: 0, style: textStyle, ref: textRef }, { children: children })) })));
41
+ return (_jsx("svg", Object.assign({ style: svgStyle, viewBox: `${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}`, width: width, height: height,
42
+ // height={
43
+ // textRect.height && maxHeight && textRect.height >= maxHeight
44
+ // ? maxHeight
45
+ // : height
46
+ // }
47
+ preserveAspectRatio: preserveAspectRatio, fill: theme.palette.text.primary }, { children: _jsx("text", Object.assign({ x: 0, y: 0, style: textStyle, ref: textRef }, { children: children })) })));
44
48
  };
package/hooks/index.d.ts CHANGED
@@ -1,15 +1,13 @@
1
- export * from './useBridges';
2
1
  export * from './useChain';
3
2
  export * from './useChains';
4
3
  export * from './useContentHeight';
5
4
  export * from './useDebouncedWatch';
6
- export * from './useExchanges';
7
5
  export * from './useHasSufficientBalance';
8
6
  export * from './useRouteExecution';
9
7
  export * from './useScrollableContainer';
10
- export * from './useSettings';
11
8
  export * from './useSwapRoutes';
12
9
  export * from './useToken';
13
10
  export * from './useTokenBalance';
14
11
  export * from './useTokenBalances';
15
12
  export * from './useTokens';
13
+ export * from './useTools';
package/hooks/index.js CHANGED
@@ -1,15 +1,13 @@
1
- export * from './useBridges';
2
1
  export * from './useChain';
3
2
  export * from './useChains';
4
3
  export * from './useContentHeight';
5
4
  export * from './useDebouncedWatch';
6
- export * from './useExchanges';
7
5
  export * from './useHasSufficientBalance';
8
6
  export * from './useRouteExecution';
9
7
  export * from './useScrollableContainer';
10
- export * from './useSettings';
11
8
  export * from './useSwapRoutes';
12
9
  export * from './useToken';
13
10
  export * from './useTokenBalance';
14
11
  export * from './useTokenBalances';
15
12
  export * from './useTokens';
13
+ export * from './useTools';
@@ -3,7 +3,7 @@ import Big from 'big.js';
3
3
  import { useMemo } from 'react';
4
4
  import { useWatch } from 'react-hook-form';
5
5
  import { SwapFormKeyHelper } from '../providers/SwapFormProvider';
6
- import { useCurrentRoute } from './useRouteExecution';
6
+ import { useCurrentRoute } from '../stores';
7
7
  import { useTokenBalances } from './useTokenBalances';
8
8
  export const useHasSufficientBalance = () => {
9
9
  var _a;
@@ -0,0 +1 @@
1
+ export declare const useInitializer: () => void;
@@ -0,0 +1,5 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ import { useTools } from './useTools';
3
+ export const useInitializer = () => {
4
+ useTools();
5
+ };
@@ -4,5 +4,5 @@ export declare const useRouteExecution: (routeId: string) => {
4
4
  restartRoute: () => void;
5
5
  removeRoute: () => void;
6
6
  route: Route;
7
- status: import("./types").RouteExecutionStatus;
7
+ status: import("../stores").RouteExecutionStatus;
8
8
  };
@@ -10,13 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { useCallback, useEffect } from 'react';
11
11
  import { useMutation } from 'react-query';
12
12
  import shallow from 'zustand/shallow';
13
- import { LiFi } from '../../lifi';
14
- import { useWallet } from '../../providers/WalletProvider';
15
- import { deepClone } from '../../utils/deepClone';
16
- import { useRouteStore } from './useRouteStore';
13
+ import { LiFi } from '../lifi';
14
+ import { useWallet } from '../providers/WalletProvider';
15
+ import { useRouteStore } from '../stores';
16
+ import { deepClone } from '../utils/deepClone';
17
17
  export const useRouteExecution = (routeId) => {
18
18
  const { account, switchChain } = useWallet();
19
- const { route, status } = useRouteStore((state) => state.routes[routeId]);
19
+ const { route, status } = useRouteStore((state) => { var _a; return (_a = state.routes[routeId]) !== null && _a !== void 0 ? _a : {}; });
20
20
  const [updateRoute, restartRoute, removeRoute] = useRouteStore((state) => [state.updateRoute, state.restartRoute, state.removeRoute], shallow);
21
21
  const updateCallback = (updatedRoute) => {
22
22
  console.log('Route updated.', updatedRoute);
@@ -14,23 +14,25 @@ import { useDebouncedWatch, useToken } from '.';
14
14
  import { LiFi } from '../lifi';
15
15
  import { SwapFormKey } from '../providers/SwapFormProvider';
16
16
  import { useWallet } from '../providers/WalletProvider';
17
- import { useCurrentRoute } from './useRouteExecution';
17
+ import { useCurrentRoute, useSettings } from '../stores';
18
18
  const refetchTime = 60000;
19
19
  export const useSwapRoutes = () => {
20
20
  var _a;
21
21
  const { account } = useWallet();
22
22
  const queryClient = useQueryClient();
23
23
  const [currentRoute, setCurrentRoute] = useCurrentRoute();
24
- const [fromChainId, fromTokenAddress, toChainId, toTokenAddress, slippage, enabledBridges, enabledExchanges, routePriority,] = useWatch({
24
+ const { slippage, enabledBridges, enabledExchanges, routePriority } = useSettings([
25
+ 'slippage',
26
+ 'routePriority',
27
+ 'enabledBridges',
28
+ 'enabledExchanges',
29
+ ]);
30
+ const [fromChainId, fromTokenAddress, toChainId, toTokenAddress] = useWatch({
25
31
  name: [
26
32
  SwapFormKey.FromChain,
27
33
  SwapFormKey.FromToken,
28
34
  SwapFormKey.ToChain,
29
35
  SwapFormKey.ToToken,
30
- SwapFormKey.Slippage,
31
- SwapFormKey.EnabledBridges,
32
- SwapFormKey.EnabledExchanges,
33
- SwapFormKey.RoutePriority,
34
36
  ],
35
37
  });
36
38
  const [fromTokenAmount] = useDebouncedWatch([SwapFormKey.FromAmount], 500);
@@ -42,7 +44,7 @@ export const useSwapRoutes = () => {
42
44
  Boolean(toTokenAddress) &&
43
45
  Boolean(fromTokenAmount) &&
44
46
  !isNaN(fromTokenAmount) &&
45
- !isNaN(slippage);
47
+ !Number.isNaN(slippage);
46
48
  const queryKey = [
47
49
  'routes',
48
50
  account.address,
@@ -0,0 +1 @@
1
+ export declare const useTools: () => import("@lifinance/types").ToolsResponse | undefined;
@@ -0,0 +1,14 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ import { useQuery } from 'react-query';
3
+ import { LiFi } from '../lifi';
4
+ import { useSettingsStore } from '../stores';
5
+ export const useTools = () => {
6
+ const initializeTools = useSettingsStore((state) => state.initializeTools);
7
+ const { data } = useQuery(['tools'], ({ signal }) => LiFi.getTools(undefined, { signal }), {
8
+ onSuccess(data) {
9
+ initializeTools('Bridges', data.bridges.map((bridge) => bridge.key));
10
+ initializeTools('Exchanges', data.exchanges.map((exchange) => exchange.key));
11
+ },
12
+ });
13
+ return data;
14
+ };
@@ -37,7 +37,6 @@
37
37
  "approximateCurrency": "\u2248 {{value, currency(currency: USD)}}",
38
38
  "currency": "{{value, currency(currency: USD)}}",
39
39
  "sendToRecipient": "Send to recipient",
40
- "recipientsAddress": "Recipient's {{chain}} address",
41
40
  "addressConfirmation": "I confirm that the address above is correct",
42
41
  "gas": "gas fee",
43
42
  "minutes": "minutes",
@@ -126,7 +125,6 @@
126
125
  "fast": "Fast"
127
126
  },
128
127
  "advancedPreferences": "Advanced preferences",
129
- "bridgePrioritization": "Bridge prioritization",
130
128
  "enabledBridges": "Enabled bridges",
131
129
  "selectEnabledBridges": "Select enabled bridges",
132
130
  "enabledExchanges": "Enabled exchanges",
package/i18n/index.d.ts CHANGED
@@ -40,7 +40,6 @@ export declare const resources: {
40
40
  approximateCurrency: string;
41
41
  currency: string;
42
42
  sendToRecipient: string;
43
- recipientsAddress: string;
44
43
  addressConfirmation: string;
45
44
  gas: string;
46
45
  minutes: string;
@@ -129,7 +128,6 @@ export declare const resources: {
129
128
  fast: string;
130
129
  };
131
130
  advancedPreferences: string;
132
- bridgePrioritization: string;
133
131
  enabledBridges: string;
134
132
  selectEnabledBridges: string;
135
133
  enabledExchanges: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/widget",
3
- "version": "1.1.3",
3
+ "version": "1.2.0",
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",
@@ -37,8 +37,8 @@
37
37
  "lifi"
38
38
  ],
39
39
  "dependencies": {
40
- "@emotion/react": "^11.9.0",
41
- "@emotion/styled": "^11.8.1",
40
+ "@emotion/react": "^11.9.3",
41
+ "@emotion/styled": "^11.9.3",
42
42
  "@ethersproject/experimental": "^5.6.2",
43
43
  "@ethersproject/providers": "^5.6.8",
44
44
  "@lifi/wallet-management": "^1.0.2",
@@ -51,8 +51,8 @@
51
51
  "immer": "^9.0.14",
52
52
  "react": "^18.1.0",
53
53
  "react-dom": "^18.1.0",
54
- "react-hook-form": "^7.31.3",
55
- "react-i18next": "^11.16.10",
54
+ "react-hook-form": "^7.32.0",
55
+ "react-i18next": "^11.17.1",
56
56
  "react-query": "^4.0.0-beta.23",
57
57
  "react-resize-detector": "^7.1.1",
58
58
  "react-router-dom": "^6.3.0",
@@ -1,19 +1,20 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box, Typography } from '@mui/material';
3
- import { useState } from 'react';
4
3
  import { useTranslation } from 'react-i18next';
5
4
  import { Switch } from '../../components/Switch';
5
+ import { useSetSettings, useSettings } from '../../stores';
6
6
  import { EnabledBridgesSelect } from './EnabledBridgesSelect';
7
7
  import { EnabledExchangesSelect } from './EnabledExchangesSelect';
8
8
  export const AdvancedPreferences = () => {
9
9
  const { t } = useTranslation();
10
- const [advancedPreferences, setAdvancedPreferences] = useState(false);
10
+ const [setValue] = useSetSettings();
11
+ const { advancedPreferences } = useSettings(['advancedPreferences']);
11
12
  const handleAdvancedPreferences = (_, checked) => {
12
- setAdvancedPreferences(checked);
13
+ setValue('advancedPreferences', checked);
13
14
  };
14
15
  return (_jsxs(Box, Object.assign({ p: 3 }, { children: [_jsxs(Box, Object.assign({ sx: {
15
16
  display: 'flex',
16
17
  justifyContent: 'space-between',
17
18
  alignItems: 'center',
18
- } }, { children: [_jsx(Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: _jsx(Typography, Object.assign({ variant: "subtitle1", color: "text.primary", lineHeight: "normal" }, { children: t(`settings.advancedPreferences`) })) })), _jsx(Switch, { value: advancedPreferences, onChange: handleAdvancedPreferences })] })), advancedPreferences && (_jsxs(Box, Object.assign({ mt: 3, mb: 1 }, { children: [_jsx(EnabledBridgesSelect, {}), _jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(EnabledExchangesSelect, {}) }))] })))] })));
19
+ } }, { children: [_jsx(Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: _jsx(Typography, Object.assign({ variant: "subtitle1", color: "text.primary", lineHeight: "normal" }, { children: t(`settings.advancedPreferences`) })) })), _jsx(Switch, { checked: advancedPreferences, onChange: handleAdvancedPreferences })] })), advancedPreferences && (_jsxs(Box, Object.assign({ mt: 3, mb: 1 }, { children: [_jsx(EnabledBridgesSelect, {}), _jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(EnabledExchangesSelect, {}) }))] })))] })));
19
20
  };
@@ -2,8 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Brightness4 as Brightness4Icon, DarkMode as DarkModeIcon, LightMode as LightModeIcon, } from '@mui/icons-material';
3
3
  import { Box, ToggleButtonGroup } from '@mui/material';
4
4
  import { useTranslation } from 'react-i18next';
5
- import { useAppearance } from '../../hooks';
6
5
  import { useWidgetConfig } from '../../providers/WidgetProvider';
6
+ import { useAppearance } from '../../stores';
7
7
  import { ToggleButton } from './ColorSchemeButtonGroup.style';
8
8
  export const ColorSchemeButtonGroup = () => {
9
9
  const { t } = useTranslation();
@@ -1,15 +1,20 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@mui/icons-material';
3
3
  import { Box, Chip, FormControl, MenuItem, Skeleton } from '@mui/material';
4
- import { useFormContext } from 'react-hook-form';
5
4
  import { useTranslation } from 'react-i18next';
5
+ import shallow from 'zustand/shallow';
6
6
  import { CardContainer, CardTitle } from '../../components/Card';
7
7
  import { Select } from '../../components/Select';
8
- import { useBridges } from '../../hooks';
9
- import { SwapFormKey } from '../../providers/SwapFormProvider';
8
+ import { useTools } from '../../hooks';
9
+ import { useSettingsStore } from '../../stores';
10
10
  export const EnabledBridgesSelect = () => {
11
+ var _a;
11
12
  const { t } = useTranslation();
12
- const { register } = useFormContext();
13
- const bridges = useBridges();
14
- return bridges.length ? (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.enabledBridges`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ multiple: true, placeholder: t(`settings.selectEnabledBridges`), defaultValue: bridges, MenuProps: { elevation: 2 }, IconComponent: KeyboardArrowDownIcon, inputProps: Object.assign({}, register(SwapFormKey.EnabledBridges)), renderValue: (selected) => (_jsx(Box, Object.assign({ sx: { display: 'flex', flexWrap: 'wrap', gap: 0.5 } }, { children: selected.map((value) => (_jsx(Chip, { label: value }, value))) }))) }, { children: bridges.map((bridge) => (_jsx(MenuItem, Object.assign({ value: bridge }, { children: bridge }), bridge))) })) }))] })) : (_jsx(Skeleton, { variant: "rectangular", width: "100%", height: 134, sx: { borderRadius: 1 } }));
13
+ const tools = useTools();
14
+ const [enabledBridges, setTools] = useSettingsStore((state) => [state.enabledBridges, state.setTools], shallow);
15
+ return (tools === null || tools === void 0 ? void 0 : tools.bridges.length) ? (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.enabledBridges`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ multiple: true, placeholder: t(`settings.selectEnabledBridges`), MenuProps: { elevation: 2 }, IconComponent: KeyboardArrowDownIcon, value: enabledBridges !== null && enabledBridges !== void 0 ? enabledBridges : [], onChange: (event) => {
16
+ if (tools === null || tools === void 0 ? void 0 : tools.bridges) {
17
+ setTools('Bridges', event.target.value, tools.bridges);
18
+ }
19
+ }, renderValue: (selected) => (_jsx(Box, Object.assign({ sx: { display: 'flex', flexWrap: 'wrap', gap: 0.5 } }, { children: selected.map((value) => (_jsx(Chip, { label: value }, value))) }))) }, { children: (_a = tools === null || tools === void 0 ? void 0 : tools.bridges) === null || _a === void 0 ? void 0 : _a.map((bridge) => (_jsx(MenuItem, Object.assign({ value: bridge.key }, { children: bridge.key }), bridge.key))) })) }))] })) : (_jsx(Skeleton, { variant: "rectangular", width: "100%", height: 134, sx: { borderRadius: 1 } }));
15
20
  };
@@ -1,15 +1,19 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@mui/icons-material';
3
3
  import { Box, Chip, FormControl, MenuItem, Skeleton } from '@mui/material';
4
- import { useFormContext } from 'react-hook-form';
5
4
  import { useTranslation } from 'react-i18next';
5
+ import shallow from 'zustand/shallow';
6
6
  import { CardContainer, CardTitle } from '../../components/Card';
7
7
  import { Select } from '../../components/Select';
8
- import { useExchanges } from '../../hooks';
9
- import { SwapFormKey } from '../../providers/SwapFormProvider';
8
+ import { useTools } from '../../hooks';
9
+ import { useSettingsStore } from '../../stores';
10
10
  export const EnabledExchangesSelect = () => {
11
11
  const { t } = useTranslation();
12
- const { register } = useFormContext();
13
- const exchanges = useExchanges();
14
- return exchanges.length ? (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.enabledExchanges`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ multiple: true, placeholder: t(`settings.selectEnabledExchanges`), defaultValue: exchanges, MenuProps: { elevation: 2 }, IconComponent: KeyboardArrowDownIcon, inputProps: Object.assign({}, register(SwapFormKey.EnabledExchanges)), renderValue: (selected) => (_jsx(Box, Object.assign({ sx: { display: 'flex', flexWrap: 'wrap', gap: 0.5 } }, { children: selected.map((value) => (_jsx(Chip, { label: value }, value))) }))) }, { children: exchanges.map((exchange) => (_jsx(MenuItem, Object.assign({ value: exchange }, { children: exchange }), exchange))) })) }))] })) : (_jsx(Skeleton, { variant: "rectangular", width: "100%", height: 206, sx: { borderRadius: 1 } }));
12
+ const tools = useTools();
13
+ const [enabledExchanges, setTools] = useSettingsStore((state) => [state.enabledExchanges, state.setTools], shallow);
14
+ return (tools === null || tools === void 0 ? void 0 : tools.exchanges.length) ? (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.enabledExchanges`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ multiple: true, placeholder: t(`settings.selectEnabledExchanges`), value: enabledExchanges !== null && enabledExchanges !== void 0 ? enabledExchanges : [], onChange: (event) => {
15
+ if (tools === null || tools === void 0 ? void 0 : tools.exchanges) {
16
+ setTools('Exchanges', event.target.value, tools.exchanges);
17
+ }
18
+ }, MenuProps: { elevation: 2 }, IconComponent: KeyboardArrowDownIcon, renderValue: (selected) => (_jsx(Box, Object.assign({ sx: { display: 'flex', flexWrap: 'wrap', gap: 0.5 } }, { children: selected.map((value) => (_jsx(Chip, { label: value }, value))) }))) }, { children: tools === null || tools === void 0 ? void 0 : tools.exchanges.map((exchange) => (_jsx(MenuItem, Object.assign({ value: exchange.key }, { children: exchange.key }), exchange.key))) })) }))] })) : (_jsx(Skeleton, { variant: "rectangular", width: "100%", height: 206, sx: { borderRadius: 1 } }));
15
19
  };
@@ -1,13 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@mui/icons-material';
3
3
  import { FormControl, MenuItem } from '@mui/material';
4
- import { useFormContext } from 'react-hook-form';
5
4
  import { useTranslation } from 'react-i18next';
6
5
  import { CardContainer, CardTitle } from '../../components/Card';
7
6
  import { Select } from '../../components/Select';
8
- import { formDefaultValues, SwapFormKey, } from '../../providers/SwapFormProvider';
7
+ import { useSetSettings, useSettings } from '../../stores';
9
8
  export const GasPriceSelect = () => {
10
9
  const { t } = useTranslation();
11
- const { register } = useFormContext();
12
- return (_jsxs(CardContainer, Object.assign({ flex: 1 }, { children: [_jsx(CardTitle, { children: t(`settings.gasPrice.title`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsxs(Select, Object.assign({ defaultValue: formDefaultValues.gasPrice, MenuProps: { elevation: 2 }, inputProps: Object.assign({}, register(SwapFormKey.GasPrice)), IconComponent: KeyboardArrowDownIcon, dense: true }, { children: [_jsx(MenuItem, Object.assign({ value: "slow" }, { children: t(`settings.gasPrice.slow`) })), _jsx(MenuItem, Object.assign({ value: "normal" }, { children: t(`settings.gasPrice.normal`) })), _jsx(MenuItem, Object.assign({ value: "fast" }, { children: t(`settings.gasPrice.fast`) }))] })) }))] })));
10
+ const [setValue] = useSetSettings();
11
+ const { gasPrice } = useSettings(['gasPrice']);
12
+ return (_jsxs(CardContainer, Object.assign({ flex: 1 }, { children: [_jsx(CardTitle, { children: t(`settings.gasPrice.title`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsxs(Select, Object.assign({ MenuProps: { elevation: 2 }, value: gasPrice, onChange: (event) => setValue('gasPrice', event.target.value), IconComponent: KeyboardArrowDownIcon, dense: true }, { children: [_jsx(MenuItem, Object.assign({ value: "slow" }, { children: t(`settings.gasPrice.slow`) })), _jsx(MenuItem, Object.assign({ value: "normal" }, { children: t(`settings.gasPrice.normal`) })), _jsx(MenuItem, Object.assign({ value: "fast" }, { children: t(`settings.gasPrice.fast`) }))] })) }))] })));
13
13
  };
@@ -2,13 +2,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Orders } from '@lifinance/sdk';
3
3
  import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@mui/icons-material';
4
4
  import { FormControl, MenuItem } from '@mui/material';
5
- import { useFormContext } from 'react-hook-form';
6
5
  import { useTranslation } from 'react-i18next';
7
6
  import { CardContainer, CardTitle } from '../../components/Card';
8
7
  import { Select } from '../../components/Select';
9
- import { formDefaultValues, SwapFormKey, } from '../../providers/SwapFormProvider';
8
+ import { useSetSettings, useSettings } from '../../stores';
10
9
  export const RoutePrioritySelect = () => {
11
10
  const { t } = useTranslation();
12
- const { register } = useFormContext();
13
- return (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.routePriority`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ defaultValue: formDefaultValues.routePriority, MenuProps: { elevation: 2 }, inputProps: Object.assign({}, register(SwapFormKey.RoutePriority)), IconComponent: KeyboardArrowDownIcon, dense: true }, { children: Orders.map((order) => (_jsx(MenuItem, Object.assign({ value: order }, { children: t(`swap.tags.${order.toLowerCase()}`) }), order))) })) }))] }));
11
+ const [setValue] = useSetSettings();
12
+ const { routePriority } = useSettings(['routePriority']);
13
+ return (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.routePriority`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Select, Object.assign({ MenuProps: { elevation: 2 }, value: routePriority, onChange: (event) => setValue('routePriority', event.target.value), IconComponent: KeyboardArrowDownIcon, dense: true }, { children: Orders.map((order) => (_jsx(MenuItem, Object.assign({ value: order }, { children: t(`swap.tags.${order.toLowerCase()}`) }), order))) })) }))] }));
14
14
  };
@@ -1,28 +1,25 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { FormControl, InputAdornment } from '@mui/material';
3
3
  import { useRef } from 'react';
4
- import { useFormContext, useWatch } from 'react-hook-form';
5
4
  import { useTranslation } from 'react-i18next';
6
5
  import { CardContainer, CardTitle } from '../../components/Card';
7
6
  import { Input } from '../../components/Input';
8
- import { SwapFormKey } from '../../providers/SwapFormProvider';
7
+ import { useSetSettings, useSettings } from '../../stores';
9
8
  import { formatSlippage } from '../../utils/format';
10
9
  export const SlippageInput = () => {
11
10
  const { t } = useTranslation();
12
- const { setValue } = useFormContext();
13
- const value = useWatch({
14
- name: SwapFormKey.Slippage,
15
- });
16
- const defaultValue = useRef(value);
11
+ const [setValue] = useSetSettings();
12
+ const { slippage } = useSettings(['slippage']);
13
+ const defaultValue = useRef(slippage);
17
14
  const handleChange = (event) => {
18
15
  const { value } = event.target;
19
- setValue(SwapFormKey.Slippage, formatSlippage(value, defaultValue.current, true));
16
+ setValue('slippage', formatSlippage(value, defaultValue.current, true));
20
17
  };
21
18
  const handleBlur = (event) => {
22
19
  const { value } = event.target;
23
- setValue(SwapFormKey.Slippage, formatSlippage(value, defaultValue.current));
20
+ setValue('slippage', formatSlippage(value, defaultValue.current));
24
21
  };
25
22
  return (_jsxs(CardContainer, { children: [_jsx(CardTitle, { children: t(`settings.slippage`) }), _jsx(FormControl, Object.assign({ fullWidth: true }, { children: _jsx(Input, { size: "small", placeholder: t(`settings.slippage`), endAdornment: _jsx(InputAdornment, Object.assign({ position: "end" }, { children: "%" })), autoComplete: "off", inputProps: {
26
23
  inputMode: 'decimal',
27
- }, onChange: handleChange, onBlur: handleBlur, value: value, name: SwapFormKey.Slippage }) }))] }));
24
+ }, onChange: handleChange, onBlur: handleBlur, value: slippage }) }))] }));
28
25
  };
@@ -13,7 +13,7 @@ export const ExecutionItem = ({ step, process }) => {
13
13
  return (_jsxs(Box, Object.assign({ px: 2, py: 1 }, { children: [_jsxs(Box, Object.assign({ sx: {
14
14
  display: 'flex',
15
15
  alignItems: 'center',
16
- } }, { children: [_jsx(CircularProgress, { status: process.status }), _jsx(Typography, Object.assign({ ml: 2, fontWeight: process.error ? 700 : 500 }, { children: title })), process.txLink ? (_jsx(Box, Object.assign({ ml: 2, sx: {
16
+ } }, { children: [_jsx(CircularProgress, { status: process.status }), _jsx(Typography, Object.assign({ ml: 2, fontSize: 14, fontWeight: process.error ? 600 : 400 }, { children: title })), process.txLink ? (_jsx(Box, Object.assign({ ml: 2, sx: {
17
17
  display: 'flex',
18
18
  flex: 1,
19
19
  justifyContent: 'flex-end',
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
- import { RouteExecution } from '../../hooks';
2
+ import { RouteExecution } from '../../stores';
3
3
  export declare const StatusBottomSheet: React.FC<RouteExecution>;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Theme } from '@mui/material';
3
- import { RouteExecutionStatus } from '../../hooks';
3
+ import { RouteExecutionStatus } from '../../stores';
4
4
  export declare const IconContainer: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<Theme> & {
5
5
  children?: import("react").ReactNode;
6
6
  component?: import("react").ElementType<any> | undefined;
@@ -25,5 +25,5 @@ export const StepItem = ({ step, fromToken, toToken }) => {
25
25
  return (_jsxs(CardContainer, Object.assign({ isError: stepHasError }, { children: [_jsxs(Box, Object.assign({ sx: {
26
26
  display: 'flex',
27
27
  flex: 1,
28
- } }, { children: [_jsx(CardTitle, Object.assign({ flex: 1 }, { children: getCardTitle() })), _jsx(CardTitle, { children: _jsx(StepTimer, { step: step }) })] })), _jsxs(Box, Object.assign({ py: 1 }, { children: [fromToken ? _jsx(StepToken, { token: fromToken, px: 2, py: 1 }) : null, _jsx(StepActions, { step: step, px: 2, py: 1, dense: true }), (_b = step.execution) === null || _b === void 0 ? void 0 : _b.process.map((process, index) => (_jsx(ExecutionItem, { step: step, process: process }, index))), toToken ? _jsx(StepToken, { token: toToken, px: 2, py: 1 }) : null] }))] })));
28
+ } }, { children: [_jsx(CardTitle, Object.assign({ flex: 1 }, { children: getCardTitle() })), _jsx(CardTitle, Object.assign({ sx: { fontWeight: 500 } }, { children: _jsx(StepTimer, { step: step }) }))] })), _jsxs(Box, Object.assign({ py: 1 }, { children: [fromToken ? _jsx(StepToken, { token: fromToken, px: 2, py: 1 }) : null, _jsx(StepActions, { step: step, px: 2, py: 1, dense: true }), (_b = step.execution) === null || _b === void 0 ? void 0 : _b.process.map((process, index) => (_jsx(ExecutionItem, { step: step, process: process }, index))), toToken ? _jsx(StepToken, { token: toToken, px: 2, py: 1 }) : null] }))] })));
29
29
  };
@@ -8,7 +8,7 @@ const getExpiryTimestamp = (step) => {
8
8
  step.estimate.executionDuration * 1000);
9
9
  };
10
10
  export const StepTimer = ({ step }) => {
11
- var _a;
11
+ var _a, _b;
12
12
  const { t } = useTranslation();
13
13
  const [isExpired, setExpired] = useState(false);
14
14
  const [isExecutionStarted, setExecutionStarted] = useState(!!step.execution);
@@ -50,7 +50,8 @@ export const StepTimer = ({ step }) => {
50
50
  value: (step.estimate.executionDuration / 60).toFixed(0),
51
51
  }) }));
52
52
  }
53
- if (((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE') {
53
+ if (((_a = step.execution) === null || _a === void 0 ? void 0 : _a.status) === 'DONE' ||
54
+ ((_b = step.execution) === null || _b === void 0 ? void 0 : _b.status) === 'FAILED') {
54
55
  return null;
55
56
  }
56
57
  return isExpired ? (_jsx(_Fragment, { children: t('swap.networkIsBusy') })) : (
@@ -2,7 +2,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Skeleton } from '@mui/material';
3
3
  import { useNavigate } from 'react-router-dom';
4
4
  import { SwapRouteCard } from '../../components/SwapRouteCard';
5
- import { useCurrentRoute, useSetExecutableRoute, useSwapRoutes, } from '../../hooks';
5
+ import { useSwapRoutes } from '../../hooks';
6
+ import { useCurrentRoute, useSetExecutableRoute } from '../../stores';
6
7
  import { routes } from '../../utils/routes';
7
8
  import { Stack } from './SwapRoutesPage.style';
8
9
  export const SwapRoutesPage = () => {
@@ -1,9 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  export declare const formDefaultValues: {
3
3
  fromAmount: string;
4
- gasPrice: string;
5
- slippage: string;
6
4
  searchTokensFilter: string;
7
- routePriority: "RECOMMENDED" | "FASTEST" | "CHEAPEST" | "SAFEST";
8
5
  };
9
6
  export declare const SwapFormProvider: React.FC<React.PropsWithChildren<{}>>;
@@ -4,10 +4,7 @@ import { useWidgetConfig } from '../WidgetProvider';
4
4
  import { SwapFormKey } from './types';
5
5
  export const formDefaultValues = {
6
6
  [SwapFormKey.FromAmount]: '',
7
- [SwapFormKey.GasPrice]: 'normal',
8
- [SwapFormKey.Slippage]: '3',
9
7
  [SwapFormKey.SearchTokensFilter]: '',
10
- [SwapFormKey.RoutePriority]: 'RECOMMENDED',
11
8
  };
12
9
  export const SwapFormProvider = ({ children, }) => {
13
10
  var _a;