@lifi/widget 1.17.1 → 1.18.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 (210) hide show
  1. package/App.js +6 -86
  2. package/AppDrawer.js +3 -2
  3. package/AppRoutes.d.ts +2 -0
  4. package/AppRoutes.js +85 -0
  5. package/cjs/App.js +5 -85
  6. package/cjs/AppDrawer.js +2 -1
  7. package/cjs/AppRoutes.d.ts +2 -0
  8. package/cjs/AppRoutes.js +89 -0
  9. package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +1 -0
  10. package/cjs/components/AppContainer.d.ts +4 -5
  11. package/cjs/components/AppContainer.js +30 -29
  12. package/cjs/components/Card/Card.d.ts +1 -0
  13. package/cjs/components/Card/Card.js +13 -9
  14. package/cjs/components/ChainSelect/ChainSelect.js +3 -3
  15. package/cjs/components/ChainSelect/ChainSelect.style.d.ts +1 -0
  16. package/cjs/components/ChainSelect/ChainSelect.style.js +2 -2
  17. package/cjs/components/ChainSelect/useChainSelect.js +2 -2
  18. package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.js +6 -2
  19. package/cjs/components/Header/Header.d.ts +2 -1
  20. package/cjs/components/Header/Header.js +3 -2
  21. package/cjs/components/Header/Header.style.js +3 -2
  22. package/cjs/components/Header/NavigationHeader.js +4 -1
  23. package/cjs/components/Header/WalletHeader.js +1 -1
  24. package/cjs/components/Header/useHeaderActionStore.js +1 -4
  25. package/cjs/components/PoweredBy/PoweredBy.js +7 -0
  26. package/cjs/components/SendToWallet/SendToWallet.js +6 -10
  27. package/cjs/components/SendToWallet/SendToWalletButton.d.ts +2 -0
  28. package/cjs/components/SendToWallet/SendToWalletButton.js +24 -0
  29. package/cjs/components/SendToWallet/index.d.ts +1 -0
  30. package/cjs/components/SendToWallet/index.js +1 -0
  31. package/cjs/components/SendToWallet/store.d.ts +4 -0
  32. package/cjs/components/SendToWallet/store.js +13 -0
  33. package/cjs/components/SendToWallet/types.d.ts +6 -0
  34. package/cjs/{stores/route → components/SendToWallet}/types.js +0 -0
  35. package/cjs/components/StepActions/StepActions.style.js +1 -1
  36. package/cjs/components/SwapButton/SwapButton.d.ts +1 -1
  37. package/cjs/components/SwapButton/SwapButton.js +4 -4
  38. package/cjs/components/SwapRouteCard/SwapRouteCard.d.ts +2 -1
  39. package/cjs/components/SwapRouteCard/SwapRouteCard.js +19 -15
  40. package/cjs/components/SwapRouteCard/SwapRouteCard.style.d.ts +30 -0
  41. package/cjs/components/SwapRouteCard/SwapRouteCard.style.js +16 -3
  42. package/cjs/components/SwapRouteCard/SwapRouteCardSkeleton.js +2 -12
  43. package/cjs/components/SwapRouteCard/SwapRouteNotFoundCard.d.ts +1 -3
  44. package/cjs/components/SwapRouteCard/SwapRouteNotFoundCard.js +1 -13
  45. package/cjs/components/SwapRouteCard/types.d.ts +6 -2
  46. package/cjs/{pages/MainPage → components/SwapRoutes}/SwapRoutes.d.ts +0 -0
  47. package/cjs/components/SwapRoutes/SwapRoutes.js +51 -0
  48. package/cjs/components/SwapRoutes/SwapRoutes.style.d.ts +43 -0
  49. package/cjs/components/SwapRoutes/SwapRoutes.style.js +47 -0
  50. package/cjs/components/SwapRoutes/SwapRoutesExpanded.d.ts +2 -0
  51. package/cjs/components/SwapRoutes/SwapRoutesExpanded.js +38 -0
  52. package/cjs/components/SwapRoutes/index.d.ts +2 -0
  53. package/cjs/components/SwapRoutes/index.js +18 -0
  54. package/cjs/components/Token/Token.d.ts +2 -1
  55. package/cjs/components/Token/Token.js +10 -6
  56. package/cjs/components/Token/Token.style.js +2 -0
  57. package/cjs/components/TokenList/TokenList.js +4 -1
  58. package/cjs/config/sentry.js +3 -26
  59. package/cjs/config/theme.js +20 -24
  60. package/cjs/config/version.d.ts +1 -1
  61. package/cjs/config/version.js +1 -1
  62. package/cjs/hooks/useChains.js +2 -2
  63. package/cjs/hooks/useGasSufficiency.js +14 -37
  64. package/cjs/hooks/useNavigateBack.js +13 -6
  65. package/cjs/hooks/useRouteExecution.js +5 -8
  66. package/cjs/hooks/useSwapRoutes.js +1 -4
  67. package/cjs/hooks/useTelemetry.js +3 -2
  68. package/cjs/hooks/useTokenBalances.d.ts +1 -1
  69. package/cjs/hooks/useTokenBalances.js +3 -1
  70. package/cjs/hooks/useWidgetEvents.js +2 -5
  71. package/cjs/i18n/index.js +2 -5
  72. package/cjs/pages/ActiveSwapsPage/ActiveSwapsEmpty.js +1 -0
  73. package/cjs/pages/MainPage/MainPage.js +4 -2
  74. package/cjs/pages/MainPage/MainSwapButton.js +4 -4
  75. package/cjs/pages/SelectTokenPage/SelectTokenPage.js +4 -3
  76. package/cjs/pages/SettingsPage/EnabledBridgesSelect.js +1 -4
  77. package/cjs/pages/SettingsPage/EnabledExchangesSelect.js +1 -4
  78. package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +2 -5
  79. package/cjs/pages/SwapHistoryPage/SwapHistoryEmpty.js +1 -0
  80. package/cjs/pages/SwapHistoryPage/SwapHistoryPage.js +8 -5
  81. package/cjs/pages/SwapPage/SwapPage.js +5 -1
  82. package/cjs/pages/SwapRoutesPage/SwapRoutesPage.js +3 -5
  83. package/cjs/providers/SDKProvider/SDKProvider.js +1 -4
  84. package/cjs/providers/WalletProvider/WalletProvider.js +2 -2
  85. package/cjs/stores/chains/useChainOrder.js +1 -4
  86. package/cjs/stores/chains/useChainOrderStore.js +1 -4
  87. package/cjs/stores/index.d.ts +2 -1
  88. package/cjs/stores/index.js +2 -1
  89. package/cjs/stores/{route → routes}/index.d.ts +2 -1
  90. package/cjs/stores/{route → routes}/index.js +2 -1
  91. package/cjs/stores/{route → routes}/types.d.ts +4 -0
  92. package/cjs/stores/routes/types.js +2 -0
  93. package/cjs/stores/{route → routes}/useExecutingRoutesIds.d.ts +0 -0
  94. package/cjs/stores/{route → routes}/useExecutingRoutesIds.js +3 -6
  95. package/cjs/stores/{route/useRouteStore.d.ts → routes/useRouteExecutionStore.d.ts} +1 -1
  96. package/cjs/stores/{route/useRouteStore.js → routes/useRouteExecutionStore.js} +3 -6
  97. package/cjs/stores/routes/useSelectedRouteStore.d.ts +4 -0
  98. package/cjs/stores/routes/useSelectedRouteStore.js +12 -0
  99. package/cjs/stores/{route → routes}/useSetExecutableRoute.d.ts +0 -0
  100. package/cjs/stores/{route → routes}/useSetExecutableRoute.js +2 -2
  101. package/cjs/stores/{route → routes}/useSwapHistory.d.ts +0 -0
  102. package/cjs/stores/{route → routes}/useSwapHistory.js +3 -6
  103. package/cjs/stores/{route → routes}/utils.d.ts +0 -0
  104. package/cjs/stores/{route → routes}/utils.js +1 -4
  105. package/cjs/stores/settings/useAppearance.js +1 -4
  106. package/cjs/stores/settings/useSettings.js +1 -4
  107. package/cjs/stores/settings/useSettingsStore.js +2 -5
  108. package/cjs/types/widget.d.ts +2 -0
  109. package/cjs/utils/colors.d.ts +1 -1
  110. package/cjs/utils/format.js +1 -4
  111. package/cjs/utils/navigationRoutes.js +12 -12
  112. package/components/ActiveSwaps/ActiveSwaps.style.d.ts +1 -0
  113. package/components/AppContainer.d.ts +4 -5
  114. package/components/AppContainer.js +29 -28
  115. package/components/Card/Card.d.ts +1 -0
  116. package/components/Card/Card.js +13 -9
  117. package/components/ChainSelect/ChainSelect.js +1 -1
  118. package/components/ChainSelect/ChainSelect.style.d.ts +1 -0
  119. package/components/ChainSelect/ChainSelect.style.js +2 -2
  120. package/components/ChainSelect/useChainSelect.js +1 -1
  121. package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +6 -2
  122. package/components/Header/Header.d.ts +2 -1
  123. package/components/Header/Header.js +1 -1
  124. package/components/Header/Header.style.js +4 -3
  125. package/components/Header/NavigationHeader.js +4 -1
  126. package/components/Header/WalletHeader.js +2 -2
  127. package/components/PoweredBy/PoweredBy.js +7 -0
  128. package/components/SendToWallet/SendToWallet.js +8 -11
  129. package/components/SendToWallet/SendToWalletButton.d.ts +2 -0
  130. package/components/SendToWallet/SendToWalletButton.js +20 -0
  131. package/components/SendToWallet/index.d.ts +1 -0
  132. package/components/SendToWallet/index.js +1 -0
  133. package/components/SendToWallet/store.d.ts +4 -0
  134. package/components/SendToWallet/store.js +10 -0
  135. package/components/SendToWallet/types.d.ts +6 -0
  136. package/{stores/route → components/SendToWallet}/types.js +0 -0
  137. package/components/StepActions/StepActions.style.js +1 -1
  138. package/components/SwapButton/SwapButton.d.ts +1 -1
  139. package/components/SwapButton/SwapButton.js +4 -3
  140. package/components/SwapRouteCard/SwapRouteCard.d.ts +2 -1
  141. package/components/SwapRouteCard/SwapRouteCard.js +19 -16
  142. package/components/SwapRouteCard/SwapRouteCard.style.d.ts +30 -0
  143. package/components/SwapRouteCard/SwapRouteCard.style.js +17 -4
  144. package/components/SwapRouteCard/SwapRouteCardSkeleton.js +2 -12
  145. package/components/SwapRouteCard/SwapRouteNotFoundCard.d.ts +1 -3
  146. package/components/SwapRouteCard/SwapRouteNotFoundCard.js +1 -13
  147. package/components/SwapRouteCard/types.d.ts +6 -2
  148. package/{pages/MainPage → components/SwapRoutes}/SwapRoutes.d.ts +0 -0
  149. package/components/SwapRoutes/SwapRoutes.js +47 -0
  150. package/components/SwapRoutes/SwapRoutes.style.d.ts +43 -0
  151. package/components/SwapRoutes/SwapRoutes.style.js +44 -0
  152. package/components/SwapRoutes/SwapRoutesExpanded.d.ts +2 -0
  153. package/components/SwapRoutes/SwapRoutesExpanded.js +34 -0
  154. package/components/SwapRoutes/index.d.ts +2 -0
  155. package/components/SwapRoutes/index.js +2 -0
  156. package/components/Token/Token.d.ts +2 -1
  157. package/components/Token/Token.js +11 -7
  158. package/components/Token/Token.style.js +2 -0
  159. package/components/TokenList/TokenList.js +4 -1
  160. package/config/theme.js +20 -24
  161. package/config/version.d.ts +1 -1
  162. package/config/version.js +1 -1
  163. package/hooks/useChains.js +1 -1
  164. package/hooks/useGasSufficiency.js +15 -35
  165. package/hooks/useNavigateBack.js +13 -6
  166. package/hooks/useRouteExecution.js +5 -5
  167. package/hooks/useTelemetry.js +3 -2
  168. package/hooks/useTokenBalances.d.ts +1 -1
  169. package/hooks/useTokenBalances.js +3 -1
  170. package/package.json +14 -14
  171. package/pages/ActiveSwapsPage/ActiveSwapsEmpty.js +1 -0
  172. package/pages/MainPage/MainPage.js +4 -2
  173. package/pages/MainPage/MainSwapButton.js +4 -3
  174. package/pages/SelectTokenPage/SelectTokenPage.js +4 -3
  175. package/pages/SwapDetailsPage/SwapDetailsPage.js +2 -2
  176. package/pages/SwapHistoryPage/SwapHistoryEmpty.js +1 -0
  177. package/pages/SwapHistoryPage/SwapHistoryPage.js +8 -5
  178. package/pages/SwapPage/SwapPage.js +5 -1
  179. package/pages/SwapRoutesPage/SwapRoutesPage.js +4 -6
  180. package/providers/WalletProvider/WalletProvider.js +1 -1
  181. package/stores/index.d.ts +2 -1
  182. package/stores/index.js +2 -1
  183. package/stores/{route → routes}/index.d.ts +2 -1
  184. package/stores/{route → routes}/index.js +2 -1
  185. package/stores/{route → routes}/types.d.ts +4 -0
  186. package/stores/routes/types.js +1 -0
  187. package/stores/{route → routes}/useExecutingRoutesIds.d.ts +0 -0
  188. package/stores/{route → routes}/useExecutingRoutesIds.js +2 -2
  189. package/stores/{route/useRouteStore.d.ts → routes/useRouteExecutionStore.d.ts} +1 -1
  190. package/stores/{route/useRouteStore.js → routes/useRouteExecutionStore.js} +1 -1
  191. package/stores/routes/useSelectedRouteStore.d.ts +4 -0
  192. package/stores/routes/useSelectedRouteStore.js +9 -0
  193. package/stores/{route → routes}/useSetExecutableRoute.d.ts +0 -0
  194. package/stores/routes/useSetExecutableRoute.js +4 -0
  195. package/stores/{route → routes}/useSwapHistory.d.ts +0 -0
  196. package/stores/{route → routes}/useSwapHistory.js +2 -2
  197. package/stores/{route → routes}/utils.d.ts +0 -0
  198. package/stores/{route → routes}/utils.js +0 -0
  199. package/stores/settings/useSettingsStore.js +1 -1
  200. package/tsconfig.cjs.tsbuildinfo +1 -1
  201. package/types/widget.d.ts +2 -0
  202. package/utils/colors.d.ts +1 -1
  203. package/utils/navigationRoutes.js +12 -12
  204. package/cjs/pages/MainPage/SwapRoutes.js +0 -43
  205. package/cjs/pages/MainPage/SwapRoutes.style.d.ts +0 -11
  206. package/cjs/pages/MainPage/SwapRoutes.style.js +0 -16
  207. package/pages/MainPage/SwapRoutes.js +0 -39
  208. package/pages/MainPage/SwapRoutes.style.d.ts +0 -11
  209. package/pages/MainPage/SwapRoutes.style.js +0 -13
  210. package/stores/route/useSetExecutableRoute.js +0 -4
@@ -3,12 +3,19 @@ import { useNavigate } from 'react-router-dom';
3
3
  export const useNavigateBack = () => {
4
4
  const navigate = useNavigate();
5
5
  const navigateBack = useCallback(() => {
6
- if (window.history.state && window.history.state.idx > 0) {
7
- navigate(-1);
8
- }
9
- else {
10
- navigate(window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) || '/', { replace: true });
11
- }
6
+ // https://github.com/remix-run/react-router/pull/9112
7
+ //
8
+ // if (window.history.length > 2) {
9
+ navigate(-1);
10
+ // } else {
11
+ // navigate(
12
+ // window.location.pathname.substring(
13
+ // 0,
14
+ // window.location.pathname.lastIndexOf('/'),
15
+ // ) || '/',
16
+ // { replace: true },
17
+ // );
18
+ // }
12
19
  }, [navigate]);
13
20
  return { navigateBack, navigate };
14
21
  };
@@ -11,7 +11,7 @@ import { useMutation } from '@tanstack/react-query';
11
11
  import { useCallback, useEffect, useRef } from 'react';
12
12
  import shallow from 'zustand/shallow';
13
13
  import { useLiFi, useWallet } from '../providers';
14
- import { getUpdatedProcess, isRouteActive, isRouteCompleted, isRouteFailed, useRouteStore, } from '../stores';
14
+ import { getUpdatedProcess, isRouteActive, isRouteCompleted, isRouteFailed, useRouteExecutionStore, } from '../stores';
15
15
  import { WidgetEvent } from '../types/events';
16
16
  import { deepClone } from '../utils';
17
17
  import { useWidgetEvents } from './useWidgetEvents';
@@ -20,10 +20,10 @@ export const useRouteExecution = (routeId, executeInBackground) => {
20
20
  const { account, switchChain } = useWallet();
21
21
  const resumedAfterMount = useRef(false);
22
22
  const emitter = useWidgetEvents();
23
- const routeExecution = useRouteStore((state) => state.routes[routeId]);
24
- const [updateRoute, restartRoute, deleteRoute] = useRouteStore((state) => [state.updateRoute, state.restartRoute, state.deleteRoute], shallow);
23
+ const routeExecution = useRouteExecutionStore((state) => state.routes[routeId]);
24
+ const [updateRoute, restartRoute, deleteRoute] = useRouteExecutionStore((state) => [state.updateRoute, state.restartRoute, state.deleteRoute], shallow);
25
25
  const updateCallback = (updatedRoute) => {
26
- const routeExecution = useRouteStore.getState().routes[updatedRoute.id];
26
+ const routeExecution = useRouteExecutionStore.getState().routes[updatedRoute.id];
27
27
  if (!routeExecution) {
28
28
  return;
29
29
  }
@@ -144,7 +144,7 @@ export const useRouteExecution = (routeId, executeInBackground) => {
144
144
  useEffect(() => {
145
145
  return () => {
146
146
  var _a;
147
- const route = (_a = useRouteStore.getState().routes[routeId]) === null || _a === void 0 ? void 0 : _a.route;
147
+ const route = (_a = useRouteExecutionStore.getState().routes[routeId]) === null || _a === void 0 ? void 0 : _a.route;
148
148
  if (!route || !isRouteActive(route)) {
149
149
  return;
150
150
  }
@@ -1,11 +1,12 @@
1
1
  /* eslint-disable consistent-return */
2
2
  import { useEffect } from 'react';
3
3
  import { initSentry } from '../config/sentry';
4
+ import { name } from '../config/version';
4
5
  export const useTelemetry = (disabled) => {
5
6
  useEffect(() => {
6
7
  if (disabled) {
7
- if (process.env.NODE_ENV === 'production') {
8
- console.warn('Enable crash reports and diagnostic data to be collected. This helps us to better understand how the widget is performing and where improvements need to be made.');
8
+ if (process.env.NODE_ENV === 'development') {
9
+ console.warn(`[${name}] Enable crash reports and diagnostic data to be collected. This helps us to better understand how the widget is performing and where improvements need to be made.`);
9
10
  }
10
11
  }
11
12
  else {
@@ -1,5 +1,5 @@
1
1
  import type { Token } from '../types';
2
- export declare const useTokenBalances: (selectedChainId: number) => {
2
+ export declare const useTokenBalances: (selectedChainId?: number) => {
3
3
  tokens: Token[] | undefined;
4
4
  tokensWithBalance: Token[] | undefined;
5
5
  featuredTokens: import("@lifi/types").Token[];
@@ -22,7 +22,9 @@ export const useTokenBalances = (selectedChainId) => {
22
22
  const featuredTokens = useFeaturedTokens(selectedChainId);
23
23
  const { tokens, isLoading } = useTokens(selectedChainId);
24
24
  const [refetchInterval, setRefetchInterval] = useState(defaultRefetchInterval);
25
- const isBalanceLoadingEnabled = Boolean(account.address) && Boolean(tokens === null || tokens === void 0 ? void 0 : tokens.length);
25
+ const isBalanceLoadingEnabled = Boolean(account.address) &&
26
+ Boolean(tokens === null || tokens === void 0 ? void 0 : tokens.length) &&
27
+ Boolean(selectedChainId);
26
28
  const { data: tokensWithBalance, isLoading: isBalanceLoading, refetch, } = useQuery(['token-balances', account.address, selectedChainId, tokens === null || tokens === void 0 ? void 0 : tokens.length], ({ queryKey: [, accountAddress] }) => __awaiter(void 0, void 0, void 0, function* () {
27
29
  if (!accountAddress || !tokens) {
28
30
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/widget",
3
- "version": "1.17.1",
3
+ "version": "1.18.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
  "main": "./cjs/index.js",
6
6
  "module": "./index.js",
@@ -41,27 +41,27 @@
41
41
  "@emotion/styled": "^11.10.4",
42
42
  "@ethersproject/address": "^5.7.0",
43
43
  "@ethersproject/experimental": "^5.7.0",
44
- "@ethersproject/providers": "^5.7.0",
45
- "@lifi/sdk": "^1.5.0",
46
- "@lifi/wallet-management": "^1.1.9",
47
- "@mui/icons-material": "^5.10.3",
48
- "@mui/lab": "^5.0.0-alpha.99",
49
- "@mui/material": "^5.10.5",
50
- "@sentry/integrations": "^7.12.1",
51
- "@sentry/react": "^7.12.1",
52
- "@sentry/tracing": "^7.12.1",
53
- "@tanstack/react-query": "^4.3.4",
44
+ "@ethersproject/providers": "^5.7.1",
45
+ "@lifi/sdk": "^1.6.0",
46
+ "@lifi/wallet-management": "^1.1.10",
47
+ "@mui/icons-material": "^5.10.6",
48
+ "@mui/lab": "^5.0.0-alpha.100",
49
+ "@mui/material": "^5.10.6",
50
+ "@sentry/integrations": "^7.13.0",
51
+ "@sentry/react": "^7.13.0",
52
+ "@sentry/tracing": "^7.13.0",
53
+ "@tanstack/react-query": "^4.3.9",
54
54
  "@tanstack/react-virtual": "^3.0.0-beta.18",
55
55
  "big.js": "^6.2.1",
56
- "i18next": "^21.9.1",
56
+ "i18next": "^21.9.2",
57
57
  "immer": "^9.0.15",
58
58
  "microdiff": "^1.3.1",
59
59
  "mitt": "^3.0.0",
60
60
  "react": "^18.2.0",
61
61
  "react-dom": "^18.2.0",
62
- "react-hook-form": "^7.35.0",
62
+ "react-hook-form": "^7.36.0",
63
63
  "react-i18next": "^11.18.6",
64
- "react-router-dom": "^6.3.0",
64
+ "react-router-dom": "^6.4.1",
65
65
  "react-timer-hook": "^3.0.5",
66
66
  "zustand": "^4.1.1"
67
67
  },
@@ -10,5 +10,6 @@ export const ActiveSwapsEmpty = () => {
10
10
  flexDirection: 'column',
11
11
  alignItems: 'center',
12
12
  justifyContent: 'center',
13
+ paddingY: 12,
13
14
  } }, { children: [_jsx(Typography, Object.assign({ fontSize: 48 }, { children: _jsx(SwapHorizIcon, { fontSize: "inherit" }) })), _jsx(Typography, Object.assign({ fontSize: 18, fontWeight: 700 }, { children: t('swap.info.title.emptyActiveSwaps') })), _jsx(Typography, Object.assign({ fontSize: 14, color: "text.secondary", textAlign: "center", mt: 2 }, { children: t('swap.info.message.emptyActiveSwaps') }))] })));
14
15
  };
@@ -1,11 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box } from '@mui/material';
3
3
  import { ActiveSwaps } from '../../components/ActiveSwaps';
4
+ import { GasSufficiencyMessage } from '../../components/GasSufficiencyMessage';
4
5
  import { SelectChainAndToken } from '../../components/SelectChainAndToken';
6
+ import { SendToWallet, SendToWalletButton, } from '../../components/SendToWallet';
5
7
  import { SwapInput } from '../../components/SwapInput';
8
+ import { SwapRoutes } from '../../components/SwapRoutes';
6
9
  import { FormContainer } from './MainPage.style';
7
10
  import { MainSwapButton } from './MainSwapButton';
8
- import { SwapRoutes } from './SwapRoutes';
9
11
  export const MainPage = () => {
10
- return (_jsxs(FormContainer, Object.assign({ disableGutters: true }, { children: [_jsx(ActiveSwaps, { mx: 3, mt: 1, mb: 2 }), _jsx(SelectChainAndToken, { mt: 1, mx: 3, mb: 3 }), _jsx(Box, Object.assign({ mx: 3, mb: 3 }, { children: _jsx(SwapInput, { formType: "from" }) })), _jsx(SwapRoutes, { mx: 3, mb: 3 }), _jsx(Box, Object.assign({ mx: 3, mb: 1 }, { children: _jsx(MainSwapButton, {}) }))] })));
12
+ return (_jsxs(FormContainer, Object.assign({ disableGutters: true }, { children: [_jsx(ActiveSwaps, { mx: 3, mt: 1, mb: 2 }), _jsx(SelectChainAndToken, { mt: 1, mx: 3, mb: 3 }), _jsx(Box, Object.assign({ mx: 3, mb: 3 }, { children: _jsx(SwapInput, { formType: "from" }) })), _jsx(SwapRoutes, { mx: 3, mb: 3 }), _jsx(GasSufficiencyMessage, { mx: 3, mb: 3 }), _jsxs(Box, Object.assign({ mx: 3, mb: 1 }, { children: [_jsx(SendToWallet, { mb: 3 }), _jsxs(Box, Object.assign({ sx: { display: 'flex' } }, { children: [_jsx(MainSwapButton, {}), _jsx(SendToWalletButton, {})] }))] }))] })));
11
13
  };
@@ -8,13 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { forwardRef } from 'react';
11
12
  import { useFormState } from 'react-hook-form';
12
13
  import { useNavigate } from 'react-router-dom';
13
14
  import { SwapButton } from '../../components/SwapButton';
14
15
  import { useSwapRoutes } from '../../hooks';
15
16
  import { useSetExecutableRoute } from '../../stores';
16
17
  import { navigationRoutes } from '../../utils';
17
- export const MainSwapButton = () => {
18
+ export const MainSwapButton = forwardRef((_, ref) => {
18
19
  const navigate = useNavigate();
19
20
  const { isValid, isValidating } = useFormState();
20
21
  const setExecutableRoute = useSetExecutableRoute();
@@ -28,5 +29,5 @@ export const MainSwapButton = () => {
28
29
  });
29
30
  }
30
31
  });
31
- return (_jsx(SwapButton, { onClick: handleClick, currentRoute: currentRoute, disable: isLoading || isFetching || isValidating || !isValid }));
32
- };
32
+ return (_jsx(SwapButton, { onClick: handleClick, currentRoute: currentRoute, disable: isLoading || isFetching || isValidating || !isValid, ref: ref }));
33
+ });
@@ -5,15 +5,16 @@ import { ChainSelect } from '../../components/ChainSelect';
5
5
  import { TokenList } from '../../components/TokenList';
6
6
  import { useContentHeight, useNavigateBack, useScrollableOverflowHidden, } from '../../hooks';
7
7
  import { SearchTokenInput } from './SearchTokenInput';
8
+ const minTokenListHeight = 330;
8
9
  export const SelectTokenPage = ({ formType }) => {
9
10
  useScrollableOverflowHidden();
10
11
  const { navigateBack } = useNavigateBack();
11
12
  const headerRef = useRef(null);
12
13
  const contentHeight = useContentHeight();
13
- const [headerHeight, setHeaderHeight] = useState(0);
14
+ const [tokenListHeight, setTokenListHeight] = useState(0);
14
15
  useLayoutEffect(() => {
15
16
  var _a, _b;
16
- setHeaderHeight(contentHeight - ((_b = (_a = headerRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) !== null && _b !== void 0 ? _b : 0));
17
+ setTokenListHeight(Math.max(contentHeight - ((_b = (_a = headerRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) !== null && _b !== void 0 ? _b : 0), minTokenListHeight));
17
18
  }, [contentHeight]);
18
- return (_jsxs(Container, Object.assign({ disableGutters: true }, { children: [_jsxs(Box, Object.assign({ pt: 1, pb: 2, px: 3, ref: headerRef }, { children: [_jsx(ChainSelect, { formType: formType }), _jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(SearchTokenInput, {}) }))] })), _jsx(TokenList, { height: headerHeight, onClick: navigateBack, formType: formType })] })));
19
+ return (_jsxs(Container, Object.assign({ disableGutters: true }, { children: [_jsxs(Box, Object.assign({ pt: 1, pb: 2, px: 3, ref: headerRef }, { children: [_jsx(ChainSelect, { formType: formType }), _jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(SearchTokenInput, {}) }))] })), _jsx(TokenList, { height: tokenListHeight, onClick: navigateBack, formType: formType })] })));
19
20
  };
@@ -20,14 +20,14 @@ import { useHeaderActionStore } from '../../components/Header';
20
20
  import { Step } from '../../components/Step';
21
21
  import { StepDivider } from '../../components/StepDivider';
22
22
  import { useNavigateBack } from '../../hooks';
23
- import { useRouteStore } from '../../stores';
23
+ import { useRouteExecutionStore } from '../../stores';
24
24
  import { Container } from './SwapDetailsPage.style';
25
25
  export const SwapDetailsPage = () => {
26
26
  var _a, _b;
27
27
  const { t } = useTranslation();
28
28
  const { navigateBack } = useNavigateBack();
29
29
  const { state } = useLocation();
30
- const [routeExecution, deleteRoute] = useRouteStore((store) => [store.routes[state === null || state === void 0 ? void 0 : state.routeId], store.deleteRoute], shallow);
30
+ const [routeExecution, deleteRoute] = useRouteExecutionStore((store) => [store.routes[state === null || state === void 0 ? void 0 : state.routeId], store.deleteRoute], shallow);
31
31
  const [open, setOpen] = useState(false);
32
32
  const toggleDialog = useCallback(() => {
33
33
  setOpen((open) => !open);
@@ -10,5 +10,6 @@ export const SwapHistoryEmpty = () => {
10
10
  flexDirection: 'column',
11
11
  alignItems: 'center',
12
12
  justifyContent: 'center',
13
+ paddingY: 12,
13
14
  } }, { children: [_jsx(Typography, Object.assign({ fontSize: 48 }, { children: _jsx(HistoryIcon, { fontSize: "inherit" }) })), _jsx(Typography, Object.assign({ fontSize: 18, fontWeight: 700 }, { children: t('swap.info.title.emptySwapHistory') })), _jsx(Typography, Object.assign({ fontSize: 14, color: "text.secondary", textAlign: "center", mt: 2 }, { children: t('swap.info.message.emptySwapHistory') }))] })));
14
15
  };
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /* eslint-disable consistent-return */
2
3
  import { DeleteOutline as DeleteIcon } from '@mui/icons-material';
3
4
  import { Button, Container, DialogActions, DialogContent, DialogContentText, DialogTitle, IconButton, Stack, } from '@mui/material';
4
5
  import { useCallback, useEffect, useState } from 'react';
@@ -6,22 +7,24 @@ import { useTranslation } from 'react-i18next';
6
7
  import { Dialog } from '../../components/Dialog';
7
8
  import { useHeaderActionStore } from '../../components/Header';
8
9
  import { useWallet } from '../../providers';
9
- import { useRouteStore } from '../../stores';
10
- import { useSwapHistory } from '../../stores/route';
10
+ import { useRouteExecutionStore } from '../../stores';
11
+ import { useSwapHistory } from '../../stores/routes';
11
12
  import { SwapHistoryEmpty } from './SwapHistoryEmpty';
12
13
  import { SwapHistoryItem } from './SwapHistoryItem';
13
14
  export const SwapHistoryPage = () => {
14
15
  const { t } = useTranslation();
15
16
  const { account } = useWallet();
16
17
  const swaps = useSwapHistory(account.address);
17
- const deleteRoutes = useRouteStore((store) => store.deleteRoutes);
18
+ const deleteRoutes = useRouteExecutionStore((store) => store.deleteRoutes);
18
19
  const [open, setOpen] = useState(false);
19
20
  const toggleDialog = useCallback(() => {
20
21
  setOpen((open) => !open);
21
22
  }, []);
22
23
  useEffect(() => {
23
- return useHeaderActionStore.getState().setAction(_jsx(IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "end", onClick: toggleDialog }, { children: _jsx(DeleteIcon, {}) })));
24
- }, [toggleDialog]);
24
+ if (swaps.length) {
25
+ return useHeaderActionStore.getState().setAction(_jsx(IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "end", onClick: toggleDialog }, { children: _jsx(DeleteIcon, {}) })));
26
+ }
27
+ }, [swaps.length, toggleDialog]);
25
28
  if (!swaps.length) {
26
29
  return _jsx(SwapHistoryEmpty, {});
27
30
  }
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ import { Delete as DeleteIcon } from '@mui/icons-material';
11
12
  import { Box, Button } from '@mui/material';
12
13
  import { Fragment } from 'react';
13
14
  import { useFormContext } from 'react-hook-form';
@@ -54,5 +55,8 @@ export const SwapPage = () => {
54
55
  return (_jsxs(Fragment, { children: [_jsx(Step, { step: step, fromToken: index === 0
55
56
  ? Object.assign(Object.assign({}, step.action.fromToken), { amount: step.action.fromAmount }) : undefined, toToken: index === steps.length - 1
56
57
  ? Object.assign(Object.assign({}, step.action.toToken), { amount: (_b = (_a = step.execution) === null || _a === void 0 ? void 0 : _a.toAmount) !== null && _b !== void 0 ? _b : step.estimate.toAmount }) : undefined }), steps.length > 1 && index !== steps.length - 1 ? (_jsx(StepDivider, {})) : null] }, step.id));
57
- }), status === 'idle' ? (_jsx(GasSufficiencyMessage, { route: route, mt: 2 })) : null, status === 'idle' || status === 'error' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(SwapButton, { text: getSwapButtonText(), onClick: handleSwapClick, currentRoute: route, disable: status === 'idle' && (isValidating || !isValid) }) }))) : null, status === 'error' ? (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(Button, Object.assign({ variant: "outlined", onClick: handleRemoveRoute, fullWidth: true }, { children: t('button.removeSwap') })) }))) : null, route && status ? (_jsx(StatusBottomSheet, { status: status, route: route })) : null] }));
58
+ }), status === 'idle' ? (_jsx(GasSufficiencyMessage, { route: route, mt: 2 })) : null, status === 'idle' || status === 'error' ? (_jsxs(Box, Object.assign({ mt: 2, display: "flex" }, { children: [_jsx(SwapButton, { text: getSwapButtonText(), onClick: handleSwapClick, currentRoute: route, disable: status === 'idle' && (isValidating || !isValid) }), status === 'error' ? (_jsx(Button, Object.assign({ onClick: handleRemoveRoute, sx: {
59
+ minWidth: 48,
60
+ marginLeft: 1,
61
+ } }, { children: _jsx(DeleteIcon, {}) }))) : null] }))) : null, route && status ? (_jsx(StatusBottomSheet, { status: status, route: route })) : null] }));
58
62
  };
@@ -1,16 +1,14 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useEffect } from 'react';
3
- import { useLocation, useNavigate } from 'react-router-dom';
4
3
  import { useHeaderActionStore } from '../../components/Header';
5
4
  import { ProgressToNextUpdate } from '../../components/ProgressToNextUpdate';
6
5
  import { SwapRouteCard, SwapRouteCardSkeleton, SwapRouteNotFoundCard, } from '../../components/SwapRouteCard';
7
- import { useSwapRoutes } from '../../hooks';
6
+ import { useNavigateBack, useSwapRoutes } from '../../hooks';
8
7
  import { useSetExecutableRoute } from '../../stores';
9
8
  import { navigationRoutes } from '../../utils';
10
9
  import { Stack } from './SwapRoutesPage.style';
11
10
  export const SwapRoutesPage = () => {
12
- const navigate = useNavigate();
13
- const { pathname } = useLocation();
11
+ const { navigateBack, navigate } = useNavigateBack();
14
12
  const { routes: swapRoutes, isLoading, isFetching, dataUpdatedAt, refetchTime, refetch, } = useSwapRoutes();
15
13
  const setExecutableRoute = useSetExecutableRoute();
16
14
  const handleRouteClick = (route) => {
@@ -21,7 +19,7 @@ export const SwapRoutesPage = () => {
21
19
  };
22
20
  useEffect(() => {
23
21
  if (!(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.length) && !isLoading && !isFetching) {
24
- navigate(pathname.substring(0, pathname.lastIndexOf('/')));
22
+ navigateBack();
25
23
  }
26
24
  // redirect to the home page if no routes are found on page reload
27
25
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -32,5 +30,5 @@ export const SwapRoutesPage = () => {
32
30
  .setAction(_jsx(ProgressToNextUpdate, { updatedAt: dataUpdatedAt || new Date().getTime(), timeToUpdate: refetchTime, isLoading: isFetching, onClick: () => refetch(), sx: { marginRight: -1 }, size: "medium", edge: "end" }));
33
31
  }, [dataUpdatedAt, isFetching, refetch, refetchTime]);
34
32
  const routeNotFound = !(swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.length) && !isLoading && !isFetching;
35
- return (_jsx(Stack, Object.assign({ direction: "column", spacing: 2, flex: 1 }, { children: routeNotFound ? (_jsx(SwapRouteNotFoundCard, {})) : isLoading || isFetching ? (Array.from({ length: 3 }).map((_, index) => (_jsx(SwapRouteCardSkeleton, {}, index)))) : (swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.map((route) => (_jsx(SwapRouteCard, { route: route, onClick: () => handleRouteClick(route) }, route.id)))) })));
33
+ return (_jsx(Stack, Object.assign({ direction: "column", spacing: 2, flex: 1 }, { children: routeNotFound ? (_jsx(SwapRouteNotFoundCard, {})) : isLoading || isFetching ? (Array.from({ length: 3 }).map((_, index) => (_jsx(SwapRouteCardSkeleton, {}, index)))) : (swapRoutes === null || swapRoutes === void 0 ? void 0 : swapRoutes.map((route, index) => (_jsx(SwapRouteCard, { route: route, onClick: () => handleRouteClick(route), active: index === 0 }, route.id)))) })));
36
34
  };
@@ -11,7 +11,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { addChain as walletAddChain, switchChain as walletSwitchChain, switchChainAndAddToken, useLiFiWalletManagement, } from '@lifi/wallet-management';
12
12
  import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from 'react';
13
13
  import { useFormContext } from 'react-hook-form';
14
- import { useChainOrderStore } from '../../stores/chains';
14
+ import { useChainOrderStore } from '../../stores';
15
15
  import { SwapFormKey } from '../SwapFormProvider';
16
16
  import { isItemAllowed, useWidgetConfig } from '../WidgetProvider';
17
17
  const stub = () => {
package/stores/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from './route';
1
+ export * from './chains';
2
+ export * from './routes';
2
3
  export * from './settings';
package/stores/index.js CHANGED
@@ -1,2 +1,3 @@
1
- export * from './route';
1
+ export * from './chains';
2
+ export * from './routes';
2
3
  export * from './settings';
@@ -1,6 +1,7 @@
1
1
  export * from './types';
2
2
  export * from './useExecutingRoutesIds';
3
- export * from './useRouteStore';
3
+ export * from './useRouteExecutionStore';
4
+ export * from './useSelectedRouteStore';
4
5
  export * from './useSetExecutableRoute';
5
6
  export * from './useSwapHistory';
6
7
  export * from './utils';
@@ -1,6 +1,7 @@
1
1
  export * from './types';
2
2
  export * from './useExecutingRoutesIds';
3
- export * from './useRouteStore';
3
+ export * from './useRouteExecutionStore';
4
+ export * from './useSelectedRouteStore';
4
5
  export * from './useSetExecutableRoute';
5
6
  export * from './useSwapHistory';
6
7
  export * from './utils';
@@ -12,3 +12,7 @@ export interface RouteExecution {
12
12
  route: Route;
13
13
  status: RouteExecutionStatus;
14
14
  }
15
+ export interface SelectedRouteStore {
16
+ selectedRoute?: Route;
17
+ setSelectedRoute: (route?: Route) => void;
18
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,7 @@
1
1
  import shallow from 'zustand/shallow';
2
- import { useRouteStore } from './useRouteStore';
2
+ import { useRouteExecutionStore } from './useRouteExecutionStore';
3
3
  export const useExecutingRoutesIds = (address) => {
4
- return useRouteStore((state) => Object.values(state.routes)
4
+ return useRouteExecutionStore((state) => Object.values(state.routes)
5
5
  .filter((item) => item.route.fromAddress === address &&
6
6
  (item.status === 'loading' || item.status === 'error'))
7
7
  .sort((a, b) => {
@@ -1,5 +1,5 @@
1
1
  import type { RouteExecutionStore } from './types';
2
- export declare const useRouteStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<RouteExecutionStore>, "persist"> & {
2
+ export declare const useRouteExecutionStore: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<RouteExecutionStore>, "persist"> & {
3
3
  persist: {
4
4
  setOptions: (options: Partial<import("zustand/middleware").PersistOptions<RouteExecutionStore, {
5
5
  routes: Partial<Record<string, import("./types").RouteExecution>>;
@@ -2,7 +2,7 @@ import create from 'zustand';
2
2
  import { persist } from 'zustand/middleware';
3
3
  import { immer } from 'zustand/middleware/immer';
4
4
  import { isRouteCompleted, isRouteFailed } from './utils';
5
- export const useRouteStore = create()(persist(immer((set) => ({
5
+ export const useRouteExecutionStore = create()(persist(immer((set) => ({
6
6
  routes: {},
7
7
  setExecutableRoute: (route) => set((state) => {
8
8
  if (!state.routes[route.id]) {
@@ -0,0 +1,4 @@
1
+ import type { SelectedRouteStore } from './types';
2
+ export declare const useSelectedRouteStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<SelectedRouteStore>, "setState"> & {
3
+ setState(nextStateOrUpdater: SelectedRouteStore | Partial<SelectedRouteStore> | ((state: import("immer/dist/internal").WritableDraft<SelectedRouteStore>) => void), shouldReplace?: boolean | undefined): void;
4
+ }>;
@@ -0,0 +1,9 @@
1
+ import create from 'zustand';
2
+ import { immer } from 'zustand/middleware/immer';
3
+ export const useSelectedRouteStore = create()(immer((set) => ({
4
+ setSelectedRoute: (route) => {
5
+ set((state) => {
6
+ state.selectedRoute = route;
7
+ });
8
+ },
9
+ })));
@@ -0,0 +1,4 @@
1
+ import { useRouteExecutionStore } from './useRouteExecutionStore';
2
+ export const useSetExecutableRoute = () => {
3
+ return useRouteExecutionStore((state) => state.setExecutableRoute);
4
+ };
File without changes
@@ -1,7 +1,7 @@
1
1
  import shallow from 'zustand/shallow';
2
- import { useRouteStore } from './useRouteStore';
2
+ import { useRouteExecutionStore } from './useRouteExecutionStore';
3
3
  export const useSwapHistory = (address) => {
4
- return useRouteStore((state) => Object.values(state.routes)
4
+ return useRouteExecutionStore((state) => Object.values(state.routes)
5
5
  .filter((item) => (item === null || item === void 0 ? void 0 : item.route.fromAddress) === address && (item === null || item === void 0 ? void 0 : item.status) === 'success')
6
6
  .sort((a, b) => {
7
7
  var _a, _b, _c, _d;
File without changes
File without changes
@@ -16,7 +16,7 @@ import { immer } from 'zustand/middleware/immer';
16
16
  import { SettingsToolTypes } from './types';
17
17
  export const useSettingsStore = create()(persist(immer((set) => ({
18
18
  advancedPreferences: false,
19
- showDestinationWallet: false,
19
+ showDestinationWallet: true,
20
20
  appearance: 'auto',
21
21
  gasPrice: 'normal',
22
22
  routePriority: 'RECOMMENDED',