@lifi/widget 2.0.0-beta.7 → 2.0.0-beta.9

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 (124) hide show
  1. package/App.d.ts +1 -1
  2. package/AppDrawer.d.ts +1 -1
  3. package/cjs/App.d.ts +1 -1
  4. package/cjs/AppDrawer.d.ts +1 -1
  5. package/cjs/components/ChainSelect/ChainSelect.d.ts +1 -1
  6. package/cjs/components/GasMessage/FundsSufficiencyMessage.d.ts +1 -1
  7. package/cjs/components/GasMessage/GasMessage.js +1 -6
  8. package/cjs/components/Header/Header.style.d.ts +10 -3
  9. package/cjs/components/Header/NavigationHeader.js +1 -1
  10. package/cjs/components/Header/NavigationTabs.d.ts +1 -1
  11. package/cjs/components/Header/NavigationTabs.style.d.ts +4 -71
  12. package/cjs/components/Header/WalletHeader.js +1 -1
  13. package/cjs/components/Insurance/InsuranceCollapsed.js +2 -8
  14. package/cjs/components/SelectChainAndToken.js +8 -7
  15. package/cjs/components/SendToWallet/SendToWallet.js +2 -2
  16. package/cjs/components/SmallAvatar.d.ts +1 -1
  17. package/cjs/components/Step/CircularProgress.d.ts +1 -1
  18. package/cjs/components/Step/Step.js +1 -1
  19. package/cjs/components/Step/StepList.d.ts +1 -1
  20. package/cjs/components/StepActions/StepActions.js +2 -1
  21. package/cjs/components/SwapInput/SwapInputEndAdornment.d.ts +1 -1
  22. package/cjs/components/SwapRoutes/SwapRoutesExpanded.d.ts +2 -2
  23. package/cjs/components/TokenList/TokenList.js +5 -2
  24. package/cjs/components/TokenList/TokenList.style.d.ts +5 -2
  25. package/cjs/components/TokenList/TokenList.style.js +20 -1
  26. package/cjs/components/TokenList/TokenListItem.d.ts +1 -1
  27. package/cjs/components/TokenList/TokenListItem.js +27 -4
  28. package/cjs/components/TokenList/VirtualizedTokenList.js +3 -3
  29. package/cjs/components/TokenList/types.d.ts +4 -0
  30. package/cjs/config/version.d.ts +1 -1
  31. package/cjs/config/version.js +1 -1
  32. package/cjs/hooks/useFundsSufficiency.js +2 -2
  33. package/cjs/hooks/useGasRefuel.d.ts +1 -1
  34. package/cjs/hooks/useGasRefuel.js +5 -15
  35. package/cjs/hooks/useGasSufficiency.js +12 -3
  36. package/cjs/hooks/useProcessMessage.js +4 -0
  37. package/cjs/hooks/useRouteExecution.js +3 -3
  38. package/cjs/hooks/useSwapRoutes.d.ts +1 -2
  39. package/cjs/hooks/useSwapRoutes.js +5 -6
  40. package/cjs/hooks/useTokenBalance.js +2 -2
  41. package/cjs/i18n/en.json +3 -1
  42. package/cjs/icons/InsuraceLogo.d.ts +1 -1
  43. package/cjs/icons/LiFiFullLogo.d.ts +1 -1
  44. package/cjs/icons/LiFiLogo.d.ts +1 -1
  45. package/cjs/icons/LiFiToolLogo.d.ts +1 -1
  46. package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +1 -1
  47. package/cjs/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -1
  48. package/cjs/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -1
  49. package/cjs/pages/SettingsPage/GasPriceSelect.d.ts +1 -1
  50. package/cjs/pages/SettingsPage/SettingsPage.d.ts +1 -1
  51. package/cjs/pages/SettingsPage/ShowDestinationWallet.d.ts +1 -1
  52. package/cjs/pages/SettingsPage/SlippageInput.d.ts +1 -1
  53. package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +1 -1
  54. package/cjs/pages/SwapPage/StatusBottomSheet.js +3 -3
  55. package/cjs/providers/SDKProvider/SDKProvider.js +2 -0
  56. package/cjs/providers/WalletProvider/WalletProvider.js +73 -47
  57. package/cjs/providers/WalletProvider/types.d.ts +0 -2
  58. package/cjs/stores/routes/RouteExecutionStore.d.ts +1 -1
  59. package/cjs/stores/settings/useSplitSubvariantStore.d.ts +1 -1
  60. package/cjs/types/widget.d.ts +1 -0
  61. package/cjs/types/widget.js +1 -0
  62. package/cjs/utils/wallet.d.ts +1 -1
  63. package/cjs/utils/wallet.js +3 -3
  64. package/components/ChainSelect/ChainSelect.d.ts +1 -1
  65. package/components/GasMessage/FundsSufficiencyMessage.d.ts +1 -1
  66. package/components/GasMessage/GasMessage.js +2 -7
  67. package/components/Header/Header.style.d.ts +10 -3
  68. package/components/Header/NavigationHeader.js +1 -1
  69. package/components/Header/NavigationTabs.d.ts +1 -1
  70. package/components/Header/NavigationTabs.style.d.ts +4 -71
  71. package/components/Header/WalletHeader.js +2 -2
  72. package/components/Insurance/InsuranceCollapsed.js +2 -8
  73. package/components/SelectChainAndToken.js +9 -8
  74. package/components/SendToWallet/SendToWallet.js +2 -2
  75. package/components/SmallAvatar.d.ts +1 -1
  76. package/components/Step/CircularProgress.d.ts +1 -1
  77. package/components/Step/Step.js +2 -2
  78. package/components/Step/StepList.d.ts +1 -1
  79. package/components/StepActions/StepActions.js +2 -1
  80. package/components/SwapInput/SwapInputEndAdornment.d.ts +1 -1
  81. package/components/SwapRoutes/SwapRoutesExpanded.d.ts +2 -2
  82. package/components/TokenList/TokenList.js +6 -3
  83. package/components/TokenList/TokenList.style.d.ts +5 -2
  84. package/components/TokenList/TokenList.style.js +21 -2
  85. package/components/TokenList/TokenListItem.d.ts +1 -1
  86. package/components/TokenList/TokenListItem.js +31 -8
  87. package/components/TokenList/VirtualizedTokenList.js +3 -3
  88. package/components/TokenList/types.d.ts +4 -0
  89. package/config/version.d.ts +1 -1
  90. package/config/version.js +1 -1
  91. package/hooks/useFundsSufficiency.js +2 -2
  92. package/hooks/useGasRefuel.d.ts +1 -1
  93. package/hooks/useGasRefuel.js +5 -15
  94. package/hooks/useGasSufficiency.js +13 -4
  95. package/hooks/useProcessMessage.js +4 -0
  96. package/hooks/useRouteExecution.js +3 -3
  97. package/hooks/useSwapRoutes.d.ts +1 -2
  98. package/hooks/useSwapRoutes.js +5 -6
  99. package/hooks/useTokenBalance.js +2 -2
  100. package/i18n/en.json +3 -1
  101. package/icons/InsuraceLogo.d.ts +1 -1
  102. package/icons/LiFiFullLogo.d.ts +1 -1
  103. package/icons/LiFiLogo.d.ts +1 -1
  104. package/icons/LiFiToolLogo.d.ts +1 -1
  105. package/package.json +8 -8
  106. package/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +1 -1
  107. package/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -1
  108. package/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -1
  109. package/pages/SettingsPage/GasPriceSelect.d.ts +1 -1
  110. package/pages/SettingsPage/SettingsPage.d.ts +1 -1
  111. package/pages/SettingsPage/ShowDestinationWallet.d.ts +1 -1
  112. package/pages/SettingsPage/SlippageInput.d.ts +1 -1
  113. package/pages/SwapDetailsPage/SwapDetailsPage.js +1 -1
  114. package/pages/SwapPage/StatusBottomSheet.js +4 -4
  115. package/providers/SDKProvider/SDKProvider.js +2 -0
  116. package/providers/WalletProvider/WalletProvider.js +74 -48
  117. package/providers/WalletProvider/types.d.ts +0 -2
  118. package/stores/routes/RouteExecutionStore.d.ts +1 -1
  119. package/stores/settings/useSplitSubvariantStore.d.ts +1 -1
  120. package/tsconfig.cjs.tsbuildinfo +1 -1
  121. package/types/widget.d.ts +1 -0
  122. package/types/widget.js +1 -0
  123. package/utils/wallet.d.ts +1 -1
  124. package/utils/wallet.js +1 -1
@@ -10,12 +10,11 @@ const useGasRecommendation_1 = require("./useGasRecommendation");
10
10
  const useTokenBalance_1 = require("./useTokenBalance");
11
11
  const useGasRefuel = () => {
12
12
  const { getChainById } = (0, _1.useChains)();
13
- const [fromChainId, fromTokenAddress, toChainId, toTokenAddress, toAddress] = (0, react_hook_form_1.useWatch)({
13
+ const [fromChainId, fromTokenAddress, toChainId, toAddress] = (0, react_hook_form_1.useWatch)({
14
14
  name: [
15
15
  providers_1.SwapFormKey.FromChain,
16
16
  providers_1.SwapFormKey.FromToken,
17
17
  providers_1.SwapFormKey.ToChain,
18
- providers_1.SwapFormKey.ToToken,
19
18
  providers_1.SwapFormKey.ToAddress,
20
19
  ],
21
20
  });
@@ -27,10 +26,7 @@ const useGasRefuel = () => {
27
26
  // We don't allow same chain refuel.
28
27
  // If a user runs out of gas, he can't send a source chain transaction.
29
28
  fromChainId === toChainId ||
30
- // We don't want to apply auto refuel when swapping to native tokens
31
- toChain?.nativeToken.address === toTokenAddress ||
32
29
  !gasRecommendation?.available ||
33
- !gasRecommendation.recommended ||
34
30
  !nativeToken) {
35
31
  return false;
36
32
  }
@@ -41,21 +37,15 @@ const useGasRefuel = () => {
41
37
  .div(2);
42
38
  const insufficientGas = tokenBalance.lt(recommendedAmount);
43
39
  return insufficientGas;
44
- }, [
45
- fromChainId,
46
- gasRecommendation?.available,
47
- gasRecommendation?.recommended,
48
- nativeToken,
49
- toChain?.nativeToken.address,
50
- toChainId,
51
- toTokenAddress,
52
- ]);
40
+ }, [fromChainId, gasRecommendation, nativeToken, toChainId]);
53
41
  return {
54
42
  enabled: enabled,
55
43
  availble: gasRecommendation?.available,
56
44
  isLoading: isLoading,
57
45
  chain: toChain,
58
- gasRecommendation,
46
+ fromAmount: gasRecommendation?.available
47
+ ? gasRecommendation.fromAmount
48
+ : undefined,
59
49
  };
60
50
  };
61
51
  exports.useGasRefuel = useGasRefuel;
@@ -5,15 +5,23 @@ const react_query_1 = require("@tanstack/react-query");
5
5
  const big_js_1 = require("big.js");
6
6
  const _1 = require(".");
7
7
  const providers_1 = require("../providers");
8
+ const stores_1 = require("../stores");
8
9
  const refetchInterval = 30000;
9
10
  const useGasSufficiency = (route) => {
10
- const { account, provider } = (0, providers_1.useWallet)();
11
+ const { account } = (0, providers_1.useWallet)();
11
12
  const { getChainById } = (0, _1.useChains)();
12
- const getTokenBalancesWithRetry = (0, _1.useGetTokenBalancesWithRetry)(provider);
13
+ const getTokenBalancesWithRetry = (0, _1.useGetTokenBalancesWithRetry)(account.signer?.provider);
14
+ const { enabledAutoRefuel } = (0, stores_1.useSettings)(['enabledAutoRefuel']);
15
+ const { enabled, isLoading: isRefuelLoading } = (0, _1.useGasRefuel)();
16
+ const enabledRefuel = enabled && enabledAutoRefuel;
13
17
  const { data: insufficientGas, isInitialLoading } = (0, react_query_1.useQuery)(['gas-sufficiency-check', account.address, route?.id], async () => {
14
18
  if (!account.address || !route) {
15
19
  return;
16
20
  }
21
+ // TODO: include LI.Fuel into calculation once steps and tools are properly typed
22
+ // const refuelSteps = route.steps
23
+ // .flatMap((step) => step.includedSteps)
24
+ // .filter((includedStep) => includedStep.tool === 'lifuelProtocol');
17
25
  const gasCosts = route.steps
18
26
  .filter((step) => !step.execution || step.execution.status !== 'DONE')
19
27
  .reduce((groupedGasCosts, step) => {
@@ -69,8 +77,9 @@ const useGasSufficiency = (route) => {
69
77
  staleTime: refetchInterval,
70
78
  cacheTime: refetchInterval,
71
79
  });
80
+ const isInsufficientGas = Boolean(insufficientGas?.length) && !isRefuelLoading && !enabledRefuel;
72
81
  return {
73
- insufficientGas,
82
+ insufficientGas: isInsufficientGas ? insufficientGas : undefined,
74
83
  isInitialLoading,
75
84
  };
76
85
  };
@@ -103,6 +103,10 @@ function getProcessMessage(t, getChainById, step, process, variant) {
103
103
  title = t(`swap.error.title.gasLimitIsTooLow`);
104
104
  message = getTransactionNotSentMessage();
105
105
  break;
106
+ case sdk_1.LifiErrorCode.InsufficientFunds:
107
+ title = t(`swap.error.title.insufficientFunds`);
108
+ message = `${t(`swap.error.message.insufficientFunds`)} ${getTransactionNotSentMessage()}`;
109
+ break;
106
110
  case sdk_1.LifiErrorCode.SlippageError:
107
111
  title = t(`swap.error.title.slippageNotMet`);
108
112
  message = t(`swap.error.message.slippageThreshold`);
@@ -17,7 +17,7 @@ const useRouteExecution = ({ routeId, executeInBackground, onAcceptExchangeRateU
17
17
  const routeExecutionStoreContext = (0, stores_1.useRouteExecutionStoreContext)();
18
18
  const routeExecution = (0, stores_1.useRouteExecutionStore)((state) => state.routes[routeId]);
19
19
  const [updateRoute, restartRoute, deleteRoute] = (0, stores_1.useRouteExecutionStore)((state) => [state.updateRoute, state.restartRoute, state.deleteRoute], shallow_1.shallow);
20
- const updateCallback = (updatedRoute) => {
20
+ const updateRouteHook = (updatedRoute) => {
21
21
  const routeExecution = routeExecutionStoreContext.getState().routes[updatedRoute.id];
22
22
  if (!routeExecution) {
23
23
  return;
@@ -71,7 +71,7 @@ const useRouteExecution = ({ routeId, executeInBackground, onAcceptExchangeRateU
71
71
  }
72
72
  queryClient.removeQueries(['routes'], { exact: false });
73
73
  return lifi.executeRoute(account.signer, routeExecution.route, {
74
- updateCallback,
74
+ updateRouteHook,
75
75
  switchChainHook,
76
76
  acceptExchangeRateUpdateHook,
77
77
  infiniteApproval: false,
@@ -93,7 +93,7 @@ const useRouteExecution = ({ routeId, executeInBackground, onAcceptExchangeRateU
93
93
  throw Error('Execution route not found.');
94
94
  }
95
95
  return lifi.resumeRoute(account.signer, resumedRoute ?? routeExecution.route, {
96
- updateCallback,
96
+ updateRouteHook,
97
97
  switchChainHook,
98
98
  acceptExchangeRateUpdateHook,
99
99
  infiniteApproval: false,
@@ -1,9 +1,8 @@
1
1
  import type { Route, RoutesResponse } from '@lifi/sdk';
2
2
  interface SwapRoutesProps {
3
- onSettled?: (data?: RoutesResponse) => void;
4
3
  insurableRoute?: Route;
5
4
  }
6
- export declare const useSwapRoutes: ({ onSettled, insurableRoute, }?: SwapRoutesProps) => {
5
+ export declare const useSwapRoutes: ({ insurableRoute }?: SwapRoutesProps) => {
7
6
  routes: Route[] | undefined;
8
7
  isLoading: boolean;
9
8
  isFetching: boolean;
@@ -12,10 +12,10 @@ const providers_1 = require("../providers");
12
12
  const stores_1 = require("../stores");
13
13
  const useSwapOnly_1 = require("./useSwapOnly");
14
14
  const refetchTime = 60000;
15
- const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
15
+ const useSwapRoutes = ({ insurableRoute } = {}) => {
16
16
  const lifi = (0, providers_1.useLiFi)();
17
17
  const { variant, sdkConfig, insurance, contractTool } = (0, providers_1.useWidgetConfig)();
18
- const { account, provider } = (0, providers_1.useWallet)();
18
+ const { account } = (0, providers_1.useWallet)();
19
19
  const queryClient = (0, react_query_1.useQueryClient)();
20
20
  const swapOnly = (0, useSwapOnly_1.useSwapOnly)();
21
21
  const { slippage, enabledBridges, enabledAutoRefuel, enabledExchanges, routePriority, } = (0, stores_1.useSettings)([
@@ -41,7 +41,7 @@ const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
41
41
  });
42
42
  const { token: fromToken } = (0, _1.useToken)(fromChainId, fromTokenAddress);
43
43
  const { token: toToken } = (0, _1.useToken)(toChainId, toTokenAddress);
44
- const { enabled: enabledRefuel, gasRecommendation } = (0, _1.useGasRefuel)();
44
+ const { enabled: enabledRefuel, fromAmount: gasRecommendationFromAmount } = (0, _1.useGasRefuel)();
45
45
  const hasAmount = (!isNaN(fromTokenAmount) && Number(fromTokenAmount) > 0) ||
46
46
  (!isNaN(toTokenAmount) && Number(toTokenAmount) > 0);
47
47
  const contractCallQuoteEnabled = variant === 'nft'
@@ -74,7 +74,7 @@ const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
74
74
  variant,
75
75
  sdkConfig?.defaultRouteOptions?.allowSwitchChain,
76
76
  enabledRefuel && enabledAutoRefuel,
77
- gasRecommendation?.fromAmount,
77
+ gasRecommendationFromAmount,
78
78
  insurance,
79
79
  insurableRoute?.id,
80
80
  ];
@@ -82,7 +82,7 @@ const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
82
82
  let toWalletAddress;
83
83
  try {
84
84
  toWalletAddress =
85
- (await provider?.resolveName(toAddress)) ??
85
+ (await account.signer?.provider?.resolveName(toAddress)) ??
86
86
  ((0, address_1.isAddress)(toAddress) ? toAddress : fromAddress);
87
87
  }
88
88
  catch {
@@ -207,7 +207,6 @@ const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
207
207
  });
208
208
  }
209
209
  },
210
- onSettled,
211
210
  });
212
211
  return {
213
212
  routes: data?.routes,
@@ -8,10 +8,10 @@ const utils_1 = require("../utils");
8
8
  const useGetTokenBalancesWithRetry_1 = require("./useGetTokenBalancesWithRetry");
9
9
  const defaultRefetchInterval = 30000;
10
10
  const useTokenBalance = (token, accountAddress) => {
11
- const { account, provider } = (0, providers_1.useWallet)();
11
+ const { account } = (0, providers_1.useWallet)();
12
12
  const queryClient = (0, react_query_1.useQueryClient)();
13
13
  const walletAddress = accountAddress || account.address;
14
- const getTokenBalancesWithRetry = (0, useGetTokenBalancesWithRetry_1.useGetTokenBalancesWithRetry)(provider);
14
+ const getTokenBalancesWithRetry = (0, useGetTokenBalancesWithRetry_1.useGetTokenBalancesWithRetry)(account.signer?.provider);
15
15
  const tokenBalanceQueryKey = (0, react_1.useMemo)(() => ['token-balance', walletAddress, token?.chainId, token?.address], [token?.address, token?.chainId, walletAddress]);
16
16
  const { data, isLoading, refetch } = (0, react_query_1.useQuery)(tokenBalanceQueryKey, async ({ queryKey: [, accountAddress] }) => {
17
17
  const cachedToken = queryClient
package/cjs/i18n/en.json CHANGED
@@ -83,6 +83,7 @@
83
83
  "error": {
84
84
  "message": {
85
85
  "allowanceRequired": "Transfer amount for {{tokenSymbol}} exceeds your current allowance. Please increase your allowance and try again.",
86
+ "insufficientFunds": "You don't have enough gas to cover the cost of the transaction.",
86
87
  "slippageThreshold": "The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.",
87
88
  "transactionFailed": "Please check the block explorer for more information.",
88
89
  "transactionNotSent": "Transaction was not sent. {{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}} on {{chainName}} remain in your wallet.",
@@ -95,6 +96,7 @@
95
96
  "chainSwitch": "Chain switch required",
96
97
  "failed": "Swap failed",
97
98
  "gasLimitIsTooLow": "The gas limit is too low",
99
+ "insufficientFunds": "Insufficient funds",
98
100
  "slippageNotMet": "Slippage conditions not met",
99
101
  "transactionCanceled": "Transaction canceled",
100
102
  "transactionFailed": "Transaction failed",
@@ -217,7 +219,7 @@
217
219
  "to": "To",
218
220
  "tokenOnChain": "{{tokenSymbol}} on {{chainName}}",
219
221
  "tokenOnChainAmount": "{{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}} on {{chainName}}",
220
- "tokenSearch": "Search your token",
222
+ "tokenSearch": "Search by token name or address",
221
223
  "valueLoss": "Value loss",
222
224
  "walletAddressOrEns": "Wallet address or ENS name",
223
225
  "warning": {
@@ -1,2 +1,2 @@
1
1
  import type { SVGProps } from 'react';
2
- export declare const InsuraceLogo: (props: SVGProps<SVGSVGElement>) => JSX.Element;
2
+ export declare const InsuraceLogo: (props: SVGProps<SVGSVGElement>) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,2 @@
1
1
  import type { SVGProps } from 'react';
2
- export declare const LiFiFullLogo: (props: SVGProps<SVGSVGElement>) => JSX.Element;
2
+ export declare const LiFiFullLogo: (props: SVGProps<SVGSVGElement>) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,2 @@
1
1
  import type { SVGProps } from 'react';
2
- export declare const LiFiLogo: (props: SVGProps<SVGSVGElement>) => JSX.Element;
2
+ export declare const LiFiLogo: (props: SVGProps<SVGSVGElement>) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,2 @@
1
1
  import type { SVGProps } from 'react';
2
- export declare const LiFiToolLogo: (props: SVGProps<SVGSVGElement>) => JSX.Element;
2
+ export declare const LiFiToolLogo: (props: SVGProps<SVGSVGElement>) => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- export declare const ActiveSwapsPage: () => JSX.Element;
1
+ export declare const ActiveSwapsPage: () => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- export declare const SearchTokenInput: () => JSX.Element;
1
+ export declare const SearchTokenInput: () => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- export declare const SelectWalletPage: () => JSX.Element;
1
+ export declare const SelectWalletPage: () => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- export declare const GasPriceSelect: () => JSX.Element;
1
+ export declare const GasPriceSelect: () => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- export declare const SettingsPage: () => JSX.Element;
1
+ export declare const SettingsPage: () => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- export declare const ShowDestinationWallet: () => JSX.Element | null;
1
+ export declare const ShowDestinationWallet: () => import("react/jsx-runtime").JSX.Element | null;
@@ -1 +1 @@
1
- export declare const SlippageInput: () => JSX.Element;
1
+ export declare const SlippageInput: () => import("react/jsx-runtime").JSX.Element;
@@ -59,6 +59,6 @@ const SwapDetailsPage = () => {
59
59
  }).format(startedAt) })] }), (0, Step_1.getStepList)(routeExecution?.route), variant === 'nft' ? (0, jsx_runtime_1.jsx)(ContractComponent_1.ContractComponent, { mt: 2 }) : null, routeExecution?.route?.insurance?.state === 'INSURED' ? ((0, jsx_runtime_1.jsx)(Insurance_1.Insurance, { mt: 2, status: routeExecution.status, feeAmountUsd: routeExecution.route.insurance.feeAmountUsd, insurableRouteId: routeExecution.route.id, insuranceCoverageId: insuranceCoverageId })) : null, (0, jsx_runtime_1.jsxs)(Card_1.Card, { mt: 2, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
60
60
  display: 'flex',
61
61
  flex: 1,
62
- }, children: [(0, jsx_runtime_1.jsx)(Card_1.CardTitle, { flex: 1, children: t('swap.supportId') }), (0, jsx_runtime_1.jsx)(material_1.Box, { mr: 1, mt: 1, children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "medium", onClick: copySupportId, children: (0, jsx_runtime_1.jsx)(ContentCopyRounded_1.default, { fontSize: "small" }) }) })] }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", pt: 1, pb: 2, px: 2, sx: { wordBreak: 'break-all' }, children: supportId })] }), (0, jsx_runtime_1.jsx)(material_1.Box, { mt: 2, children: (0, jsx_runtime_1.jsx)(material_1.Button, { href: "https://discord.com/channels/849912621360218112/863689862514343946", target: "_blank", rel: "nofollow noreferrer", fullWidth: true, children: t('button.contactSupport') }) }), (0, jsx_runtime_1.jsxs)(Dialog_1.Dialog, { open: open, onClose: toggleDialog, children: [(0, jsx_runtime_1.jsx)(material_1.DialogTitle, { children: t('swap.warning.title.deleteSwap') }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, { children: t('swap.warning.message.deleteSwapHistory') }) }), (0, jsx_runtime_1.jsxs)(material_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, { onClick: toggleDialog, children: t('button.cancel') }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", onClick: handleDeleteRoute, autoFocus: true, children: t('button.delete') })] })] })] }));
62
+ }, children: [(0, jsx_runtime_1.jsx)(Card_1.CardTitle, { flex: 1, children: t('swap.supportId') }), (0, jsx_runtime_1.jsx)(material_1.Box, { mr: 1, mt: 1, children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "medium", onClick: copySupportId, children: (0, jsx_runtime_1.jsx)(ContentCopyRounded_1.default, { fontSize: "small" }) }) })] }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", pt: 1, pb: 2, px: 2, sx: { wordBreak: 'break-all' }, children: supportId })] }), (0, jsx_runtime_1.jsx)(material_1.Box, { mt: 2, children: (0, jsx_runtime_1.jsx)(material_1.Button, { href: "https://discord.gg/lifi", target: "_blank", rel: "nofollow noreferrer", fullWidth: true, children: t('button.contactSupport') }) }), (0, jsx_runtime_1.jsxs)(Dialog_1.Dialog, { open: open, onClose: toggleDialog, children: [(0, jsx_runtime_1.jsx)(material_1.DialogTitle, { children: t('swap.warning.title.deleteSwap') }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, { children: t('swap.warning.message.deleteSwapHistory') }) }), (0, jsx_runtime_1.jsxs)(material_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, { onClick: toggleDialog, children: t('button.cancel') }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", onClick: handleDeleteRoute, autoFocus: true, children: t('button.delete') })] })] })] }));
63
63
  };
64
64
  exports.SwapDetailsPage = SwapDetailsPage;
@@ -82,7 +82,7 @@ const StatusBottomSheet = ({ status, route, }) => {
82
82
  amount: token.amount,
83
83
  tokenSymbol: token.symbol,
84
84
  chainName: getChainById(token.chainId)?.name,
85
- walletAddress: (0, utils_1.shortenWalletAddress)(route.toAddress),
85
+ walletAddress: (0, utils_1.shortenAddress)(route.toAddress),
86
86
  });
87
87
  }
88
88
  handlePrimaryButton = handleDone;
@@ -99,7 +99,7 @@ const StatusBottomSheet = ({ status, route, }) => {
99
99
  amount: token.amount,
100
100
  tokenSymbol: token.symbol,
101
101
  chainName: getChainById(token.chainId)?.name,
102
- walletAddress: (0, utils_1.shortenWalletAddress)(route.toAddress),
102
+ walletAddress: (0, utils_1.shortenAddress)(route.toAddress),
103
103
  });
104
104
  }
105
105
  handlePrimaryButton = handlePartialDone;
@@ -116,7 +116,7 @@ const StatusBottomSheet = ({ status, route, }) => {
116
116
  amount: token.amount,
117
117
  tokenSymbol: token.symbol,
118
118
  chainName: getChainById(token.chainId)?.name,
119
- walletAddress: (0, utils_1.shortenWalletAddress)(route.toAddress),
119
+ walletAddress: (0, utils_1.shortenAddress)(route.toAddress),
120
120
  });
121
121
  }
122
122
  break;
@@ -4,6 +4,7 @@ exports.SDKProvider = exports.useLiFi = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const sdk_1 = require("@lifi/sdk");
6
6
  const react_1 = require("react");
7
+ const version_1 = require("../../config/version");
7
8
  const WidgetProvider_1 = require("../WidgetProvider");
8
9
  let lifi;
9
10
  const SDKContext = (0, react_1.createContext)(null);
@@ -27,6 +28,7 @@ const SDKProvider = ({ children, }) => {
27
28
  if (!lifi) {
28
29
  lifi = new sdk_1.LiFi({
29
30
  disableVersionCheck: true,
31
+ widgetVersion: version_1.version,
30
32
  ...config,
31
33
  });
32
34
  }
@@ -24,19 +24,6 @@ const WalletProvider = ({ children }) => {
24
24
  const { walletManagement } = (0, WidgetProvider_1.useWidgetConfig)();
25
25
  const [account, setAccount] = (0, react_1.useState)({});
26
26
  const [currentWallet, setCurrentWallet] = (0, react_1.useState)();
27
- (0, react_1.useEffect)(() => {
28
- const autoConnect = async () => {
29
- const persistedActiveWallets = (0, wallet_management_1.readActiveWallets)();
30
- const activeWallets = wallet_management_1.supportedWallets.filter((wallet) => persistedActiveWallets.some((perstistedWallet) => perstistedWallet.name === wallet.name));
31
- if (!activeWallets.length) {
32
- return;
33
- }
34
- await liFiWalletManagement.autoConnect(activeWallets);
35
- activeWallets[0].on('walletAccountChanged', handleWalletUpdate);
36
- handleWalletUpdate(activeWallets[0]);
37
- };
38
- autoConnect();
39
- }, []);
40
27
  const handleWalletUpdate = async (wallet) => {
41
28
  setCurrentWallet(wallet);
42
29
  const account = await (0, exports.extractAccountFromSigner)(wallet?.account?.signer);
@@ -64,54 +51,102 @@ const WalletProvider = ({ children }) => {
64
51
  currentWallet.removeAllListeners();
65
52
  handleWalletUpdate(undefined);
66
53
  }
67
- }, [walletManagement, currentWallet]);
54
+ }, [currentWallet, walletManagement]);
68
55
  const switchChain = (0, react_1.useCallback)(async (chainId) => {
69
- if (walletManagement?.switchChain) {
70
- const signer = await walletManagement.switchChain(chainId);
71
- const account = await (0, exports.extractAccountFromSigner)(signer);
72
- setAccount(account);
73
- return true;
74
- }
75
56
  try {
76
- await currentWallet?.switchChain(chainId);
77
- handleWalletUpdate(currentWallet);
57
+ if (walletManagement?.switchChain) {
58
+ const signer = await walletManagement.switchChain(chainId);
59
+ const account = await (0, exports.extractAccountFromSigner)(signer);
60
+ setAccount(account);
61
+ }
62
+ else if (!currentWallet) {
63
+ const provider = account.signer?.provider;
64
+ if (!provider) {
65
+ throw new Error(`Switch chain: No provider available`);
66
+ }
67
+ await (0, wallet_management_1.switchChain)(provider, chainId);
68
+ }
69
+ else {
70
+ await currentWallet?.switchChain(chainId);
71
+ handleWalletUpdate(currentWallet);
72
+ }
78
73
  return true;
79
74
  }
80
75
  catch {
81
76
  return false;
82
77
  }
83
- }, [walletManagement, currentWallet]);
78
+ }, [account.signer?.provider, currentWallet, walletManagement]);
84
79
  const addChain = (0, react_1.useCallback)(async (chainId) => {
85
- if (walletManagement?.addChain) {
86
- return walletManagement.addChain(chainId);
87
- }
88
80
  try {
89
- await currentWallet?.addChain(chainId);
90
- handleWalletUpdate(currentWallet);
81
+ if (walletManagement?.addChain) {
82
+ return walletManagement.addChain(chainId);
83
+ }
84
+ else if (!currentWallet) {
85
+ const provider = account.signer?.provider;
86
+ if (!provider) {
87
+ throw new Error(`Add chain: No provider available`);
88
+ }
89
+ await (0, wallet_management_1.addChain)(provider, chainId);
90
+ }
91
+ else {
92
+ await currentWallet?.addChain(chainId);
93
+ handleWalletUpdate(currentWallet);
94
+ }
91
95
  return true;
92
96
  }
93
97
  catch {
94
98
  return false;
95
99
  }
96
- }, [walletManagement, currentWallet]);
100
+ }, [account.signer?.provider, currentWallet, walletManagement]);
97
101
  const addToken = (0, react_1.useCallback)(async (chainId, token) => {
98
- if (walletManagement?.addToken) {
99
- return walletManagement.addToken(token, chainId);
102
+ try {
103
+ if (walletManagement?.addToken) {
104
+ return walletManagement.addToken(token, chainId);
105
+ }
106
+ else if (!currentWallet) {
107
+ const provider = account.signer?.provider;
108
+ if (!provider) {
109
+ throw new Error(`Add token: No provider available`);
110
+ }
111
+ await (0, wallet_management_1.switchChainAndAddToken)(provider, chainId, token);
112
+ }
113
+ else {
114
+ await currentWallet?.addToken(chainId, token);
115
+ handleWalletUpdate(currentWallet);
116
+ }
100
117
  }
101
- await currentWallet?.addToken(chainId, token);
102
- handleWalletUpdate(currentWallet);
103
- return;
104
- }, [walletManagement, currentWallet]);
118
+ catch { }
119
+ }, [account.signer?.provider, currentWallet, walletManagement]);
120
+ (0, react_1.useEffect)(() => {
121
+ const autoConnect = async () => {
122
+ const persistedActiveWallets = (0, wallet_management_1.readActiveWallets)();
123
+ const activeWallets = wallet_management_1.supportedWallets.filter((wallet) => persistedActiveWallets.some((perstistedWallet) => perstistedWallet.name === wallet.name));
124
+ if (!activeWallets.length) {
125
+ return;
126
+ }
127
+ await liFiWalletManagement.autoConnect(activeWallets);
128
+ activeWallets[0].on('walletAccountChanged', handleWalletUpdate);
129
+ handleWalletUpdate(activeWallets[0]);
130
+ };
131
+ autoConnect();
132
+ }, []);
105
133
  // keep widget in sync with changing external signer object
106
134
  (0, react_1.useEffect)(() => {
107
135
  if (walletManagement) {
136
+ let ignore = false;
108
137
  const updateAccount = async () => {
109
138
  const account = await (0, exports.extractAccountFromSigner)(walletManagement?.signer);
110
- setAccount(account);
139
+ // we should ignore the update if there is a newer one
140
+ if (!ignore) {
141
+ setAccount(account);
142
+ }
111
143
  };
112
144
  updateAccount();
145
+ return () => {
146
+ ignore = true;
147
+ };
113
148
  }
114
- }, [walletManagement, walletManagement?.signer]);
149
+ }, [walletManagement]);
115
150
  const value = (0, react_1.useMemo)(() => ({
116
151
  connect,
117
152
  disconnect,
@@ -119,16 +154,7 @@ const WalletProvider = ({ children }) => {
119
154
  addChain,
120
155
  addToken,
121
156
  account,
122
- provider: currentWallet?.account?.provider,
123
- }), [
124
- account,
125
- addChain,
126
- addToken,
127
- connect,
128
- disconnect,
129
- currentWallet,
130
- switchChain,
131
- ]);
157
+ }), [account, addChain, addToken, connect, disconnect, switchChain]);
132
158
  return ((0, jsx_runtime_1.jsx)(WalletContext.Provider, { value: value, children: children }));
133
159
  };
134
160
  exports.WalletProvider = WalletProvider;
@@ -1,10 +1,8 @@
1
1
  import type { Signer } from '@ethersproject/abstract-signer';
2
- import type { Provider } from '@ethersproject/providers';
3
2
  import type { StaticToken } from '@lifi/sdk';
4
3
  import type { Wallet } from '@lifi/wallet-management';
5
4
  export interface WalletContextProps {
6
5
  account: WalletAccount;
7
- provider?: Provider;
8
6
  addChain(chainId: number): Promise<boolean>;
9
7
  addToken(chainId: number, token: StaticToken): Promise<void>;
10
8
  disconnect(wallet?: Wallet): void;
@@ -4,6 +4,6 @@ import type { PersistStoreProviderProps } from '../types';
4
4
  import type { RouteExecutionState } from './types';
5
5
  export type RouteExecutionStore = UseBoundStore<StoreApi<RouteExecutionState>>;
6
6
  export declare const RouteExecutionStoreContext: import("react").Context<RouteExecutionStore | null>;
7
- export declare function RouteExecutionStoreProvider({ children, ...props }: PersistStoreProviderProps): JSX.Element;
7
+ export declare function RouteExecutionStoreProvider({ children, ...props }: PersistStoreProviderProps): import("react/jsx-runtime").JSX.Element;
8
8
  export declare function useRouteExecutionStore<T>(selector: (state: RouteExecutionState) => T, equalityFn?: (left: T, right: T) => boolean): T;
9
9
  export declare function useRouteExecutionStoreContext(): RouteExecutionStore;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import type { SplitSubvariantProps, SplitSubvariantProviderProps, SplitSubvariantState, SplitSubvariantStore } from './types';
3
3
  export declare const SplitSubvariantStoreContext: import("react").Context<SplitSubvariantStore | null>;
4
- export declare function SplitSubvariantStoreProvider({ children, ...props }: SplitSubvariantProviderProps): JSX.Element;
4
+ export declare function SplitSubvariantStoreProvider({ children, ...props }: SplitSubvariantProviderProps): import("react/jsx-runtime").JSX.Element;
5
5
  export declare function useSplitSubvariantStore<T>(selector: (state: SplitSubvariantState) => T, equalityFn?: (left: T, right: T) => boolean): T;
6
6
  export declare function useSplitSubvariantStoreContext(): SplitSubvariantStore;
7
7
  export declare const createSplitSubvariantStore: ({ state }: SplitSubvariantProps) => import("zustand").UseBoundStore<import("zustand").StoreApi<SplitSubvariantState>>;
@@ -20,6 +20,7 @@ export declare enum HiddenUI {
20
20
  Language = "language",
21
21
  PoweredBy = "poweredBy",
22
22
  ToAddress = "toAddress",
23
+ ToToken = "toToken",
23
24
  WalletMenu = "walletMenu"
24
25
  }
25
26
  export type HiddenUIType = `${HiddenUI}`;
@@ -16,6 +16,7 @@ var HiddenUI;
16
16
  HiddenUI["Language"] = "language";
17
17
  HiddenUI["PoweredBy"] = "poweredBy";
18
18
  HiddenUI["ToAddress"] = "toAddress";
19
+ HiddenUI["ToToken"] = "toToken";
19
20
  HiddenUI["WalletMenu"] = "walletMenu";
20
21
  })(HiddenUI = exports.HiddenUI || (exports.HiddenUI = {}));
21
22
  var RequiredUI;
@@ -1 +1 @@
1
- export declare const shortenWalletAddress: (address?: string) => string | null;
1
+ export declare const shortenAddress: (address?: string) => string | null;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shortenWalletAddress = void 0;
4
- const shortenWalletAddress = (address) => address
3
+ exports.shortenAddress = void 0;
4
+ const shortenAddress = (address) => address
5
5
  ? `${address.substring(0, 5)}...${address.substring(address.length - 4)}`
6
6
  : null;
7
- exports.shortenWalletAddress = shortenWalletAddress;
7
+ exports.shortenAddress = shortenAddress;
@@ -1,2 +1,2 @@
1
1
  import type { SwapFormTypeProps } from '../../providers';
2
- export declare const ChainSelect: ({ formType }: SwapFormTypeProps) => JSX.Element;
2
+ export declare const ChainSelect: ({ formType }: SwapFormTypeProps) => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- export declare const FundsSufficiencyMessage: () => JSX.Element;
1
+ export declare const FundsSufficiencyMessage: () => import("react/jsx-runtime").JSX.Element;
@@ -1,15 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Box, Collapse } from '@mui/material';
3
- import { useFundsSufficiency, useGasRefuel, useGasSufficiency, } from '../../hooks';
4
- import { useSettings } from '../../stores';
3
+ import { useFundsSufficiency, useGasSufficiency } from '../../hooks';
5
4
  import { FundsSufficiencyMessage } from './FundsSufficiencyMessage';
6
5
  import { GasSufficiencyMessage } from './GasSufficiencyMessage';
7
6
  export const GasMessage = ({ route, ...props }) => {
8
7
  const { insufficientGas } = useGasSufficiency(route);
9
8
  const { insufficientFunds } = useFundsSufficiency(route);
10
- const { enabledAutoRefuel } = useSettings(['enabledAutoRefuel']);
11
- const { enabled, isLoading: isRefuelLoading } = useGasRefuel();
12
- const enabledRefuel = enabled && enabledAutoRefuel;
13
- const showGasSufficiencyMessage = insufficientGas?.length && !isRefuelLoading && !enabledRefuel;
14
- return (_jsx(Collapse, { timeout: 225, in: Boolean(insufficientFunds || showGasSufficiencyMessage), unmountOnExit: true, mountOnEnter: true, children: _jsx(Box, { ...props, children: insufficientFunds ? (_jsx(FundsSufficiencyMessage, {})) : showGasSufficiencyMessage ? (_jsx(GasSufficiencyMessage, { insufficientGas: insufficientGas })) : null }) }));
9
+ return (_jsx(Collapse, { timeout: 225, in: Boolean(insufficientFunds || insufficientGas?.length), unmountOnExit: true, mountOnEnter: true, children: _jsx(Box, { ...props, children: insufficientFunds ? (_jsx(FundsSufficiencyMessage, {})) : insufficientGas?.length ? (_jsx(GasSufficiencyMessage, { insufficientGas: insufficientGas })) : null }) }));
15
10
  };