@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
@@ -1,5 +1,17 @@
1
+ import type { Process, Route } from '@lifi/sdk';
1
2
  export declare enum WidgetEvent {
2
- SwapStarted = "swapStarted",
3
- SwapCompleted = "swapCompleted",
4
- SwapFailed = "swapFailed"
3
+ RouteExecutionStarted = "routeExecutionStarted",
4
+ RouteExecutionUpdated = "routeExecutionUpdated",
5
+ RouteExecutionCompleted = "routeExecutionCompleted",
6
+ RouteExecutionFailed = "routeExecutionFailed"
7
+ }
8
+ export declare type WidgetEvents = {
9
+ routeExecutionStarted: Route;
10
+ routeExecutionUpdated: RouteExecutionUpdate;
11
+ routeExecutionCompleted: Route;
12
+ routeExecutionFailed: RouteExecutionUpdate;
13
+ };
14
+ export interface RouteExecutionUpdate {
15
+ route: Route;
16
+ process: Process;
5
17
  }
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WidgetEvent = void 0;
4
4
  var WidgetEvent;
5
5
  (function (WidgetEvent) {
6
- WidgetEvent["SwapStarted"] = "swapStarted";
7
- WidgetEvent["SwapCompleted"] = "swapCompleted";
8
- WidgetEvent["SwapFailed"] = "swapFailed";
6
+ WidgetEvent["RouteExecutionStarted"] = "routeExecutionStarted";
7
+ WidgetEvent["RouteExecutionUpdated"] = "routeExecutionUpdated";
8
+ WidgetEvent["RouteExecutionCompleted"] = "routeExecutionCompleted";
9
+ WidgetEvent["RouteExecutionFailed"] = "routeExecutionFailed";
9
10
  })(WidgetEvent = exports.WidgetEvent || (exports.WidgetEvent = {}));
@@ -17,33 +17,40 @@ export interface WidgetWalletManagement {
17
17
  addChain?(chainId: number): Promise<boolean>;
18
18
  signer?: Signer;
19
19
  }
20
- interface WidgetConfigBase {
21
- fromAmount?: number | string;
20
+ export interface WidgetConfig {
21
+ fromChain?: `${ChainKey}` | number;
22
+ toChain?: `${ChainKey}` | number;
23
+ fromToken?: string;
24
+ toToken?: string;
22
25
  toAddress?: string;
23
- containerStyle?: CSSProperties;
24
- theme?: ThemeConfig;
26
+ fromAmount?: number | string;
25
27
  appearance?: Appearance;
28
+ theme?: ThemeConfig;
29
+ containerStyle?: CSSProperties;
26
30
  disableAppearance?: boolean;
27
31
  disableTelemetry?: boolean;
28
- walletManagement?: WidgetWalletManagement;
29
- integrator?: string;
32
+ /** @deprecated Use chains.deny instead */
30
33
  disabledChains?: number[];
34
+ /** @deprecated Use tokens.featured instead */
31
35
  featuredTokens?: Token[];
36
+ integrator?: string;
37
+ walletManagement?: WidgetWalletManagement;
32
38
  sdkConfig?: ConfigUpdate;
39
+ bridges?: {
40
+ allow?: string[];
41
+ deny?: string[];
42
+ };
43
+ exchanges?: {
44
+ allow?: string[];
45
+ deny?: string[];
46
+ };
47
+ chains?: {
48
+ allow?: number[];
49
+ deny?: number[];
50
+ };
51
+ tokens?: {
52
+ featured?: Token[];
53
+ allow?: Token[];
54
+ deny?: (Partial<Token> & Pick<Token, 'address' | 'chainId'>)[];
55
+ };
33
56
  }
34
- declare type WidgetFromTokenConfig = {
35
- fromChain: `${ChainKey}` | number;
36
- fromToken?: string;
37
- } | {
38
- fromChain?: never;
39
- fromToken?: never;
40
- };
41
- declare type WidgetToTokenConfig = {
42
- toChain: `${ChainKey}` | number;
43
- toToken?: string;
44
- } | {
45
- toChain?: never;
46
- toToken?: never;
47
- };
48
- export declare type WidgetConfig = WidgetConfigBase & WidgetFromTokenConfig & WidgetToTokenConfig;
49
- export {};
@@ -1,3 +1,3 @@
1
1
  import type { Theme } from '@mui/material';
2
2
  export declare const getContrastAlphaColor: (theme: Theme, alpha: string | number) => string;
3
- export declare const getContrastTextColor: (theme: Theme, background?: string) => "#fff" | "#000";
3
+ export declare const getContrastTextColor: (theme: Theme, background?: string) => "#000" | "#fff";
@@ -3,7 +3,7 @@ import { Box, Container, ScopedCssBaseline } from '@mui/material';
3
3
  import { styled } from '@mui/material/styles';
4
4
  import { useLayoutEffect, useRef } from 'react';
5
5
  import { useLocation } from 'react-router-dom';
6
- import { useWidgetConfig } from '../providers/WidgetProvider';
6
+ import { useWidgetConfig } from '../providers';
7
7
  import { ElementId } from '../utils';
8
8
  const CssBaselineContainer = styled(ScopedCssBaseline)(({ theme }) => ({
9
9
  // height: '100%',
@@ -1,15 +1,15 @@
1
1
  import { Box } from '@mui/material';
2
2
  import { styled } from '@mui/material/styles';
3
3
  import { Card } from '../../components/Card';
4
- export const ChainCard = styled(Card)(({ theme }) => ({
4
+ export const ChainCard = styled(Card)({
5
5
  display: 'grid',
6
6
  placeItems: 'center',
7
- width: 56,
7
+ minWidth: 56,
8
8
  height: 56,
9
- }));
9
+ });
10
10
  export const ChainContainer = styled(Box)(({ theme }) => ({
11
11
  display: 'grid',
12
- gridTemplateColumns: 'repeat(auto-fit, 56px)',
12
+ gridTemplateColumns: 'repeat(auto-fit, minmax(56px, 1fr))',
13
13
  gridAutoRows: '56px',
14
14
  justifyContent: 'space-between',
15
15
  gap: theme.spacing(1.5),
@@ -1,6 +1,6 @@
1
1
  import type { EVMChain } from '@lifi/sdk';
2
- import type { SwapFormDirection } from '../../providers';
3
- export declare const useChainSelect: (formType: SwapFormDirection) => {
2
+ import type { SwapFormType } from '../../providers';
3
+ export declare const useChainSelect: (formType: SwapFormType) => {
4
4
  chains: EVMChain[] | undefined;
5
5
  getChains: () => EVMChain[];
6
6
  setCurrentChain: (chainId: number) => void;
@@ -20,15 +20,15 @@ export const GasSufficiencyMessage = (_a) => {
20
20
  var { route } = _a, props = __rest(_a, ["route"]);
21
21
  const { t } = useTranslation();
22
22
  const { insufficientFunds, insufficientGas } = useGasSufficiency(route);
23
- if (!insufficientFunds && !insufficientGas.length) {
23
+ if (!insufficientFunds && !(insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length)) {
24
24
  return null;
25
25
  }
26
26
  return (_jsxs(MessageCard, Object.assign({}, props, { children: [_jsx(WarningIcon, { sx: {
27
27
  marginTop: 2,
28
28
  marginLeft: 2,
29
- } }), _jsxs(Box, { children: [insufficientGas.length ? (_jsx(CardTitle, { children: t(`swap.warning.title.insufficientGas`) })) : null, insufficientFunds ? (_jsx(Typography, Object.assign({ variant: "body2", px: 2, pb: insufficientGas.length ? 0 : 2, pt: insufficientGas.length ? 1 : 2 }, { children: insufficientFunds
29
+ } }), _jsxs(Box, { children: [(insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length) ? (_jsx(CardTitle, { children: t(`swap.warning.title.insufficientGas`) })) : null, insufficientFunds ? (_jsx(Typography, Object.assign({ variant: "body2", px: 2, pb: (insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length) ? 0 : 2, pt: (insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length) ? 1 : 2 }, { children: insufficientFunds
30
30
  ? t(`swap.warning.message.insufficientFunds`)
31
- : null }))) : null, insufficientGas.length ? (_jsx(Typography, Object.assign({ variant: "body2", px: 2, pt: 1 }, { children: t(`swap.warning.message.insufficientGas`) }))) : null, insufficientGas.length
31
+ : null }))) : null, (insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length) ? (_jsx(Typography, Object.assign({ variant: "body2", px: 2, pt: 1 }, { children: t(`swap.warning.message.insufficientGas`) }))) : null, (insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length)
32
32
  ? insufficientGas.map((item, index) => {
33
33
  var _a, _b;
34
34
  return (_jsx(Typography, Object.assign({ variant: "body2", px: 2, pb: insufficientGas.length - 1 === index ? 2 : 0, pt: 0.5 }, { children: t(`swap.tokenOnChainAmount`, {
@@ -1,6 +1,4 @@
1
- /// <reference types="react" />
2
1
  import type { HeaderActionStore } from './types';
3
2
  export declare const useHeaderActionStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<HeaderActionStore>, "setState"> & {
4
3
  setState(nextStateOrUpdater: HeaderActionStore | Partial<HeaderActionStore> | ((state: import("immer/dist/internal").WritableDraft<HeaderActionStore>) => void), shouldReplace?: boolean | undefined): void;
5
4
  }>;
6
- export declare const useSetHeaderAction: () => (element?: import("react").ReactNode) => () => void;
@@ -14,6 +14,3 @@ export const useHeaderActionStore = create()(immer((set, get) => ({
14
14
  });
15
15
  },
16
16
  })));
17
- export const useSetHeaderAction = () => {
18
- return useHeaderActionStore((state) => state.setAction);
19
- };
@@ -3,7 +3,7 @@ import { Box, useMediaQuery } from '@mui/material';
3
3
  import { useWatch } from 'react-hook-form';
4
4
  import { ReverseTokensButton } from '../components/ReverseTokensButton';
5
5
  import { SelectTokenButton } from '../components/SelectTokenButton';
6
- import { SwapFormKey } from '../providers/SwapFormProvider';
6
+ import { SwapFormKey } from '../providers';
7
7
  export const SelectChainAndToken = (props) => {
8
8
  const prefersNarrowView = useMediaQuery((theme) => theme.breakpoints.down('sm'));
9
9
  const [fromChain, toChain, fromToken, toToken] = useWatch({
@@ -8,51 +8,33 @@ 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 { ChainId } from '@lifi/sdk';
12
11
  import { Button } from '@mui/material';
13
- import { useWatch } from 'react-hook-form';
14
12
  import { useTranslation } from 'react-i18next';
15
13
  import { useNavigate } from 'react-router-dom';
16
- import { useChains, useGasSufficiency } from '../../hooks';
17
- import { SwapFormKeyHelper, useWallet, useWidgetConfig } from '../../providers';
14
+ import { useGasSufficiency } from '../../hooks';
15
+ import { useWallet, useWidgetConfig } from '../../providers';
18
16
  import { navigationRoutes } from '../../utils';
19
17
  export const SwapButton = ({ onClick, currentRoute, text, disable, }) => {
20
- var _a;
21
18
  const { t } = useTranslation();
22
19
  const navigate = useNavigate();
23
- const { getChainById } = useChains();
24
20
  const config = useWidgetConfig();
25
- const { account, switchChain, connect: walletConnect } = useWallet();
21
+ const { account, connect } = useWallet();
26
22
  const { insufficientFunds, insufficientGas } = useGasSufficiency(currentRoute);
27
- const [chainId] = useWatch({
28
- name: [SwapFormKeyHelper.getChainKey('from')],
29
- });
30
- // Allow switching chain only if execution is not started
31
- const switchChainAllowed = ((_a = getChainById(chainId || ChainId.ETH)) === null || _a === void 0 ? void 0 : _a.id) !== account.chainId &&
32
- currentRoute &&
33
- !currentRoute.steps.some((step) => step.execution);
34
23
  const handleSwapButtonClick = () => __awaiter(void 0, void 0, void 0, function* () {
35
24
  if (!account.isActive) {
36
25
  if (config.walletManagement) {
37
- yield walletConnect();
26
+ yield connect();
38
27
  }
39
28
  else {
40
29
  navigate(navigationRoutes.selectWallet);
41
30
  }
42
31
  }
43
- else if (switchChainAllowed) {
44
- yield switchChain(chainId);
45
- // check that the current route exists in the up to date route list
46
- }
47
32
  else {
48
33
  onClick === null || onClick === void 0 ? void 0 : onClick();
49
34
  }
50
35
  });
51
36
  const getButtonText = () => {
52
37
  if (account.isActive) {
53
- if (switchChainAllowed) {
54
- return t(`button.switchChain`);
55
- }
56
38
  if (!currentRoute) {
57
39
  return t(`button.swap`);
58
40
  }
@@ -60,7 +42,5 @@ export const SwapButton = ({ onClick, currentRoute, text, disable, }) => {
60
42
  }
61
43
  return t(`button.connectWallet`);
62
44
  };
63
- return (_jsx(Button, Object.assign({ variant: "contained", color: account.isActive ? 'primary' : 'success', onClick: handleSwapButtonClick, disabled: currentRoute &&
64
- !switchChainAllowed &&
65
- (insufficientFunds || !!insufficientGas.length || disable), fullWidth: true }, { children: getButtonText() })));
45
+ return (_jsx(Button, Object.assign({ variant: "contained", color: account.isActive ? 'primary' : 'success', onClick: handleSwapButtonClick, disabled: insufficientFunds || !!(insufficientGas === null || insufficientGas === void 0 ? void 0 : insufficientGas.length) || disable, fullWidth: true }, { children: getButtonText() })));
66
46
  };
@@ -50,5 +50,5 @@ export const TokenList = ({ formType, height, onClick, }) => {
50
50
  }
51
51
  onClick === null || onClick === void 0 ? void 0 : onClick();
52
52
  }, [formType, getValues, onClick, setValue]);
53
- return (_jsxs(Box, Object.assign({ ref: parentRef, style: { height, overflow: 'auto' } }, { children: [!tokens.length && !isLoading ? _jsx(TokenNotFound, {}) : null, _jsx(VirtualizedTokenList, { tokens: tokens, featuredTokensLength: featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.length, scrollElementRef: parentRef, chainId: selectedChainId, isLoading: isLoading, isBalanceLoading: isBalanceLoading, showBalance: account.isActive, showFeatured: !tokenSearchFilter, onClick: handleTokenClick })] })));
53
+ return (_jsxs(Box, Object.assign({ ref: parentRef, style: { height, overflow: 'auto' } }, { children: [!tokens.length && !isLoading ? (_jsx(TokenNotFound, { formType: formType })) : null, _jsx(VirtualizedTokenList, { tokens: tokens, featuredTokensLength: featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.length, scrollElementRef: parentRef, chainId: selectedChainId, isLoading: isLoading, isBalanceLoading: isBalanceLoading, showBalance: account.isActive, showFeatured: !tokenSearchFilter, onClick: handleTokenClick })] })));
54
54
  };
@@ -4,7 +4,8 @@ import { styled } from '@mui/material/styles';
4
4
  import { getContrastAlphaColor } from '../../utils';
5
5
  export const ListItemButton = styled(MuiListItemButton)(({ theme }) => ({
6
6
  borderRadius: theme.shape.borderRadiusSecondary,
7
- paddingLeft: theme.spacing(2),
7
+ paddingLeft: theme.spacing(1.5),
8
+ paddingRight: theme.spacing(1.5),
8
9
  height: 64,
9
10
  width: '100%',
10
11
  '&:hover': {
@@ -18,8 +19,8 @@ export const ListItem = styled(MuiListItem)(({ theme }) => ({
18
19
  height: 64,
19
20
  flexDirection: 'column',
20
21
  alignItems: 'flex-start',
21
- padding: theme.spacing(0, 3),
22
+ padding: theme.spacing(0, 1.5),
22
23
  [`.${listItemSecondaryActionClasses.root}`]: {
23
- right: theme.spacing(5),
24
+ right: theme.spacing(3),
24
25
  },
25
26
  }));
@@ -16,7 +16,7 @@ export const TokenListItem = memo(({ onClick, size, start, token, showBalance, i
16
16
  }) }))) : null] })))) : null] })), endAdornment] })));
17
17
  });
18
18
  export const TokenListItemSkeleton = () => {
19
- return (_jsxs(ListItem, Object.assign({ secondaryAction: _jsx(TokenAmountSkeleton, {}), disablePadding: true, sx: { position: 'relative', flexDirection: 'row', alignItems: 'center' } }, { children: [_jsx(ListItemAvatar, { children: _jsx(Skeleton, { variant: "circular", width: 32, height: 32, sx: { marginLeft: 2, marginRight: 2 } }) }), _jsx(ListItemText, { primary: _jsx(Skeleton, { variant: "text", width: 48, height: 20 }), secondary: _jsx(Skeleton, { variant: "text", width: 96, height: 20 }) })] })));
19
+ return (_jsxs(ListItem, Object.assign({ secondaryAction: _jsx(TokenAmountSkeleton, {}), disablePadding: true, sx: { position: 'relative', flexDirection: 'row', alignItems: 'center' } }, { children: [_jsx(ListItemAvatar, { children: _jsx(Skeleton, { variant: "circular", width: 32, height: 32, sx: { marginLeft: 1.5, marginRight: 2 } }) }), _jsx(ListItemText, { primary: _jsx(Skeleton, { variant: "text", width: 48, height: 20 }), secondary: _jsx(Skeleton, { variant: "text", width: 96, height: 20 }) })] })));
20
20
  };
21
21
  export const TokenAmountSkeleton = () => {
22
22
  return (_jsxs(Box, Object.assign({ sx: {
@@ -1,2 +1,3 @@
1
1
  /// <reference types="react" />
2
- export declare const TokenNotFound: React.FC;
2
+ import type { SwapFormTypeProps } from '../../providers';
3
+ export declare const TokenNotFound: React.FC<SwapFormTypeProps>;
@@ -1,9 +1,17 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { SearchOff as SearchOffIcon } from '@mui/icons-material';
3
3
  import { Box, Typography } from '@mui/material';
4
+ import { useWatch } from 'react-hook-form';
4
5
  import { useTranslation } from 'react-i18next';
5
- export const TokenNotFound = () => {
6
+ import { useChains } from '../../hooks';
7
+ import { SwapFormKeyHelper } from '../../providers';
8
+ export const TokenNotFound = ({ formType }) => {
9
+ var _a;
6
10
  const { t } = useTranslation();
11
+ const [selectedChainId] = useWatch({
12
+ name: [SwapFormKeyHelper.getChainKey(formType)],
13
+ });
14
+ const { getChainById } = useChains();
7
15
  return (_jsxs(Box, Object.assign({ sx: {
8
16
  display: 'flex',
9
17
  justifyContent: 'center',
@@ -11,5 +19,7 @@ export const TokenNotFound = () => {
11
19
  flexDirection: 'column',
12
20
  flex: 1,
13
21
  padding: 3,
14
- } }, { children: [_jsx(Typography, Object.assign({ fontSize: 48, lineHeight: 1 }, { children: _jsx(SearchOffIcon, { fontSize: "inherit" }) })), _jsx(Typography, Object.assign({ fontSize: 14, color: "text.secondary", textAlign: "center", mt: 2, px: 2 }, { children: t('swap.couldntFindTokens') }))] })));
22
+ } }, { children: [_jsx(Typography, Object.assign({ fontSize: 48, lineHeight: 1 }, { children: _jsx(SearchOffIcon, { fontSize: "inherit" }) })), _jsx(Typography, Object.assign({ fontSize: 14, color: "text.secondary", textAlign: "center", mt: 2, px: 2 }, { children: t('swap.info.message.emptyTokenList', {
23
+ chainName: (_a = getChainById(selectedChainId)) === null || _a === void 0 ? void 0 : _a.name,
24
+ }) }))] })));
15
25
  };
@@ -1,9 +1,9 @@
1
1
  import type { TokenAmount } from '@lifi/sdk';
2
2
  import type { MutableRefObject } from 'react';
3
- import type { SwapFormDirection } from '../../providers';
3
+ import type { SwapFormType } from '../../providers';
4
4
  import type { Token } from '../../types';
5
5
  export interface TokenListProps {
6
- formType: SwapFormDirection;
6
+ formType: SwapFormType;
7
7
  height: number;
8
8
  onClick?(): void;
9
9
  }
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "1.16.0";
2
+ export declare const version = "1.17.1";
package/config/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/widget';
2
- export const version = '1.16.0';
2
+ export const version = '1.17.1';
@@ -9,24 +9,37 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { useQuery } from '@tanstack/react-query';
11
11
  import { useCallback } from 'react';
12
- import { LiFi } from '../config/lifi';
13
- import { useWidgetConfig } from '../providers/WidgetProvider';
14
- import { useSetChainOrder } from '../stores/chains';
12
+ import { useFormContext } from 'react-hook-form';
13
+ import { isItemAllowed, SwapFormKey, useLiFi, useWidgetConfig, } from '../providers';
14
+ import { useChainOrderStore } from '../stores/chains';
15
15
  export const useChains = () => {
16
- const { disabledChains } = useWidgetConfig();
17
- const [, initializeChains] = useSetChainOrder();
16
+ const { disabledChains, chains } = useWidgetConfig();
17
+ const lifi = useLiFi();
18
+ const { getValues, setValue } = useFormContext();
18
19
  const { data, isLoading } = useQuery(['chains'], () => __awaiter(void 0, void 0, void 0, function* () {
19
- const chains = yield LiFi.getChains();
20
- const filteredChains = chains.filter((chain) => !(disabledChains === null || disabledChains === void 0 ? void 0 : disabledChains.includes(chain.id)));
21
- initializeChains(filteredChains.map((chain) => chain.id));
22
- return filteredChains;
20
+ const availableChains = yield lifi.getChains();
21
+ const filteredChains = availableChains.filter((chain) => isItemAllowed(chain.id, chains, disabledChains));
22
+ const chainOrder = useChainOrderStore
23
+ .getState()
24
+ .initializeChains(filteredChains.map((chain) => chain.id));
25
+ const [fromChainValue, toChainValue] = getValues([
26
+ SwapFormKey.FromChain,
27
+ SwapFormKey.ToChain,
28
+ ]);
29
+ if (!fromChainValue) {
30
+ setValue(SwapFormKey.FromChain, chainOrder[0]);
31
+ }
32
+ if (!toChainValue) {
33
+ setValue(SwapFormKey.ToChain, chainOrder[0]);
34
+ }
35
+ return { availableChains, filteredChains };
23
36
  }));
24
37
  const getChainById = useCallback((chainId) => {
25
- const chain = data === null || data === void 0 ? void 0 : data.find((chain) => chain.id === chainId);
38
+ const chain = data === null || data === void 0 ? void 0 : data.availableChains.find((chain) => chain.id === chainId);
26
39
  // if (!chain) {
27
40
  // throw new Error('Chain not found or chainId is invalid.');
28
41
  // }
29
42
  return chain;
30
43
  }, [data]);
31
- return { chains: data, getChainById, isLoading };
44
+ return { chains: data === null || data === void 0 ? void 0 : data.filteredChains, getChainById, isLoading };
32
45
  };
@@ -1 +1 @@
1
- export declare const useFeaturedTokens: (selectedChainId: number) => import("@lifi/types").Token[] | undefined;
1
+ export declare const useFeaturedTokens: (selectedChainId?: number) => import("@lifi/types").Token[];
@@ -1,6 +1,9 @@
1
1
  import { useMemo } from 'react';
2
- import { useWidgetConfig } from '../providers/WidgetProvider';
2
+ import { useWidgetConfig } from '../providers';
3
3
  export const useFeaturedTokens = (selectedChainId) => {
4
- const { featuredTokens } = useWidgetConfig();
5
- return useMemo(() => featuredTokens === null || featuredTokens === void 0 ? void 0 : featuredTokens.filter((token) => token.chainId === selectedChainId), [featuredTokens, selectedChainId]);
4
+ const { featuredTokens, tokens } = useWidgetConfig();
5
+ return useMemo(() => {
6
+ var _a;
7
+ return [...((_a = tokens === null || tokens === void 0 ? void 0 : tokens.featured) !== null && _a !== void 0 ? _a : []), ...(featuredTokens !== null && featuredTokens !== void 0 ? featuredTokens : [])].filter((token) => token.chainId === selectedChainId);
8
+ }, [featuredTokens, selectedChainId, tokens === null || tokens === void 0 ? void 0 : tokens.featured]);
6
9
  };
@@ -9,7 +9,7 @@ interface GasSufficiency {
9
9
  chain?: EVMChain;
10
10
  }
11
11
  export declare const useGasSufficiency: (route?: Route) => {
12
- insufficientGas: GasSufficiency[];
12
+ insufficientGas: GasSufficiency[] | undefined;
13
13
  insufficientFunds: boolean;
14
14
  };
15
15
  export {};
@@ -1,11 +1,20 @@
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 Big from 'big.js';
2
- import { useMemo } from 'react';
11
+ import { useCallback, useEffect, useMemo, useState } from 'react';
3
12
  import { useWatch } from 'react-hook-form';
4
13
  import { useChains, useDebouncedWatch } from '.';
5
- import { SwapFormKey, SwapFormKeyHelper } from '../providers/SwapFormProvider';
6
- import { useWallet } from '../providers/WalletProvider';
14
+ import { SwapFormKey, SwapFormKeyHelper, useLiFi, useWallet, } from '../providers';
7
15
  import { useTokenBalances } from './useTokenBalances';
8
16
  export const useGasSufficiency = (route) => {
17
+ const lifi = useLiFi();
9
18
  const { account } = useWallet();
10
19
  const [fromChainId, toChainId, fromToken] = useWatch({
11
20
  name: [
@@ -17,20 +26,13 @@ export const useGasSufficiency = (route) => {
17
26
  const fromAmount = useDebouncedWatch(SwapFormKey.FromAmount, 250);
18
27
  const { getChainById } = useChains();
19
28
  const { tokensWithBalance: fromChainTokenBalances } = useTokenBalances(fromChainId);
20
- const { tokensWithBalance: toChainTokenBalances } = useTokenBalances(toChainId);
21
- const insufficientGas = useMemo(() => {
29
+ const [insufficientGas, setInsufficientGas] = useState();
30
+ const checkInsufficientGas = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
22
31
  var _a;
23
- if (!account.isActive ||
24
- !route ||
25
- !fromAmount ||
26
- !fromChainTokenBalances ||
27
- !toChainTokenBalances) {
28
- return [];
32
+ if (!account.isActive || !route || !fromAmount) {
33
+ setInsufficientGas(undefined);
34
+ return;
29
35
  }
30
- const tokenBalancesByChain = {
31
- [fromChainId]: fromChainTokenBalances,
32
- [toChainId]: toChainTokenBalances,
33
- };
34
36
  const gasCosts = route.steps.reduce((groupedGasCosts, step) => {
35
37
  if (step.estimate.gasCosts) {
36
38
  const { token } = step.estimate.gasCosts[0];
@@ -55,30 +57,36 @@ export const useGasSufficiency = (route) => {
55
57
  route.fromToken.address === gasCosts[fromChainId].token.address) {
56
58
  gasCosts[fromChainId].tokenAmount = (_a = gasCosts[fromChainId]) === null || _a === void 0 ? void 0 : _a.gasAmount.plus(Big(fromAmount));
57
59
  }
60
+ const tokenBalances = yield lifi.getTokenBalances(account.address, Object.values(gasCosts).map((item) => item.token));
61
+ if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
62
+ setInsufficientGas(undefined);
63
+ return;
64
+ }
58
65
  [fromChainId, toChainId].forEach((chainId) => {
59
- var _a, _b, _c, _d, _e, _f, _g;
66
+ var _a, _b, _c, _d, _e, _f;
60
67
  if (gasCosts[chainId]) {
61
- const gasTokenBalance = Big((_c = (_b = (_a = tokenBalancesByChain[chainId]) === null || _a === void 0 ? void 0 : _a.find((t) => t.address === gasCosts[chainId].token.address)) === null || _b === void 0 ? void 0 : _b.amount) !== null && _c !== void 0 ? _c : 0);
68
+ const gasTokenBalance = Big((_b = (_a = tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.find((t) => t.chainId === gasCosts[chainId].token.chainId &&
69
+ t.address === gasCosts[chainId].token.address)) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0);
62
70
  const insufficientFromChainGas = gasTokenBalance.lte(0) ||
63
- gasTokenBalance.lt((_d = gasCosts[chainId].gasAmount) !== null && _d !== void 0 ? _d : Big(0)) ||
64
- gasTokenBalance.lt((_e = gasCosts[chainId].tokenAmount) !== null && _e !== void 0 ? _e : Big(0));
71
+ gasTokenBalance.lt((_c = gasCosts[chainId].gasAmount) !== null && _c !== void 0 ? _c : Big(0)) ||
72
+ gasTokenBalance.lt((_d = gasCosts[chainId].tokenAmount) !== null && _d !== void 0 ? _d : Big(0));
65
73
  const insufficientFromChainGasAmount = insufficientFromChainGas
66
- ? (_g = (_f = gasCosts[chainId].tokenAmount) === null || _f === void 0 ? void 0 : _f.minus(gasTokenBalance)) !== null && _g !== void 0 ? _g : gasCosts[chainId].gasAmount.minus(gasTokenBalance)
74
+ ? (_f = (_e = gasCosts[chainId].tokenAmount) === null || _e === void 0 ? void 0 : _e.minus(gasTokenBalance)) !== null && _f !== void 0 ? _f : gasCosts[chainId].gasAmount.minus(gasTokenBalance)
67
75
  : undefined;
68
76
  gasCosts[chainId] = Object.assign(Object.assign({}, gasCosts[chainId]), { insufficient: insufficientFromChainGas, insufficientAmount: insufficientFromChainGasAmount });
69
77
  }
70
78
  });
71
79
  const gasCostResult = Object.values(gasCosts).filter((gasCost) => gasCost.insufficient);
72
- return gasCostResult;
73
- }, [
80
+ setInsufficientGas(gasCostResult);
81
+ }), [
82
+ account.address,
74
83
  account.isActive,
75
84
  fromAmount,
76
85
  fromChainId,
77
- fromChainTokenBalances,
78
86
  getChainById,
87
+ lifi,
79
88
  route,
80
89
  toChainId,
81
- toChainTokenBalances,
82
90
  ]);
83
91
  const insufficientFunds = useMemo(() => {
84
92
  var _a, _b;
@@ -91,6 +99,9 @@ export const useGasSufficiency = (route) => {
91
99
  const balance = Big((_b = (_a = fromChainTokenBalances === null || fromChainTokenBalances === void 0 ? void 0 : fromChainTokenBalances.find((t) => t.address === fromToken)) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0);
92
100
  return Big(fromAmount).gt(balance);
93
101
  }, [account.isActive, fromAmount, fromChainTokenBalances, fromToken]);
102
+ useEffect(() => {
103
+ checkInsufficientGas();
104
+ }, [checkInsufficientGas]);
94
105
  return {
95
106
  insufficientGas,
96
107
  insufficientFunds,
@@ -1,5 +1,11 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
+ import { checkPackageUpdates } from '@lifi/sdk';
3
+ import { useEffect } from 'react';
4
+ import { name, version } from '../config/version';
2
5
  import { useTools } from './useTools';
3
6
  export const useInitializer = () => {
4
7
  useTools();
8
+ useEffect(() => {
9
+ checkPackageUpdates(name, version);
10
+ }, []);
5
11
  };