@lifi/widget 1.16.0 → 1.17.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.
Files changed (179) hide show
  1. package/AppDrawer.d.ts +3 -3
  2. package/AppProvider.d.ts +0 -4
  3. package/AppProvider.js +2 -10
  4. package/README.md +1 -1
  5. package/cjs/AppDrawer.d.ts +3 -3
  6. package/cjs/AppProvider.d.ts +0 -4
  7. package/cjs/AppProvider.js +3 -12
  8. package/cjs/components/AppContainer.js +2 -2
  9. package/cjs/components/ChainSelect/ChainSelect.style.js +4 -4
  10. package/cjs/components/ChainSelect/useChainSelect.d.ts +2 -2
  11. package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.js +3 -3
  12. package/cjs/components/Header/useHeaderActionStore.d.ts +0 -2
  13. package/cjs/components/Header/useHeaderActionStore.js +1 -5
  14. package/cjs/components/SelectChainAndToken.js +5 -5
  15. package/cjs/components/SwapButton/SwapButton.js +3 -23
  16. package/cjs/components/TokenList/TokenList.js +1 -1
  17. package/cjs/components/TokenList/TokenList.style.js +4 -3
  18. package/cjs/components/TokenList/TokenListItem.js +1 -1
  19. package/cjs/components/TokenList/TokenNotFound.d.ts +2 -1
  20. package/cjs/components/TokenList/TokenNotFound.js +12 -2
  21. package/cjs/components/TokenList/types.d.ts +2 -2
  22. package/cjs/config/version.d.ts +1 -1
  23. package/cjs/config/version.js +1 -1
  24. package/cjs/hooks/useChains.js +23 -10
  25. package/cjs/hooks/useFeaturedTokens.d.ts +1 -1
  26. package/cjs/hooks/useFeaturedTokens.js +6 -3
  27. package/cjs/hooks/useGasSufficiency.d.ts +1 -1
  28. package/cjs/hooks/useGasSufficiency.js +39 -28
  29. package/cjs/hooks/useInitializer.js +6 -0
  30. package/cjs/hooks/useRouteExecution.js +28 -12
  31. package/cjs/hooks/useSwapRoutes.js +10 -11
  32. package/cjs/hooks/useToken.d.ts +0 -1
  33. package/cjs/hooks/useToken.js +1 -2
  34. package/cjs/hooks/useTokenBalances.d.ts +1 -2
  35. package/cjs/hooks/useTokenBalances.js +5 -6
  36. package/cjs/hooks/useTokenSearch.js +3 -2
  37. package/cjs/hooks/useTokens.d.ts +1 -2
  38. package/cjs/hooks/useTokens.js +32 -9
  39. package/cjs/hooks/useTools.js +11 -5
  40. package/cjs/hooks/useWidgetEvents.d.ts +3 -3
  41. package/cjs/hooks/useWidgetEvents.js +2 -2
  42. package/cjs/i18n/en/translation.json +2 -3
  43. package/cjs/i18n/index.d.ts +1 -2
  44. package/cjs/index.d.ts +2 -1
  45. package/cjs/pages/MainPage/MainSwapButton.js +1 -1
  46. package/cjs/pages/SettingsPage/AdvancedPreferences.js +1 -1
  47. package/cjs/pages/SettingsPage/GasPriceSelect.js +1 -1
  48. package/cjs/pages/SettingsPage/RoutePrioritySelect.js +1 -1
  49. package/cjs/pages/SettingsPage/ShowDestinationWallet.js +1 -1
  50. package/cjs/pages/SettingsPage/SlippageInput.js +1 -1
  51. package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +2 -3
  52. package/cjs/pages/SwapHistoryPage/SwapHistoryPage.js +2 -3
  53. package/cjs/pages/SwapPage/SwapPage.js +11 -2
  54. package/cjs/pages/SwapRoutesPage/SwapRoutesPage.js +4 -3
  55. package/cjs/providers/SDKProvider/SDKProvider.d.ts +4 -0
  56. package/cjs/providers/SDKProvider/SDKProvider.js +27 -0
  57. package/cjs/providers/SDKProvider/index.d.ts +1 -0
  58. package/cjs/providers/SDKProvider/index.js +17 -0
  59. package/cjs/providers/SwapFormProvider/SwapFormProvider.js +4 -58
  60. package/cjs/providers/SwapFormProvider/types.d.ts +5 -5
  61. package/cjs/providers/TelemetryProvider/TelemetryProvider.d.ts +4 -0
  62. package/cjs/providers/TelemetryProvider/TelemetryProvider.js +11 -0
  63. package/cjs/providers/TelemetryProvider/index.d.ts +1 -0
  64. package/cjs/providers/TelemetryProvider/index.js +17 -0
  65. package/cjs/providers/WalletProvider/WalletProvider.d.ts +1 -4
  66. package/cjs/providers/WalletProvider/WalletProvider.js +59 -1
  67. package/cjs/providers/WidgetProvider/WidgetProvider.js +1 -12
  68. package/cjs/providers/WidgetProvider/index.d.ts +1 -0
  69. package/cjs/providers/WidgetProvider/index.js +1 -0
  70. package/cjs/providers/WidgetProvider/utils.d.ts +4 -0
  71. package/cjs/providers/WidgetProvider/utils.js +13 -0
  72. package/cjs/providers/index.d.ts +2 -0
  73. package/cjs/providers/index.js +2 -0
  74. package/cjs/stores/chains/index.d.ts +0 -1
  75. package/cjs/stores/chains/index.js +0 -1
  76. package/cjs/stores/chains/types.d.ts +1 -1
  77. package/cjs/stores/chains/useChainOrderStore.js +17 -14
  78. package/cjs/stores/route/utils.d.ts +2 -1
  79. package/cjs/stores/route/utils.js +17 -1
  80. package/cjs/stores/settings/index.d.ts +0 -1
  81. package/cjs/stores/settings/index.js +0 -1
  82. package/cjs/stores/settings/useAppearance.js +3 -1
  83. package/cjs/types/events.d.ts +15 -3
  84. package/cjs/types/events.js +4 -3
  85. package/cjs/types/widget.d.ts +29 -22
  86. package/cjs/utils/colors.d.ts +1 -1
  87. package/components/AppContainer.js +1 -1
  88. package/components/ChainSelect/ChainSelect.style.js +4 -4
  89. package/components/ChainSelect/useChainSelect.d.ts +2 -2
  90. package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +3 -3
  91. package/components/Header/useHeaderActionStore.d.ts +0 -2
  92. package/components/Header/useHeaderActionStore.js +0 -3
  93. package/components/SelectChainAndToken.js +1 -1
  94. package/components/SwapButton/SwapButton.js +5 -25
  95. package/components/TokenList/TokenList.js +1 -1
  96. package/components/TokenList/TokenList.style.js +4 -3
  97. package/components/TokenList/TokenListItem.js +1 -1
  98. package/components/TokenList/TokenNotFound.d.ts +2 -1
  99. package/components/TokenList/TokenNotFound.js +12 -2
  100. package/components/TokenList/types.d.ts +2 -2
  101. package/config/version.d.ts +1 -1
  102. package/config/version.js +1 -1
  103. package/hooks/useChains.js +24 -11
  104. package/hooks/useFeaturedTokens.d.ts +1 -1
  105. package/hooks/useFeaturedTokens.js +6 -3
  106. package/hooks/useGasSufficiency.d.ts +1 -1
  107. package/hooks/useGasSufficiency.js +35 -24
  108. package/hooks/useInitializer.js +6 -0
  109. package/hooks/useRouteExecution.js +28 -12
  110. package/hooks/useSwapRoutes.js +3 -4
  111. package/hooks/useToken.d.ts +0 -1
  112. package/hooks/useToken.js +1 -2
  113. package/hooks/useTokenBalances.d.ts +1 -2
  114. package/hooks/useTokenBalances.js +4 -5
  115. package/hooks/useTokenSearch.js +3 -2
  116. package/hooks/useTokens.d.ts +1 -2
  117. package/hooks/useTokens.js +32 -9
  118. package/hooks/useTools.js +11 -5
  119. package/hooks/useWidgetEvents.d.ts +3 -3
  120. package/hooks/useWidgetEvents.js +2 -2
  121. package/i18n/en/translation.json +2 -3
  122. package/i18n/index.d.ts +1 -2
  123. package/index.d.ts +2 -1
  124. package/package.json +9 -8
  125. package/pages/MainPage/MainSwapButton.js +1 -1
  126. package/pages/SettingsPage/AdvancedPreferences.js +2 -2
  127. package/pages/SettingsPage/GasPriceSelect.js +2 -2
  128. package/pages/SettingsPage/RoutePrioritySelect.js +2 -2
  129. package/pages/SettingsPage/ShowDestinationWallet.js +2 -2
  130. package/pages/SettingsPage/SlippageInput.js +2 -2
  131. package/pages/SwapDetailsPage/SwapDetailsPage.js +3 -4
  132. package/pages/SwapHistoryPage/SwapHistoryPage.js +3 -4
  133. package/pages/SwapPage/SwapPage.js +11 -2
  134. package/pages/SwapRoutesPage/SwapRoutesPage.js +5 -4
  135. package/providers/SDKProvider/SDKProvider.d.ts +4 -0
  136. package/providers/SDKProvider/SDKProvider.js +19 -0
  137. package/providers/SDKProvider/index.d.ts +1 -0
  138. package/providers/SDKProvider/index.js +1 -0
  139. package/providers/SwapFormProvider/SwapFormProvider.js +4 -58
  140. package/providers/SwapFormProvider/types.d.ts +5 -5
  141. package/providers/TelemetryProvider/TelemetryProvider.d.ts +4 -0
  142. package/providers/TelemetryProvider/TelemetryProvider.js +7 -0
  143. package/providers/TelemetryProvider/index.d.ts +1 -0
  144. package/providers/TelemetryProvider/index.js +1 -0
  145. package/providers/WalletProvider/WalletProvider.d.ts +1 -4
  146. package/providers/WalletProvider/WalletProvider.js +59 -1
  147. package/providers/WidgetProvider/WidgetProvider.js +3 -14
  148. package/providers/WidgetProvider/index.d.ts +1 -0
  149. package/providers/WidgetProvider/index.js +1 -0
  150. package/providers/WidgetProvider/utils.d.ts +4 -0
  151. package/providers/WidgetProvider/utils.js +9 -0
  152. package/providers/index.d.ts +2 -0
  153. package/providers/index.js +2 -0
  154. package/stores/chains/index.d.ts +0 -1
  155. package/stores/chains/index.js +0 -1
  156. package/stores/chains/types.d.ts +1 -1
  157. package/stores/chains/useChainOrderStore.js +17 -14
  158. package/stores/route/utils.d.ts +2 -1
  159. package/stores/route/utils.js +12 -0
  160. package/stores/settings/index.d.ts +0 -1
  161. package/stores/settings/index.js +0 -1
  162. package/stores/settings/useAppearance.js +3 -1
  163. package/tsconfig.cjs.tsbuildinfo +1 -1
  164. package/types/events.d.ts +15 -3
  165. package/types/events.js +4 -3
  166. package/types/widget.d.ts +29 -22
  167. package/utils/colors.d.ts +1 -1
  168. package/cjs/config/lifi.d.ts +0 -4
  169. package/cjs/config/lifi.js +0 -14
  170. package/cjs/stores/chains/useInitializeChainOrder.d.ts +0 -1
  171. package/cjs/stores/chains/useInitializeChainOrder.js +0 -12
  172. package/cjs/stores/settings/useSetSettings.d.ts +0 -5
  173. package/cjs/stores/settings/useSetSettings.js +0 -12
  174. package/config/lifi.d.ts +0 -4
  175. package/config/lifi.js +0 -7
  176. package/stores/chains/useInitializeChainOrder.d.ts +0 -1
  177. package/stores/chains/useInitializeChainOrder.js +0 -5
  178. package/stores/settings/useSetSettings.d.ts +0 -5
  179. package/stores/settings/useSetSettings.js +0 -5
@@ -10,28 +10,42 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { useMutation } from '@tanstack/react-query';
11
11
  import { useCallback, useEffect, useRef } from 'react';
12
12
  import shallow from 'zustand/shallow';
13
- import { LiFi } from '../config/lifi';
14
- import { useWallet } from '../providers/WalletProvider';
15
- import { isRouteActive, isRouteCompleted, isRouteFailed, useRouteStore, } from '../stores';
13
+ import { useLiFi, useWallet } from '../providers';
14
+ import { getUpdatedProcess, isRouteActive, isRouteCompleted, isRouteFailed, useRouteStore, } from '../stores';
16
15
  import { WidgetEvent } from '../types/events';
17
16
  import { deepClone } from '../utils';
18
17
  import { useWidgetEvents } from './useWidgetEvents';
19
18
  export const useRouteExecution = (routeId, executeInBackground) => {
19
+ const lifi = useLiFi();
20
20
  const { account, switchChain } = useWallet();
21
21
  const resumedAfterMount = useRef(false);
22
22
  const emitter = useWidgetEvents();
23
23
  const routeExecution = useRouteStore((state) => state.routes[routeId]);
24
24
  const [updateRoute, restartRoute, deleteRoute] = useRouteStore((state) => [state.updateRoute, state.restartRoute, state.deleteRoute], shallow);
25
25
  const updateCallback = (updatedRoute) => {
26
+ const routeExecution = useRouteStore.getState().routes[updatedRoute.id];
27
+ if (!routeExecution) {
28
+ return;
29
+ }
26
30
  const clonedUpdatedRoute = deepClone(updatedRoute);
27
- console.log('Route updated.', clonedUpdatedRoute);
28
31
  updateRoute(clonedUpdatedRoute);
32
+ const process = getUpdatedProcess(routeExecution.route, clonedUpdatedRoute);
33
+ if (process) {
34
+ emitter.emit(WidgetEvent.RouteExecutionUpdated, {
35
+ route: clonedUpdatedRoute,
36
+ process,
37
+ });
38
+ }
29
39
  if (isRouteCompleted(clonedUpdatedRoute)) {
30
- emitter.emit(WidgetEvent.SwapCompleted);
40
+ emitter.emit(WidgetEvent.RouteExecutionCompleted, clonedUpdatedRoute);
31
41
  }
32
- if (isRouteFailed(clonedUpdatedRoute)) {
33
- emitter.emit(WidgetEvent.SwapFailed);
42
+ if (isRouteFailed(clonedUpdatedRoute) && process) {
43
+ emitter.emit(WidgetEvent.RouteExecutionFailed, {
44
+ route: clonedUpdatedRoute,
45
+ process,
46
+ });
34
47
  }
48
+ console.log('Route updated.', clonedUpdatedRoute);
35
49
  };
36
50
  const switchChainHook = (requiredChainId) => __awaiter(void 0, void 0, void 0, function* () {
37
51
  if (!account.isActive || !account.signer) {
@@ -53,7 +67,7 @@ export const useRouteExecution = (routeId, executeInBackground) => {
53
67
  if (!(routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route)) {
54
68
  throw Error('Execution route not found.');
55
69
  }
56
- return LiFi.executeRoute(account.signer, routeExecution.route, {
70
+ return lifi.executeRoute(account.signer, routeExecution.route, {
57
71
  updateCallback,
58
72
  switchChainHook,
59
73
  infiniteApproval: false,
@@ -62,7 +76,9 @@ export const useRouteExecution = (routeId, executeInBackground) => {
62
76
  }, {
63
77
  onMutate: () => {
64
78
  console.log('Execution started.', routeId);
65
- emitter.emit(WidgetEvent.SwapStarted);
79
+ if (routeExecution) {
80
+ emitter.emit(WidgetEvent.RouteExecutionStarted, routeExecution.route);
81
+ }
66
82
  },
67
83
  });
68
84
  const resumeRouteMutation = useMutation((resumedRoute) => {
@@ -72,7 +88,7 @@ export const useRouteExecution = (routeId, executeInBackground) => {
72
88
  if (!(routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route)) {
73
89
  throw Error('Execution route not found.');
74
90
  }
75
- return LiFi.resumeRoute(account.signer, resumedRoute !== null && resumedRoute !== void 0 ? resumedRoute : routeExecution.route, {
91
+ return lifi.resumeRoute(account.signer, resumedRoute !== null && resumedRoute !== void 0 ? resumedRoute : routeExecution.route, {
76
92
  updateCallback,
77
93
  switchChainHook,
78
94
  infiniteApproval: false,
@@ -132,11 +148,11 @@ export const useRouteExecution = (routeId, executeInBackground) => {
132
148
  if (!route || !isRouteActive(route)) {
133
149
  return;
134
150
  }
135
- LiFi.updateRouteExecution(route, { executeInBackground: true });
151
+ lifi.updateRouteExecution(route, { executeInBackground: true });
136
152
  console.log('Move route execution to background.', routeId);
137
153
  resumedAfterMount.current = false;
138
154
  };
139
- }, [routeId]);
155
+ }, [lifi, routeId]);
140
156
  return {
141
157
  executeRoute,
142
158
  restartRoute: restartRouteMutation,
@@ -12,13 +12,12 @@ import { useQuery, useQueryClient } from '@tanstack/react-query';
12
12
  import Big from 'big.js';
13
13
  import { useWatch } from 'react-hook-form';
14
14
  import { useDebouncedWatch, useToken } from '.';
15
- import { LiFi } from '../config/lifi';
16
- import { SwapFormKey } from '../providers/SwapFormProvider';
17
- import { useWallet } from '../providers/WalletProvider';
15
+ import { SwapFormKey, useLiFi, useWallet } from '../providers';
18
16
  import { useSettings } from '../stores';
19
17
  const refetchTime = 60000;
20
18
  export const useSwapRoutes = () => {
21
19
  var _a;
20
+ const lifi = useLiFi();
22
21
  const { account, provider } = useWallet();
23
22
  const queryClient = useQueryClient();
24
23
  const { slippage, enabledBridges, enabledExchanges, routePriority } = useSettings([
@@ -75,7 +74,7 @@ export const useSwapRoutes = () => {
75
74
  catch (_d) {
76
75
  toWalletAddress = isAddress(toAddress) ? toAddress : fromAddress;
77
76
  }
78
- return LiFi.getRoutes({
77
+ return lifi.getRoutes({
79
78
  fromChainId,
80
79
  fromAmount: Big(Number(fromTokenAmount) * Math.pow(10, ((_c = token === null || token === void 0 ? void 0 : token.decimals) !== null && _c !== void 0 ? _c : 0))).toString(),
81
80
  fromTokenAddress,
@@ -1,5 +1,4 @@
1
1
  export declare const useToken: (chainId: number, tokenAddress: string) => {
2
2
  token: import("..").Token | undefined;
3
3
  isLoading: boolean;
4
- isFetching: boolean;
5
4
  };
package/hooks/useToken.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { useMemo } from 'react';
2
2
  import { useTokens } from './useTokens';
3
3
  export const useToken = (chainId, tokenAddress) => {
4
- const { tokens, isLoading, isFetching } = useTokens(chainId);
4
+ const { tokens, isLoading } = useTokens(chainId);
5
5
  const token = useMemo(() => {
6
6
  const token = tokens === null || tokens === void 0 ? void 0 : tokens.find((token) => token.address === tokenAddress && token.chainId === chainId);
7
7
  return token;
@@ -9,6 +9,5 @@ export const useToken = (chainId, tokenAddress) => {
9
9
  return {
10
10
  token,
11
11
  isLoading,
12
- isFetching,
13
12
  };
14
13
  };
@@ -2,9 +2,8 @@ import type { Token } from '../types';
2
2
  export declare const useTokenBalances: (selectedChainId: number) => {
3
3
  tokens: Token[] | undefined;
4
4
  tokensWithBalance: Token[] | undefined;
5
- featuredTokens: import("@lifi/types").Token[] | undefined;
5
+ featuredTokens: import("@lifi/types").Token[];
6
6
  isLoading: boolean;
7
7
  isBalanceLoading: boolean;
8
- isBalanceFetched: boolean;
9
8
  refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<Token[] | undefined, unknown>>;
10
9
  };
@@ -10,24 +10,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  /* eslint-disable consistent-return */
11
11
  import { useQuery } from '@tanstack/react-query';
12
12
  import { useState } from 'react';
13
- import { LiFi } from '../config/lifi';
14
- import { useWallet } from '../providers/WalletProvider';
13
+ import { useLiFi, useWallet } from '../providers';
15
14
  import { formatTokenAmount } from '../utils';
16
15
  import { useFeaturedTokens } from './useFeaturedTokens';
17
16
  import { useTokens } from './useTokens';
18
17
  const defaultRefetchInterval = 60000;
19
18
  const minRefetchInterval = 1000;
20
19
  export const useTokenBalances = (selectedChainId) => {
20
+ const lifi = useLiFi();
21
21
  const { account } = useWallet();
22
22
  const featuredTokens = useFeaturedTokens(selectedChainId);
23
23
  const { tokens, isLoading } = useTokens(selectedChainId);
24
24
  const [refetchInterval, setRefetchInterval] = useState(defaultRefetchInterval);
25
25
  const isBalanceLoadingEnabled = Boolean(account.address) && Boolean(tokens === null || tokens === void 0 ? void 0 : tokens.length);
26
- const { data: tokensWithBalance, isLoading: isBalanceLoading, isFetched: isBalanceFetched, 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* () {
26
+ 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
27
  if (!accountAddress || !tokens) {
28
28
  return;
29
29
  }
30
- const tokenBalances = yield LiFi.getTokenBalances(accountAddress, tokens);
30
+ const tokenBalances = yield lifi.getTokenBalances(accountAddress, tokens);
31
31
  if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
32
32
  // Sometimes RPCs (e.g. Arbitrum) don't return balances on first call
33
33
  // TODO: fix and remove backplane
@@ -70,7 +70,6 @@ export const useTokenBalances = (selectedChainId) => {
70
70
  featuredTokens,
71
71
  isLoading,
72
72
  isBalanceLoading: isBalanceLoading && isBalanceLoadingEnabled,
73
- isBalanceFetched,
74
73
  refetch,
75
74
  };
76
75
  };
@@ -8,11 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { useQuery, useQueryClient } from '@tanstack/react-query';
11
- import { LiFi } from '../config/lifi';
11
+ import { useLiFi } from '../providers';
12
12
  export const useTokenSearch = (token, chainId, enabled) => {
13
+ const lifi = useLiFi();
13
14
  const queryClient = useQueryClient();
14
15
  const { data, isLoading, isFetching, isFetched } = useQuery(['token-search', chainId, token], ({ queryKey: [, chainId, token], signal }) => __awaiter(void 0, void 0, void 0, function* () {
15
- const data = yield LiFi.getToken(chainId, token, {
16
+ const data = yield lifi.getToken(chainId, token, {
16
17
  signal,
17
18
  });
18
19
  if (data) {
@@ -1,6 +1,5 @@
1
1
  import type { Token } from '../types';
2
- export declare const useTokens: (selectedChainId: number) => {
2
+ export declare const useTokens: (selectedChainId?: number) => {
3
3
  tokens: Token[] | undefined;
4
4
  isLoading: boolean;
5
- isFetching: boolean;
6
5
  };
@@ -8,25 +8,48 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { useQuery } from '@tanstack/react-query';
11
- import { LiFi } from '../config/lifi';
11
+ import { isItemAllowed, useLiFi, useWidgetConfig } from '../providers';
12
12
  import { useFeaturedTokens } from './useFeaturedTokens';
13
13
  export const useTokens = (selectedChainId) => {
14
+ var _a, _b, _c, _d;
15
+ const lifi = useLiFi();
14
16
  const featuredTokens = useFeaturedTokens(selectedChainId);
15
- const { data: tokens, isLoading, isFetching, } = useQuery(['tokens', selectedChainId, featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.length], () => __awaiter(void 0, void 0, void 0, function* () {
16
- var _a, _b, _c;
17
- const data = yield LiFi.getTokens({ chains: [selectedChainId] });
17
+ const { tokens, chains, disabledChains } = useWidgetConfig();
18
+ const { data, isLoading } = useQuery([
19
+ 'tokens',
20
+ selectedChainId,
21
+ featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.length,
22
+ (_a = tokens === null || tokens === void 0 ? void 0 : tokens.allow) === null || _a === void 0 ? void 0 : _a.length,
23
+ (_b = tokens === null || tokens === void 0 ? void 0 : tokens.deny) === null || _b === void 0 ? void 0 : _b.length,
24
+ (_c = chains === null || chains === void 0 ? void 0 : chains.allow) === null || _c === void 0 ? void 0 : _c.length,
25
+ (_d = chains === null || chains === void 0 ? void 0 : chains.deny) === null || _d === void 0 ? void 0 : _d.length,
26
+ ], () => __awaiter(void 0, void 0, void 0, function* () {
27
+ var _e, _f, _g, _h, _j;
28
+ const chainAllowed = selectedChainId &&
29
+ isItemAllowed(selectedChainId, chains, disabledChains);
30
+ if (!chainAllowed) {
31
+ return [];
32
+ }
33
+ let filteredTokens = (_e = tokens === null || tokens === void 0 ? void 0 : tokens.allow) === null || _e === void 0 ? void 0 : _e.filter((token) => token.chainId === selectedChainId);
34
+ if (!(filteredTokens === null || filteredTokens === void 0 ? void 0 : filteredTokens.length)) {
35
+ const data = yield lifi.getTokens({ chains: [selectedChainId] });
36
+ filteredTokens = (_f = data.tokens) === null || _f === void 0 ? void 0 : _f[selectedChainId];
37
+ }
38
+ const deniedTokenAddresses = (_g = tokens === null || tokens === void 0 ? void 0 : tokens.deny) === null || _g === void 0 ? void 0 : _g.filter((token) => token.chainId === selectedChainId).map((token) => token.address);
39
+ if (deniedTokenAddresses === null || deniedTokenAddresses === void 0 ? void 0 : deniedTokenAddresses.length) {
40
+ filteredTokens = filteredTokens === null || filteredTokens === void 0 ? void 0 : filteredTokens.filter((token) => !deniedTokenAddresses.includes(token.address));
41
+ }
18
42
  const featuredTokenAddresses = new Set(featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.map((token) => token.address));
19
43
  return [
20
- ...((_a = featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.map((token) => {
44
+ ...((_h = featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.map((token) => {
21
45
  token.featured = true;
22
46
  return token;
23
- })) !== null && _a !== void 0 ? _a : []),
24
- ...((_c = (_b = data.tokens) === null || _b === void 0 ? void 0 : _b[selectedChainId].filter((token) => !featuredTokenAddresses.has(token.address))) !== null && _c !== void 0 ? _c : []),
47
+ })) !== null && _h !== void 0 ? _h : []),
48
+ ...((_j = filteredTokens === null || filteredTokens === void 0 ? void 0 : filteredTokens.filter((token) => !featuredTokenAddresses.has(token.address))) !== null && _j !== void 0 ? _j : []),
25
49
  ];
26
50
  }));
27
51
  return {
28
- tokens,
52
+ tokens: data,
29
53
  isLoading,
30
- isFetching,
31
54
  };
32
55
  };
package/hooks/useTools.js CHANGED
@@ -1,13 +1,19 @@
1
1
  import { useQuery } from '@tanstack/react-query';
2
2
  import { useMemo } from 'react';
3
- import { LiFi } from '../config/lifi';
3
+ import { isItemAllowed, useLiFi, useWidgetConfig } from '../providers';
4
4
  import { useSettingsStore } from '../stores';
5
5
  export const useTools = () => {
6
- const initializeTools = useSettingsStore((state) => state.initializeTools);
7
- const { data } = useQuery(['tools'], ({ signal }) => LiFi.getTools(undefined, { signal }), {
6
+ const lifi = useLiFi();
7
+ const { bridges, exchanges } = useWidgetConfig();
8
+ const { data } = useQuery(['tools'], ({ signal }) => lifi.getTools(undefined, { signal }), {
8
9
  onSuccess(data) {
9
- initializeTools('Bridges', data.bridges.map((bridge) => bridge.key));
10
- initializeTools('Exchanges', data.exchanges.map((exchange) => exchange.key));
10
+ const { initializeTools } = useSettingsStore.getState();
11
+ initializeTools('Bridges', data.bridges
12
+ .filter((bridge) => isItemAllowed(bridge.key, bridges))
13
+ .map((bridge) => bridge.key));
14
+ initializeTools('Exchanges', data.exchanges
15
+ .filter((exchange) => isItemAllowed(exchange.key, exchanges))
16
+ .map((exchange) => exchange.key));
11
17
  },
12
18
  });
13
19
  const formattedTools = useMemo(() => ({
@@ -1,3 +1,3 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- export declare const useWidgetEvents: () => EventEmitter;
1
+ import type { Emitter } from 'mitt';
2
+ import type { WidgetEvents } from '../types';
3
+ export declare const useWidgetEvents: () => Emitter<WidgetEvents>;
@@ -1,6 +1,6 @@
1
- import { EventEmitter } from 'events';
1
+ import mitt from 'mitt';
2
2
  import create from 'zustand';
3
- const emitterStore = create()(() => new EventEmitter());
3
+ const emitterStore = create()(() => mitt());
4
4
  export const useWidgetEvents = () => {
5
5
  return emitterStore();
6
6
  };
@@ -15,7 +15,6 @@
15
15
  },
16
16
  "button": {
17
17
  "connectWallet": "Connect wallet",
18
- "switchChain": "Switch chain",
19
18
  "swap": "Swap",
20
19
  "reviewSwap": "Review swap",
21
20
  "startSwap": "Start swap",
@@ -56,7 +55,6 @@
56
55
  "featuredTokens": "Featured tokens",
57
56
  "otherTokens": "Other tokens",
58
57
  "inProgress": "in progress",
59
- "couldntFindTokens": "We couldn't find tokens on this chain or you don't have any.",
60
58
  "stepSwap": "Swap",
61
59
  "stepBridge": "Bridge",
62
60
  "stepSwapAndBridge": "Swap and bridge",
@@ -92,7 +90,8 @@
92
90
  "message": {
93
91
  "routeNotFound": "Try another token combination.",
94
92
  "emptySwapHistory": "Swap history is only stored locally and will be deleted if you clear your browser data.",
95
- "emptyActiveSwaps": "Swaps in progress will appear here. Once completed, find them in swap history."
93
+ "emptyActiveSwaps": "Swaps in progress will appear here. Once completed, find them in swap history.",
94
+ "emptyTokenList": "We couldn't find tokens on {{chainName}} chain or you don't have any. Please try search again or choose another chain."
96
95
  }
97
96
  },
98
97
  "warning": {
package/i18n/index.d.ts CHANGED
@@ -18,7 +18,6 @@ export declare const resources: {
18
18
  };
19
19
  button: {
20
20
  connectWallet: string;
21
- switchChain: string;
22
21
  swap: string;
23
22
  reviewSwap: string;
24
23
  startSwap: string;
@@ -59,7 +58,6 @@ export declare const resources: {
59
58
  featuredTokens: string;
60
59
  otherTokens: string;
61
60
  inProgress: string;
62
- couldntFindTokens: string;
63
61
  stepSwap: string;
64
62
  stepBridge: string;
65
63
  stepSwapAndBridge: string;
@@ -96,6 +94,7 @@ export declare const resources: {
96
94
  routeNotFound: string;
97
95
  emptySwapHistory: string;
98
96
  emptyActiveSwaps: string;
97
+ emptyTokenList: string;
99
98
  };
100
99
  };
101
100
  warning: {
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import './fonts/inter.css';
3
+ export type { WidgetDrawer, WidgetDrawerProps } from './AppDrawer';
3
4
  export { useWidgetEvents } from './hooks';
4
5
  export * from './types';
5
6
  export declare const LiFiWidget: import("react").FC<import("./AppProvider").AppProps>;
6
- export declare const LiFiWidgetDrawer: import("react").ForwardRefExoticComponent<Pick<import("./AppDrawer").AppDrawerProps, "className" | "style" | "classes" | "slot" | "title" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "children" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "sx" | "key" | "transitionDuration" | "variant" | "open" | "anchor" | "elementRef" | "components" | "componentsProps" | "BackdropComponent" | "BackdropProps" | "closeAfterTransition" | "container" | "disableAutoFocus" | "disableEnforceFocus" | "disableEscapeKeyDown" | "disablePortal" | "disableRestoreFocus" | "disableScrollLock" | "hideBackdrop" | "keepMounted" | "onBackdropClick" | "onClose" | "config" | "elevation" | "ModalProps" | "PaperProps" | "SlideProps"> & import("react").RefAttributes<import("./AppDrawer").AppDrawerBase>>;
7
+ export declare const LiFiWidgetDrawer: import("react").ForwardRefExoticComponent<Pick<import("./AppDrawer").WidgetDrawerProps, "className" | "style" | "classes" | "slot" | "title" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "children" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "sx" | "key" | "transitionDuration" | "variant" | "open" | "anchor" | "elementRef" | "components" | "componentsProps" | "BackdropComponent" | "BackdropProps" | "closeAfterTransition" | "container" | "disableAutoFocus" | "disableEnforceFocus" | "disableEscapeKeyDown" | "disablePortal" | "disableRestoreFocus" | "disableScrollLock" | "hideBackdrop" | "keepMounted" | "onBackdropClick" | "onClose" | "config" | "elevation" | "ModalProps" | "PaperProps" | "SlideProps"> & import("react").RefAttributes<import("./AppDrawer").WidgetDrawer>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/widget",
3
- "version": "1.16.0",
3
+ "version": "1.17.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",
@@ -45,21 +45,22 @@
45
45
  "@lifi/sdk": "^1.5.0",
46
46
  "@lifi/wallet-management": "^1.1.9",
47
47
  "@mui/icons-material": "^5.10.3",
48
- "@mui/lab": "^5.0.0-alpha.98",
49
- "@mui/material": "^5.10.4",
48
+ "@mui/lab": "^5.0.0-alpha.99",
49
+ "@mui/material": "^5.10.5",
50
50
  "@sentry/integrations": "^7.12.1",
51
51
  "@sentry/react": "^7.12.1",
52
52
  "@sentry/tracing": "^7.12.1",
53
- "@tanstack/react-query": "^4.2.3",
54
- "@tanstack/react-virtual": "^3.0.0-beta.17",
53
+ "@tanstack/react-query": "^4.3.4",
54
+ "@tanstack/react-virtual": "^3.0.0-beta.18",
55
55
  "big.js": "^6.2.1",
56
- "events": "^3.3.0",
57
56
  "i18next": "^21.9.1",
58
57
  "immer": "^9.0.15",
58
+ "microdiff": "^1.3.1",
59
+ "mitt": "^3.0.0",
59
60
  "react": "^18.2.0",
60
61
  "react-dom": "^18.2.0",
61
- "react-hook-form": "^7.34.2",
62
- "react-i18next": "^11.18.5",
62
+ "react-hook-form": "^7.35.0",
63
+ "react-i18next": "^11.18.6",
63
64
  "react-router-dom": "^6.3.0",
64
65
  "react-timer-hook": "^3.0.5",
65
66
  "zustand": "^4.1.1"
@@ -28,5 +28,5 @@ export const MainSwapButton = () => {
28
28
  });
29
29
  }
30
30
  });
31
- return (_jsx(SwapButton, { onClick: handleClick, currentRoute: currentRoute, disable: isLoading || isFetching || !currentRoute || isValidating || !isValid }));
31
+ return (_jsx(SwapButton, { onClick: handleClick, currentRoute: currentRoute, disable: isLoading || isFetching || isValidating || !isValid }));
32
32
  };
@@ -2,12 +2,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box, Typography } from '@mui/material';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { Switch } from '../../components/Switch';
5
- import { useSetSettings, useSettings } from '../../stores';
5
+ import { useSettings, useSettingsStore } 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 [setValue] = useSetSettings();
10
+ const setValue = useSettingsStore((state) => state.setValue);
11
11
  const { advancedPreferences } = useSettings(['advancedPreferences']);
12
12
  const handleAdvancedPreferences = (_, checked) => {
13
13
  setValue('advancedPreferences', checked);
@@ -4,10 +4,10 @@ import { FormControl, MenuItem } from '@mui/material';
4
4
  import { useTranslation } from 'react-i18next';
5
5
  import { Card, CardTitle } from '../../components/Card';
6
6
  import { Select } from '../../components/Select';
7
- import { useSetSettings, useSettings } from '../../stores';
7
+ import { useSettings, useSettingsStore } from '../../stores';
8
8
  export const GasPriceSelect = () => {
9
9
  const { t } = useTranslation();
10
- const [setValue] = useSetSettings();
10
+ const setValue = useSettingsStore((state) => state.setValue);
11
11
  const { gasPrice } = useSettings(['gasPrice']);
12
12
  return (_jsxs(Card, 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
  };
@@ -5,10 +5,10 @@ import { FormControl, MenuItem } from '@mui/material';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { Card, CardTitle } from '../../components/Card';
7
7
  import { Select } from '../../components/Select';
8
- import { useSetSettings, useSettings } from '../../stores';
8
+ import { useSettings, useSettingsStore } from '../../stores';
9
9
  export const RoutePrioritySelect = () => {
10
10
  const { t } = useTranslation();
11
- const [setValue] = useSetSettings();
11
+ const setValue = useSettingsStore((state) => state.setValue);
12
12
  const { routePriority } = useSettings(['routePriority']);
13
13
  return (_jsxs(Card, { 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) => {
14
14
  const tag = t(`swap.tags.${order.toUpperCase()}`);
@@ -2,10 +2,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box, Typography } from '@mui/material';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { Switch } from '../../components/Switch';
5
- import { useSetSettings, useSettings } from '../../stores';
5
+ import { useSettings, useSettingsStore } from '../../stores';
6
6
  export const ShowDestinationWallet = () => {
7
7
  const { t } = useTranslation();
8
- const [setValue] = useSetSettings();
8
+ const setValue = useSettingsStore((state) => state.setValue);
9
9
  const { showDestinationWallet } = useSettings(['showDestinationWallet']);
10
10
  const onChange = (_, checked) => {
11
11
  setValue('showDestinationWallet', checked);
@@ -4,12 +4,12 @@ import { useRef } from 'react';
4
4
  import { useTranslation } from 'react-i18next';
5
5
  import { Card, CardTitle } from '../../components/Card';
6
6
  import { Input } from '../../components/Input';
7
- import { useSetSettings, useSettings } from '../../stores';
7
+ import { useSettings, useSettingsStore } from '../../stores';
8
8
  import { formatSlippage } from '../../utils';
9
9
  export const SlippageInput = () => {
10
10
  const { t } = useTranslation();
11
- const [setValue] = useSetSettings();
12
11
  const { slippage } = useSettings(['slippage']);
12
+ const setValue = useSettingsStore((state) => state.setValue);
13
13
  const defaultValue = useRef(slippage);
14
14
  const handleChange = (event) => {
15
15
  const { value } = event.target;
@@ -16,7 +16,7 @@ import { useLocation } from 'react-router-dom';
16
16
  import shallow from 'zustand/shallow';
17
17
  import { Card, CardTitle } from '../../components/Card';
18
18
  import { Dialog } from '../../components/Dialog';
19
- import { useSetHeaderAction } from '../../components/Header';
19
+ 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';
@@ -26,7 +26,6 @@ export const SwapDetailsPage = () => {
26
26
  var _a, _b;
27
27
  const { t } = useTranslation();
28
28
  const { navigateBack } = useNavigateBack();
29
- const setHeaderAction = useSetHeaderAction();
30
29
  const { state } = useLocation();
31
30
  const [routeExecution, deleteRoute] = useRouteStore((store) => [store.routes[state === null || state === void 0 ? void 0 : state.routeId], store.deleteRoute], shallow);
32
31
  const [open, setOpen] = useState(false);
@@ -44,8 +43,8 @@ export const SwapDetailsPage = () => {
44
43
  yield navigator.clipboard.writeText((_c = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.id) !== null && _c !== void 0 ? _c : '');
45
44
  });
46
45
  useEffect(() => {
47
- return setHeaderAction(_jsx(IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "end", onClick: toggleDialog }, { children: _jsx(DeleteIcon, {}) })));
48
- }, [setHeaderAction, toggleDialog]);
46
+ return useHeaderActionStore.getState().setAction(_jsx(IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "end", onClick: toggleDialog }, { children: _jsx(DeleteIcon, {}) })));
47
+ }, [toggleDialog]);
49
48
  const startedAt = new Date((_b = (_a = routeExecution === null || routeExecution === void 0 ? void 0 : routeExecution.route.steps[0].execution) === null || _a === void 0 ? void 0 : _a.process[0].startedAt) !== null && _b !== void 0 ? _b : 0);
50
49
  return (_jsxs(Container, { children: [_jsxs(Box, Object.assign({ sx: {
51
50
  display: 'flex',
@@ -4,7 +4,7 @@ import { Button, Container, DialogActions, DialogContent, DialogContentText, Dia
4
4
  import { useCallback, useEffect, useState } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { Dialog } from '../../components/Dialog';
7
- import { useSetHeaderAction } from '../../components/Header';
7
+ import { useHeaderActionStore } from '../../components/Header';
8
8
  import { useWallet } from '../../providers';
9
9
  import { useRouteStore } from '../../stores';
10
10
  import { useSwapHistory } from '../../stores/route';
@@ -15,14 +15,13 @@ export const SwapHistoryPage = () => {
15
15
  const { account } = useWallet();
16
16
  const swaps = useSwapHistory(account.address);
17
17
  const deleteRoutes = useRouteStore((store) => store.deleteRoutes);
18
- const setHeaderAction = useSetHeaderAction();
19
18
  const [open, setOpen] = useState(false);
20
19
  const toggleDialog = useCallback(() => {
21
20
  setOpen((open) => !open);
22
21
  }, []);
23
22
  useEffect(() => {
24
- return setHeaderAction(_jsx(IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "end", onClick: toggleDialog }, { children: _jsx(DeleteIcon, {}) })));
25
- }, [setHeaderAction, toggleDialog]);
23
+ return useHeaderActionStore.getState().setAction(_jsx(IconButton, Object.assign({ size: "medium", "aria-label": "settings", edge: "end", onClick: toggleDialog }, { children: _jsx(DeleteIcon, {}) })));
24
+ }, [toggleDialog]);
26
25
  if (!swaps.length) {
27
26
  return _jsx(SwapHistoryEmpty, {});
28
27
  }
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
11
  import { Box, Button } from '@mui/material';
3
12
  import { Fragment } from 'react';
@@ -22,7 +31,7 @@ export const SwapPage = () => {
22
31
  navigateBack();
23
32
  deleteRoute();
24
33
  };
25
- const handleSwapClick = () => {
34
+ const handleSwapClick = () => __awaiter(void 0, void 0, void 0, function* () {
26
35
  if (status === 'idle') {
27
36
  executeRoute();
28
37
  setValue(SwapFormKey.FromAmount, '');
@@ -30,7 +39,7 @@ export const SwapPage = () => {
30
39
  if (status === 'error') {
31
40
  restartRoute();
32
41
  }
33
- };
42
+ });
34
43
  // eslint-disable-next-line consistent-return
35
44
  const getSwapButtonText = () => {
36
45
  if (status === 'idle') {