@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
@@ -1,16 +1,24 @@
1
1
  import { useQuery } from '@tanstack/react-query';
2
2
  import Big from 'big.js';
3
- import { useChains, useGetTokenBalancesWithRetry } from '.';
3
+ import { useChains, useGasRefuel, useGetTokenBalancesWithRetry } from '.';
4
4
  import { useWallet } from '../providers';
5
+ import { useSettings } from '../stores';
5
6
  const refetchInterval = 30000;
6
7
  export const useGasSufficiency = (route) => {
7
- const { account, provider } = useWallet();
8
+ const { account } = useWallet();
8
9
  const { getChainById } = useChains();
9
- const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider);
10
+ const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(account.signer?.provider);
11
+ const { enabledAutoRefuel } = useSettings(['enabledAutoRefuel']);
12
+ const { enabled, isLoading: isRefuelLoading } = useGasRefuel();
13
+ const enabledRefuel = enabled && enabledAutoRefuel;
10
14
  const { data: insufficientGas, isInitialLoading } = useQuery(['gas-sufficiency-check', account.address, route?.id], async () => {
11
15
  if (!account.address || !route) {
12
16
  return;
13
17
  }
18
+ // TODO: include LI.Fuel into calculation once steps and tools are properly typed
19
+ // const refuelSteps = route.steps
20
+ // .flatMap((step) => step.includedSteps)
21
+ // .filter((includedStep) => includedStep.tool === 'lifuelProtocol');
14
22
  const gasCosts = route.steps
15
23
  .filter((step) => !step.execution || step.execution.status !== 'DONE')
16
24
  .reduce((groupedGasCosts, step) => {
@@ -66,8 +74,9 @@ export const useGasSufficiency = (route) => {
66
74
  staleTime: refetchInterval,
67
75
  cacheTime: refetchInterval,
68
76
  });
77
+ const isInsufficientGas = Boolean(insufficientGas?.length) && !isRefuelLoading && !enabledRefuel;
69
78
  return {
70
- insufficientGas,
79
+ insufficientGas: isInsufficientGas ? insufficientGas : undefined,
71
80
  isInitialLoading,
72
81
  };
73
82
  };
@@ -99,6 +99,10 @@ export function getProcessMessage(t, getChainById, step, process, variant) {
99
99
  title = t(`swap.error.title.gasLimitIsTooLow`);
100
100
  message = getTransactionNotSentMessage();
101
101
  break;
102
+ case LifiErrorCode.InsufficientFunds:
103
+ title = t(`swap.error.title.insufficientFunds`);
104
+ message = `${t(`swap.error.message.insufficientFunds`)} ${getTransactionNotSentMessage()}`;
105
+ break;
102
106
  case LifiErrorCode.SlippageError:
103
107
  title = t(`swap.error.title.slippageNotMet`);
104
108
  message = t(`swap.error.message.slippageThreshold`);
@@ -14,7 +14,7 @@ export const useRouteExecution = ({ routeId, executeInBackground, onAcceptExchan
14
14
  const routeExecutionStoreContext = useRouteExecutionStoreContext();
15
15
  const routeExecution = useRouteExecutionStore((state) => state.routes[routeId]);
16
16
  const [updateRoute, restartRoute, deleteRoute] = useRouteExecutionStore((state) => [state.updateRoute, state.restartRoute, state.deleteRoute], shallow);
17
- const updateCallback = (updatedRoute) => {
17
+ const updateRouteHook = (updatedRoute) => {
18
18
  const routeExecution = routeExecutionStoreContext.getState().routes[updatedRoute.id];
19
19
  if (!routeExecution) {
20
20
  return;
@@ -68,7 +68,7 @@ export const useRouteExecution = ({ routeId, executeInBackground, onAcceptExchan
68
68
  }
69
69
  queryClient.removeQueries(['routes'], { exact: false });
70
70
  return lifi.executeRoute(account.signer, routeExecution.route, {
71
- updateCallback,
71
+ updateRouteHook,
72
72
  switchChainHook,
73
73
  acceptExchangeRateUpdateHook,
74
74
  infiniteApproval: false,
@@ -90,7 +90,7 @@ export const useRouteExecution = ({ routeId, executeInBackground, onAcceptExchan
90
90
  throw Error('Execution route not found.');
91
91
  }
92
92
  return lifi.resumeRoute(account.signer, resumedRoute ?? routeExecution.route, {
93
- updateCallback,
93
+ updateRouteHook,
94
94
  switchChainHook,
95
95
  acceptExchangeRateUpdateHook,
96
96
  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;
@@ -9,10 +9,10 @@ import { SwapFormKey, useLiFi, useWallet, useWidgetConfig } from '../providers';
9
9
  import { useSettings } from '../stores';
10
10
  import { useSwapOnly } from './useSwapOnly';
11
11
  const refetchTime = 60000;
12
- export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
12
+ export const useSwapRoutes = ({ insurableRoute } = {}) => {
13
13
  const lifi = useLiFi();
14
14
  const { variant, sdkConfig, insurance, contractTool } = useWidgetConfig();
15
- const { account, provider } = useWallet();
15
+ const { account } = useWallet();
16
16
  const queryClient = useQueryClient();
17
17
  const swapOnly = useSwapOnly();
18
18
  const { slippage, enabledBridges, enabledAutoRefuel, enabledExchanges, routePriority, } = useSettings([
@@ -38,7 +38,7 @@ export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
38
38
  });
39
39
  const { token: fromToken } = useToken(fromChainId, fromTokenAddress);
40
40
  const { token: toToken } = useToken(toChainId, toTokenAddress);
41
- const { enabled: enabledRefuel, gasRecommendation } = useGasRefuel();
41
+ const { enabled: enabledRefuel, fromAmount: gasRecommendationFromAmount } = useGasRefuel();
42
42
  const hasAmount = (!isNaN(fromTokenAmount) && Number(fromTokenAmount) > 0) ||
43
43
  (!isNaN(toTokenAmount) && Number(toTokenAmount) > 0);
44
44
  const contractCallQuoteEnabled = variant === 'nft'
@@ -71,7 +71,7 @@ export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
71
71
  variant,
72
72
  sdkConfig?.defaultRouteOptions?.allowSwitchChain,
73
73
  enabledRefuel && enabledAutoRefuel,
74
- gasRecommendation?.fromAmount,
74
+ gasRecommendationFromAmount,
75
75
  insurance,
76
76
  insurableRoute?.id,
77
77
  ];
@@ -79,7 +79,7 @@ export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
79
79
  let toWalletAddress;
80
80
  try {
81
81
  toWalletAddress =
82
- (await provider?.resolveName(toAddress)) ??
82
+ (await account.signer?.provider?.resolveName(toAddress)) ??
83
83
  (isAddress(toAddress) ? toAddress : fromAddress);
84
84
  }
85
85
  catch {
@@ -204,7 +204,6 @@ export const useSwapRoutes = ({ onSettled, insurableRoute, } = {}) => {
204
204
  });
205
205
  }
206
206
  },
207
- onSettled,
208
207
  });
209
208
  return {
210
209
  routes: data?.routes,
@@ -5,10 +5,10 @@ import { formatTokenAmount } from '../utils';
5
5
  import { useGetTokenBalancesWithRetry } from './useGetTokenBalancesWithRetry';
6
6
  const defaultRefetchInterval = 30000;
7
7
  export const useTokenBalance = (token, accountAddress) => {
8
- const { account, provider } = useWallet();
8
+ const { account } = useWallet();
9
9
  const queryClient = useQueryClient();
10
10
  const walletAddress = accountAddress || account.address;
11
- const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider);
11
+ const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(account.signer?.provider);
12
12
  const tokenBalanceQueryKey = useMemo(() => ['token-balance', walletAddress, token?.chainId, token?.address], [token?.address, token?.chainId, walletAddress]);
13
13
  const { data, isLoading, refetch } = useQuery(tokenBalanceQueryKey, async ({ queryKey: [, accountAddress] }) => {
14
14
  const cachedToken = queryClient
package/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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/widget",
3
- "version": "2.0.0-beta.7",
3
+ "version": "2.0.0-beta.9",
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",
@@ -37,18 +37,18 @@
37
37
  "lifi"
38
38
  ],
39
39
  "dependencies": {
40
- "@emotion/react": "^11.10.8",
41
- "@emotion/styled": "^11.10.8",
40
+ "@emotion/react": "^11.11.0",
41
+ "@emotion/styled": "^11.11.0",
42
42
  "@ethersproject/abstract-signer": "^5.7.0",
43
43
  "@ethersproject/address": "^5.7.0",
44
44
  "@ethersproject/experimental": "^5.7.0",
45
45
  "@ethersproject/providers": "^5.7.2",
46
- "@lifi/sdk": "^2.0.0-beta.11",
47
- "@lifi/wallet-management": "^2.0.0-beta.5",
46
+ "@lifi/sdk": "^2.0.0-beta.13",
47
+ "@lifi/wallet-management": "^2.0.0-beta.7",
48
48
  "@mui/icons-material": "^5.11.16",
49
49
  "@mui/lab": "^5.0.0-alpha.129",
50
- "@mui/material": "^5.12.3",
51
- "@tanstack/react-query": "^4.29.5",
50
+ "@mui/material": "^5.13.0",
51
+ "@tanstack/react-query": "^4.29.7",
52
52
  "@tanstack/react-virtual": "^3.0.0-beta.54",
53
53
  "big.js": "^6.2.1",
54
54
  "i18next": "^22.4.15",
@@ -61,7 +61,7 @@
61
61
  "react-i18next": "^12.2.2",
62
62
  "react-intersection-observer": "^9.4.3",
63
63
  "react-router-dom": "^6.11.1",
64
- "react-timer-hook": "^3.0.5",
64
+ "react-timer-hook": "^3.0.6",
65
65
  "uuid": "^9.0.0",
66
66
  "zustand": "^4.3.8"
67
67
  },
@@ -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;
@@ -56,5 +56,5 @@ export const SwapDetailsPage = () => {
56
56
  }).format(startedAt) })] }), getStepList(routeExecution?.route), variant === 'nft' ? _jsx(ContractComponent, { mt: 2 }) : null, routeExecution?.route?.insurance?.state === 'INSURED' ? (_jsx(Insurance, { mt: 2, status: routeExecution.status, feeAmountUsd: routeExecution.route.insurance.feeAmountUsd, insurableRouteId: routeExecution.route.id, insuranceCoverageId: insuranceCoverageId })) : null, _jsxs(Card, { mt: 2, children: [_jsxs(Box, { sx: {
57
57
  display: 'flex',
58
58
  flex: 1,
59
- }, children: [_jsx(CardTitle, { flex: 1, children: t('swap.supportId') }), _jsx(Box, { mr: 1, mt: 1, children: _jsx(IconButton, { size: "medium", onClick: copySupportId, children: _jsx(ContentCopyIcon, { fontSize: "small" }) }) })] }), _jsx(Typography, { variant: "body2", pt: 1, pb: 2, px: 2, sx: { wordBreak: 'break-all' }, children: supportId })] }), _jsx(Box, { mt: 2, children: _jsx(Button, { href: "https://discord.com/channels/849912621360218112/863689862514343946", target: "_blank", rel: "nofollow noreferrer", fullWidth: true, children: t('button.contactSupport') }) }), _jsxs(Dialog, { open: open, onClose: toggleDialog, children: [_jsx(DialogTitle, { children: t('swap.warning.title.deleteSwap') }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('swap.warning.message.deleteSwapHistory') }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: toggleDialog, children: t('button.cancel') }), _jsx(Button, { variant: "contained", onClick: handleDeleteRoute, autoFocus: true, children: t('button.delete') })] })] })] }));
59
+ }, children: [_jsx(CardTitle, { flex: 1, children: t('swap.supportId') }), _jsx(Box, { mr: 1, mt: 1, children: _jsx(IconButton, { size: "medium", onClick: copySupportId, children: _jsx(ContentCopyIcon, { fontSize: "small" }) }) })] }), _jsx(Typography, { variant: "body2", pt: 1, pb: 2, px: 2, sx: { wordBreak: 'break-all' }, children: supportId })] }), _jsx(Box, { mt: 2, children: _jsx(Button, { href: "https://discord.gg/lifi", target: "_blank", rel: "nofollow noreferrer", fullWidth: true, children: t('button.contactSupport') }) }), _jsxs(Dialog, { open: open, onClose: toggleDialog, children: [_jsx(DialogTitle, { children: t('swap.warning.title.deleteSwap') }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('swap.warning.message.deleteSwapHistory') }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: toggleDialog, children: t('button.cancel') }), _jsx(Button, { variant: "contained", onClick: handleDeleteRoute, autoFocus: true, children: t('button.delete') })] })] })] }));
60
60
  };
@@ -12,7 +12,7 @@ import { Token } from '../../components/Token';
12
12
  import { getProcessMessage, useChains, useNavigateBack, useTokenBalance, } from '../../hooks';
13
13
  import { SwapFormKey, useWidgetConfig } from '../../providers';
14
14
  import { RouteExecutionStatus } from '../../stores';
15
- import { formatTokenAmount, hasEnumFlag, navigationRoutes, shortenWalletAddress, } from '../../utils';
15
+ import { formatTokenAmount, hasEnumFlag, navigationRoutes, shortenAddress, } from '../../utils';
16
16
  import { CenterContainer, IconCircle } from './StatusBottomSheet.style';
17
17
  export const StatusBottomSheet = ({ status, route, }) => {
18
18
  const { t } = useTranslation();
@@ -79,7 +79,7 @@ export const StatusBottomSheet = ({ status, route, }) => {
79
79
  amount: token.amount,
80
80
  tokenSymbol: token.symbol,
81
81
  chainName: getChainById(token.chainId)?.name,
82
- walletAddress: shortenWalletAddress(route.toAddress),
82
+ walletAddress: shortenAddress(route.toAddress),
83
83
  });
84
84
  }
85
85
  handlePrimaryButton = handleDone;
@@ -96,7 +96,7 @@ export const StatusBottomSheet = ({ status, route, }) => {
96
96
  amount: token.amount,
97
97
  tokenSymbol: token.symbol,
98
98
  chainName: getChainById(token.chainId)?.name,
99
- walletAddress: shortenWalletAddress(route.toAddress),
99
+ walletAddress: shortenAddress(route.toAddress),
100
100
  });
101
101
  }
102
102
  handlePrimaryButton = handlePartialDone;
@@ -113,7 +113,7 @@ export const StatusBottomSheet = ({ status, route, }) => {
113
113
  amount: token.amount,
114
114
  tokenSymbol: token.symbol,
115
115
  chainName: getChainById(token.chainId)?.name,
116
- walletAddress: shortenWalletAddress(route.toAddress),
116
+ walletAddress: shortenAddress(route.toAddress),
117
117
  });
118
118
  }
119
119
  break;
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { LiFi } from '@lifi/sdk';
3
3
  import { createContext, useContext, useMemo } from 'react';
4
+ import { version } from '../../config/version';
4
5
  import { useWidgetConfig } from '../WidgetProvider';
5
6
  let lifi;
6
7
  const SDKContext = createContext(null);
@@ -23,6 +24,7 @@ export const SDKProvider = ({ children, }) => {
23
24
  if (!lifi) {
24
25
  lifi = new LiFi({
25
26
  disableVersionCheck: true,
27
+ widgetVersion: version,
26
28
  ...config,
27
29
  });
28
30
  }
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { LiFiWalletManagement, readActiveWallets, supportedWallets, } from '@lifi/wallet-management';
2
+ import { LiFiWalletManagement, readActiveWallets, supportedWallets, addChain as walletAgnosticAddChain, switchChainAndAddToken as walletAgnosticAddToken, switchChain as walletAgnosticSwitchChain, } from '@lifi/wallet-management';
3
3
  import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from 'react';
4
4
  import { useWidgetConfig } from '../WidgetProvider';
5
5
  const liFiWalletManagement = new LiFiWalletManagement();
@@ -20,19 +20,6 @@ export const WalletProvider = ({ children }) => {
20
20
  const { walletManagement } = useWidgetConfig();
21
21
  const [account, setAccount] = useState({});
22
22
  const [currentWallet, setCurrentWallet] = useState();
23
- useEffect(() => {
24
- const autoConnect = async () => {
25
- const persistedActiveWallets = readActiveWallets();
26
- const activeWallets = supportedWallets.filter((wallet) => persistedActiveWallets.some((perstistedWallet) => perstistedWallet.name === wallet.name));
27
- if (!activeWallets.length) {
28
- return;
29
- }
30
- await liFiWalletManagement.autoConnect(activeWallets);
31
- activeWallets[0].on('walletAccountChanged', handleWalletUpdate);
32
- handleWalletUpdate(activeWallets[0]);
33
- };
34
- autoConnect();
35
- }, []);
36
23
  const handleWalletUpdate = async (wallet) => {
37
24
  setCurrentWallet(wallet);
38
25
  const account = await extractAccountFromSigner(wallet?.account?.signer);
@@ -60,54 +47,102 @@ export const WalletProvider = ({ children }) => {
60
47
  currentWallet.removeAllListeners();
61
48
  handleWalletUpdate(undefined);
62
49
  }
63
- }, [walletManagement, currentWallet]);
50
+ }, [currentWallet, walletManagement]);
64
51
  const switchChain = useCallback(async (chainId) => {
65
- if (walletManagement?.switchChain) {
66
- const signer = await walletManagement.switchChain(chainId);
67
- const account = await extractAccountFromSigner(signer);
68
- setAccount(account);
69
- return true;
70
- }
71
52
  try {
72
- await currentWallet?.switchChain(chainId);
73
- handleWalletUpdate(currentWallet);
53
+ if (walletManagement?.switchChain) {
54
+ const signer = await walletManagement.switchChain(chainId);
55
+ const account = await extractAccountFromSigner(signer);
56
+ setAccount(account);
57
+ }
58
+ else if (!currentWallet) {
59
+ const provider = account.signer?.provider;
60
+ if (!provider) {
61
+ throw new Error(`Switch chain: No provider available`);
62
+ }
63
+ await walletAgnosticSwitchChain(provider, chainId);
64
+ }
65
+ else {
66
+ await currentWallet?.switchChain(chainId);
67
+ handleWalletUpdate(currentWallet);
68
+ }
74
69
  return true;
75
70
  }
76
71
  catch {
77
72
  return false;
78
73
  }
79
- }, [walletManagement, currentWallet]);
74
+ }, [account.signer?.provider, currentWallet, walletManagement]);
80
75
  const addChain = useCallback(async (chainId) => {
81
- if (walletManagement?.addChain) {
82
- return walletManagement.addChain(chainId);
83
- }
84
76
  try {
85
- await currentWallet?.addChain(chainId);
86
- handleWalletUpdate(currentWallet);
77
+ if (walletManagement?.addChain) {
78
+ return walletManagement.addChain(chainId);
79
+ }
80
+ else if (!currentWallet) {
81
+ const provider = account.signer?.provider;
82
+ if (!provider) {
83
+ throw new Error(`Add chain: No provider available`);
84
+ }
85
+ await walletAgnosticAddChain(provider, chainId);
86
+ }
87
+ else {
88
+ await currentWallet?.addChain(chainId);
89
+ handleWalletUpdate(currentWallet);
90
+ }
87
91
  return true;
88
92
  }
89
93
  catch {
90
94
  return false;
91
95
  }
92
- }, [walletManagement, currentWallet]);
96
+ }, [account.signer?.provider, currentWallet, walletManagement]);
93
97
  const addToken = useCallback(async (chainId, token) => {
94
- if (walletManagement?.addToken) {
95
- return walletManagement.addToken(token, chainId);
98
+ try {
99
+ if (walletManagement?.addToken) {
100
+ return walletManagement.addToken(token, chainId);
101
+ }
102
+ else if (!currentWallet) {
103
+ const provider = account.signer?.provider;
104
+ if (!provider) {
105
+ throw new Error(`Add token: No provider available`);
106
+ }
107
+ await walletAgnosticAddToken(provider, chainId, token);
108
+ }
109
+ else {
110
+ await currentWallet?.addToken(chainId, token);
111
+ handleWalletUpdate(currentWallet);
112
+ }
96
113
  }
97
- await currentWallet?.addToken(chainId, token);
98
- handleWalletUpdate(currentWallet);
99
- return;
100
- }, [walletManagement, currentWallet]);
114
+ catch { }
115
+ }, [account.signer?.provider, currentWallet, walletManagement]);
116
+ useEffect(() => {
117
+ const autoConnect = async () => {
118
+ const persistedActiveWallets = readActiveWallets();
119
+ const activeWallets = supportedWallets.filter((wallet) => persistedActiveWallets.some((perstistedWallet) => perstistedWallet.name === wallet.name));
120
+ if (!activeWallets.length) {
121
+ return;
122
+ }
123
+ await liFiWalletManagement.autoConnect(activeWallets);
124
+ activeWallets[0].on('walletAccountChanged', handleWalletUpdate);
125
+ handleWalletUpdate(activeWallets[0]);
126
+ };
127
+ autoConnect();
128
+ }, []);
101
129
  // keep widget in sync with changing external signer object
102
130
  useEffect(() => {
103
131
  if (walletManagement) {
132
+ let ignore = false;
104
133
  const updateAccount = async () => {
105
134
  const account = await extractAccountFromSigner(walletManagement?.signer);
106
- setAccount(account);
135
+ // we should ignore the update if there is a newer one
136
+ if (!ignore) {
137
+ setAccount(account);
138
+ }
107
139
  };
108
140
  updateAccount();
141
+ return () => {
142
+ ignore = true;
143
+ };
109
144
  }
110
- }, [walletManagement, walletManagement?.signer]);
145
+ }, [walletManagement]);
111
146
  const value = useMemo(() => ({
112
147
  connect,
113
148
  disconnect,
@@ -115,16 +150,7 @@ export const WalletProvider = ({ children }) => {
115
150
  addChain,
116
151
  addToken,
117
152
  account,
118
- provider: currentWallet?.account?.provider,
119
- }), [
120
- account,
121
- addChain,
122
- addToken,
123
- connect,
124
- disconnect,
125
- currentWallet,
126
- switchChain,
127
- ]);
153
+ }), [account, addChain, addToken, connect, disconnect, switchChain]);
128
154
  return (_jsx(WalletContext.Provider, { value: value, children: children }));
129
155
  };
130
156
  export const extractAccountFromSigner = async (signer) => {
@@ -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>>;