@lifi/widget 1.18.9 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/App.js +3 -3
  2. package/cjs/App.js +3 -3
  3. package/cjs/components/ActiveSwaps/ActiveSwaps.js +1 -1
  4. package/cjs/components/ActiveSwaps/ActiveSwaps.style.d.ts +0 -14
  5. package/cjs/components/ActiveSwaps/ActiveSwaps.style.js +1 -9
  6. package/cjs/components/AppContainer.d.ts +11 -1
  7. package/cjs/components/AppContainer.js +2 -6
  8. package/cjs/components/BottomSheet/BottomSheet.js +9 -31
  9. package/cjs/components/BottomSheet/types.d.ts +2 -2
  10. package/cjs/components/Card/Card.js +1 -1
  11. package/cjs/components/Card/CardHeader.d.ts +1 -1
  12. package/cjs/components/ChainSelect/ChainSelect.js +1 -1
  13. package/cjs/components/ChainSelect/useChainSelect.js +2 -4
  14. package/cjs/components/Dialog.d.ts +22 -1
  15. package/cjs/components/Dialog.js +23 -19
  16. package/cjs/components/GasSufficiencyMessage/GasSufficiencyMessage.js +19 -22
  17. package/cjs/components/Header/NavigationHeader.js +1 -1
  18. package/cjs/components/Header/WalletHeader.js +2 -2
  19. package/cjs/components/PoweredBy/PoweredBy.js +1 -1
  20. package/cjs/components/ProgressToNextUpdate/ProgressToNextUpdate.js +1 -1
  21. package/cjs/components/ReverseTokensButton/ReverseTokensButton.js +6 -6
  22. package/cjs/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
  23. package/cjs/components/SendToWallet/SendToWallet.d.ts +1 -0
  24. package/cjs/components/SendToWallet/SendToWallet.js +10 -5
  25. package/cjs/components/SendToWallet/SendToWalletButton.js +2 -2
  26. package/cjs/components/Step/StepProcess.js +1 -1
  27. package/cjs/components/SwapButton/SwapButton.js +4 -4
  28. package/cjs/components/SwapButton/types.d.ts +2 -0
  29. package/cjs/components/SwapInput/SwapInput.js +6 -2
  30. package/cjs/components/SwapInput/SwapInputAdornment.js +4 -2
  31. package/cjs/components/SwapInput/SwapInputAdornment.style.js +2 -14
  32. package/cjs/components/SwapRouteCard/SwapRouteCard.js +7 -6
  33. package/cjs/components/SwapRoutes/SwapRoutes.js +4 -4
  34. package/cjs/components/SwapRoutes/SwapRoutesExpanded.d.ts +1 -0
  35. package/cjs/components/SwapRoutes/SwapRoutesExpanded.js +17 -12
  36. package/cjs/components/SwapRoutes/useSetRecommendedRoute.d.ts +2 -0
  37. package/cjs/components/SwapRoutes/useSetRecommendedRoute.js +13 -0
  38. package/cjs/components/TokenList/TokenList.js +9 -6
  39. package/cjs/config/theme.js +22 -8
  40. package/cjs/config/version.d.ts +1 -1
  41. package/cjs/config/version.js +1 -1
  42. package/cjs/hooks/index.d.ts +1 -0
  43. package/cjs/hooks/index.js +1 -0
  44. package/cjs/hooks/useContentHeight.d.ts +2 -0
  45. package/cjs/hooks/useContentHeight.js +18 -1
  46. package/cjs/hooks/useExpandableVariant.d.ts +1 -0
  47. package/cjs/hooks/useExpandableVariant.js +14 -0
  48. package/cjs/hooks/useGasSufficiency.d.ts +3 -2
  49. package/cjs/hooks/useGasSufficiency.js +50 -26
  50. package/cjs/hooks/useSwapRoutes.js +4 -2
  51. package/cjs/hooks/useTokenBalance.js +2 -2
  52. package/cjs/i18n/en/translation.json +15 -7
  53. package/cjs/i18n/index.d.ts +13 -5
  54. package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.js +21 -4
  55. package/cjs/pages/MainPage/MainPage.js +3 -3
  56. package/cjs/pages/SelectWalletPage/SelectWalletPage.js +1 -1
  57. package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +2 -2
  58. package/cjs/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
  59. package/cjs/pages/SwapPage/StatusBottomSheet.js +4 -4
  60. package/cjs/pages/SwapPage/StatusBottomSheet.style.d.ts +0 -4
  61. package/cjs/pages/SwapPage/StatusBottomSheet.style.js +23 -17
  62. package/cjs/pages/SwapPage/SwapPage.js +38 -17
  63. package/cjs/pages/SwapPage/TokenValueBottomSheet.d.ts +11 -0
  64. package/cjs/pages/SwapPage/TokenValueBottomSheet.js +42 -0
  65. package/cjs/providers/SwapFormProvider/SwapFormProvider.js +3 -2
  66. package/cjs/providers/SwapFormProvider/URLSearchParamsBuilder.d.ts +1 -0
  67. package/cjs/providers/SwapFormProvider/URLSearchParamsBuilder.js +46 -0
  68. package/cjs/providers/SwapFormProvider/types.d.ts +4 -4
  69. package/cjs/providers/SwapFormProvider/types.js +2 -2
  70. package/cjs/providers/WalletProvider/WalletFormUpdate.d.ts +5 -0
  71. package/cjs/providers/WalletProvider/WalletFormUpdate.js +64 -0
  72. package/cjs/providers/WalletProvider/WalletProvider.js +3 -58
  73. package/cjs/providers/WidgetProvider/WidgetProvider.js +12 -5
  74. package/cjs/stores/routes/index.d.ts +1 -1
  75. package/cjs/stores/routes/index.js +1 -1
  76. package/cjs/stores/routes/types.d.ts +5 -5
  77. package/cjs/stores/routes/useRecommendedRouteStore.d.ts +4 -0
  78. package/cjs/stores/routes/{useSelectedRouteStore.js → useRecommendedRouteStore.js} +4 -4
  79. package/cjs/stores/routes/useRouteExecutionStore.js +9 -2
  80. package/cjs/types/widget.d.ts +1 -0
  81. package/components/ActiveSwaps/ActiveSwaps.js +3 -3
  82. package/components/ActiveSwaps/ActiveSwaps.style.d.ts +0 -14
  83. package/components/ActiveSwaps/ActiveSwaps.style.js +1 -9
  84. package/components/AppContainer.d.ts +11 -1
  85. package/components/AppContainer.js +1 -4
  86. package/components/BottomSheet/BottomSheet.js +10 -32
  87. package/components/BottomSheet/types.d.ts +2 -2
  88. package/components/Card/Card.js +1 -1
  89. package/components/Card/CardHeader.d.ts +1 -1
  90. package/components/ChainSelect/ChainSelect.js +1 -1
  91. package/components/ChainSelect/useChainSelect.js +2 -4
  92. package/components/Dialog.d.ts +22 -1
  93. package/components/Dialog.js +23 -19
  94. package/components/GasSufficiencyMessage/GasSufficiencyMessage.js +21 -24
  95. package/components/Header/NavigationHeader.js +2 -2
  96. package/components/Header/WalletHeader.js +2 -2
  97. package/components/PoweredBy/PoweredBy.js +1 -1
  98. package/components/ProgressToNextUpdate/ProgressToNextUpdate.js +1 -1
  99. package/components/ReverseTokensButton/ReverseTokensButton.js +6 -6
  100. package/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
  101. package/components/SendToWallet/SendToWallet.d.ts +1 -0
  102. package/components/SendToWallet/SendToWallet.js +9 -5
  103. package/components/SendToWallet/SendToWalletButton.js +2 -2
  104. package/components/Step/StepProcess.js +1 -1
  105. package/components/SwapButton/SwapButton.js +4 -4
  106. package/components/SwapButton/types.d.ts +2 -0
  107. package/components/SwapInput/SwapInput.js +6 -2
  108. package/components/SwapInput/SwapInputAdornment.js +4 -2
  109. package/components/SwapInput/SwapInputAdornment.style.js +3 -15
  110. package/components/SwapRouteCard/SwapRouteCard.js +8 -7
  111. package/components/SwapRoutes/SwapRoutes.js +4 -4
  112. package/components/SwapRoutes/SwapRoutesExpanded.d.ts +1 -0
  113. package/components/SwapRoutes/SwapRoutesExpanded.js +16 -12
  114. package/components/SwapRoutes/useSetRecommendedRoute.d.ts +2 -0
  115. package/components/SwapRoutes/useSetRecommendedRoute.js +9 -0
  116. package/components/TokenList/TokenList.js +9 -6
  117. package/config/theme.js +22 -8
  118. package/config/version.d.ts +1 -1
  119. package/config/version.js +1 -1
  120. package/hooks/index.d.ts +1 -0
  121. package/hooks/index.js +1 -0
  122. package/hooks/useContentHeight.d.ts +2 -0
  123. package/hooks/useContentHeight.js +16 -0
  124. package/hooks/useExpandableVariant.d.ts +1 -0
  125. package/hooks/useExpandableVariant.js +10 -0
  126. package/hooks/useGasSufficiency.d.ts +3 -2
  127. package/hooks/useGasSufficiency.js +50 -26
  128. package/hooks/useSwapRoutes.js +4 -2
  129. package/hooks/useTokenBalance.js +2 -2
  130. package/i18n/en/translation.json +15 -7
  131. package/i18n/index.d.ts +13 -5
  132. package/package.json +11 -11
  133. package/pages/ActiveSwapsPage/ActiveSwapsPage.js +24 -7
  134. package/pages/MainPage/MainPage.js +3 -3
  135. package/pages/SelectWalletPage/SelectWalletPage.js +1 -1
  136. package/pages/SwapDetailsPage/SwapDetailsPage.js +2 -2
  137. package/pages/SwapHistoryPage/SwapHistoryPage.js +2 -2
  138. package/pages/SwapPage/StatusBottomSheet.js +5 -5
  139. package/pages/SwapPage/StatusBottomSheet.style.d.ts +0 -4
  140. package/pages/SwapPage/StatusBottomSheet.style.js +23 -17
  141. package/pages/SwapPage/SwapPage.js +41 -20
  142. package/pages/SwapPage/TokenValueBottomSheet.d.ts +11 -0
  143. package/pages/SwapPage/TokenValueBottomSheet.js +38 -0
  144. package/providers/SwapFormProvider/SwapFormProvider.js +4 -3
  145. package/providers/SwapFormProvider/URLSearchParamsBuilder.d.ts +1 -0
  146. package/providers/SwapFormProvider/URLSearchParamsBuilder.js +42 -0
  147. package/providers/SwapFormProvider/types.d.ts +4 -4
  148. package/providers/SwapFormProvider/types.js +2 -2
  149. package/providers/WalletProvider/WalletFormUpdate.d.ts +5 -0
  150. package/providers/WalletProvider/WalletFormUpdate.js +60 -0
  151. package/providers/WalletProvider/WalletProvider.js +5 -60
  152. package/providers/WidgetProvider/WidgetProvider.js +12 -5
  153. package/stores/routes/index.d.ts +1 -1
  154. package/stores/routes/index.js +1 -1
  155. package/stores/routes/types.d.ts +5 -5
  156. package/stores/routes/useRecommendedRouteStore.d.ts +4 -0
  157. package/stores/routes/useRecommendedRouteStore.js +9 -0
  158. package/stores/routes/useRouteExecutionStore.js +9 -2
  159. package/tsconfig.cjs.tsbuildinfo +1 -1
  160. package/types/widget.d.ts +1 -0
  161. package/cjs/components/SwapRoutes/useSetSelectedRoute.d.ts +0 -2
  162. package/cjs/components/SwapRoutes/useSetSelectedRoute.js +0 -13
  163. package/cjs/stores/routes/useSelectedRouteStore.d.ts +0 -4
  164. package/components/SwapRoutes/useSetSelectedRoute.d.ts +0 -2
  165. package/components/SwapRoutes/useSetSelectedRoute.js +0 -9
  166. package/stores/routes/useSelectedRouteStore.d.ts +0 -4
  167. package/stores/routes/useSelectedRouteStore.js +0 -9
@@ -30,11 +30,15 @@ const SwapInput = ({ formType }) => {
30
30
  const isSelected = !!(chain && token);
31
31
  const handleChange = (event) => {
32
32
  const { value } = event.target;
33
- setValue(amountKey, (0, utils_1.formatAmount)(value, true));
33
+ const formattedAmount = (0, utils_1.formatAmount)(value, true);
34
+ setValue(amountKey, formattedAmount, {
35
+ shouldTouch: true,
36
+ });
34
37
  };
35
38
  const handleBlur = (event) => {
36
39
  const { value } = event.target;
37
- setValue(amountKey, (0, utils_1.formatAmount)(value));
40
+ const formattedAmount = (0, utils_1.formatAmount)(value);
41
+ setValue(amountKey, formattedAmount);
38
42
  };
39
43
  (0, react_1.useLayoutEffect)(() => {
40
44
  (0, utils_1.fitInputText)(SwapInput_style_1.maxInputFontSize, SwapInput_style_1.minInputFontSize, ref.current);
@@ -20,8 +20,10 @@ const SwapInputAdornment = ({ formType }) => {
20
20
  const { token, isLoading } = (0, hooks_1.useTokenAddressBalance)(chainId, tokenAddress);
21
21
  const handleMax = () => {
22
22
  var _a;
23
- setValue(providers_1.SwapFormKeyHelper.getAmountKey(formType), (_a = token === null || token === void 0 ? void 0 : token.amount) !== null && _a !== void 0 ? _a : '');
23
+ setValue(providers_1.SwapFormKeyHelper.getAmountKey(formType), (_a = token === null || token === void 0 ? void 0 : token.amount) !== null && _a !== void 0 ? _a : '', {
24
+ shouldTouch: true,
25
+ });
24
26
  };
25
- return ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, Object.assign({ position: "end" }, { children: isLoading && tokenAddress ? ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: 46, height: 20, sx: { borderRadius: 0.5 } })) : formType === 'from' && (token === null || token === void 0 ? void 0 : token.amount) ? ((0, jsx_runtime_1.jsx)(SwapInputAdornment_style_1.Button, Object.assign({ onClick: handleMax, variant: "outlined" }, { children: t('button.max') }))) : null })));
27
+ return ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, Object.assign({ position: "end" }, { children: isLoading && tokenAddress ? ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: 46, height: 24, sx: { borderRadius: 0.5 } })) : formType === 'from' && (token === null || token === void 0 ? void 0 : token.amount) ? ((0, jsx_runtime_1.jsx)(SwapInputAdornment_style_1.Button, Object.assign({ onClick: handleMax }, { children: t('button.max') }))) : null })));
26
28
  };
27
29
  exports.SwapInputAdornment = SwapInputAdornment;
@@ -4,20 +4,8 @@ exports.Button = void 0;
4
4
  const material_1 = require("@mui/material");
5
5
  const styles_1 = require("@mui/material/styles");
6
6
  exports.Button = (0, styles_1.styled)(material_1.Button)(({ theme }) => ({
7
- borderColor: theme.palette.mode === 'light'
8
- ? theme.palette.grey[300]
9
- : theme.palette.grey[800],
10
- color: theme.palette.text.secondary,
11
- padding: theme.spacing(0.125, 1, 0.375, 1),
12
- lineHeight: 1,
7
+ padding: theme.spacing(0.5, 1, 0.625, 1),
8
+ lineHeight: 1.0715,
13
9
  fontSize: '0.875rem',
14
10
  minWidth: 'unset',
15
- '&:hover': {
16
- color: theme.palette.mode === 'light'
17
- ? theme.palette.primary.main
18
- : theme.palette.text.primary,
19
- borderColor: theme.palette.mode === 'light'
20
- ? (0, styles_1.lighten)(theme.palette.primary.main, 0.5)
21
- : theme.palette.text.secondary,
22
- },
23
11
  }));
@@ -34,17 +34,18 @@ const SwapRouteCard = (_a) => {
34
34
  e.stopPropagation();
35
35
  setCardExpanded((expanded) => !expanded);
36
36
  };
37
- return ((0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({ dense: variant === 'dense', variant: active ? 'selected' : 'default', selectionColor: "secondary", indented: true }, other, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center", mb: 2 }, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_style_1.Label, Object.assign({ active: active !== null && active !== void 0 ? active : label !== alternativeTag }, { children: label })), variant === 'stretched' ? ((0, jsx_runtime_1.jsx)(exports.SwapRouteCardEssentials, { route: route })) : null] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(Token_1.Token, { token: Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }), step: variant === 'stretched' ? route.steps[0] : undefined }), variant === 'stretched' && !expanded ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_style_1.IconButton, Object.assign({ onClick: handleExpand, size: "small" }, { children: cardExpanded ? (0, jsx_runtime_1.jsx)(icons_material_1.ExpandLess, {}) : (0, jsx_runtime_1.jsx)(icons_material_1.ExpandMore, {}) }))) : null] })), (0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ mountOnEnter: true, unmountOnExit: true, in: cardExpanded }, { children: route.steps.map((step) => ((0, jsx_runtime_1.jsx)(StepActions_1.StepActions, { step: step, mt: 2 }, step.id))) })), variant !== 'stretched' ? ((0, jsx_runtime_1.jsx)(exports.SwapRouteCardEssentials, { route: route, dense: true })) : null] })));
37
+ return ((0, jsx_runtime_1.jsxs)(Card_1.Card, Object.assign({ dense: variant === 'dense', variant: active ? 'selected' : 'default', selectionColor: "secondary", indented: true }, other, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center", mb: 2 }, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_style_1.Label, Object.assign({ active: active !== null && active !== void 0 ? active : label !== alternativeTag }, { children: label })), variant === 'stretched' ? ((0, jsx_runtime_1.jsx)(exports.SwapRouteCardEssentials, { route: route })) : null] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: "space-between", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(Token_1.Token, { token: Object.assign(Object.assign({}, route.toToken), { amount: route.toAmount }), step: variant === 'stretched' ? route.steps[0] : undefined }), variant === 'stretched' && !expanded ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_style_1.IconButton, Object.assign({ onClick: handleExpand, size: "small" }, { children: cardExpanded ? (0, jsx_runtime_1.jsx)(icons_material_1.ExpandLess, {}) : (0, jsx_runtime_1.jsx)(icons_material_1.ExpandMore, {}) }))) : null] })), (0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ timeout: 225, in: cardExpanded, mountOnEnter: true, unmountOnExit: true }, { children: route.steps.map((step) => ((0, jsx_runtime_1.jsx)(StepActions_1.StepActions, { step: step, mt: 2 }, step.id))) })), variant !== 'stretched' ? ((0, jsx_runtime_1.jsx)(exports.SwapRouteCardEssentials, { route: route, dense: true })) : null] })));
38
38
  };
39
39
  exports.SwapRouteCard = SwapRouteCard;
40
40
  const SwapRouteCardEssentials = ({ route, dense }) => {
41
41
  var _a;
42
42
  const { t } = (0, react_i18next_1.useTranslation)();
43
- const executionTime = (route.steps
43
+ const executionTimeMinutes = Math.ceil(route.steps
44
44
  .map((step) => step.estimate.executionDuration)
45
- .reduce((duration, x) => duration + x) / 60).toFixed(0) || 1;
46
- return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: dense ? 'space-between' : 'flex-end', flex: 1, pl: dense ? 0 : 2, mt: dense ? 2 : 0 }, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", alignItems: "center", pr: dense ? 0 : 2 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.EvStationOutlined, { fontSize: dense ? 'medium' : 'small' }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: t(`swap.currency`, { value: (_a = route.gasCostUSD) !== null && _a !== void 0 ? _a : 0.01 }) }))] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", alignItems: "center", pr: dense ? 0 : 2 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.AccessTime, { fontSize: dense ? 'medium' : 'small' }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: t('swap.estimatedTime', {
47
- value: executionTime,
48
- }) }))] })), !dense ? ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.LayersOutlined, { fontSize: dense ? 'medium' : 'small' }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: route.steps.length }))] }))) : null] })));
45
+ .reduce((duration, x) => duration + x, 0) / 60);
46
+ const gasCostUSD = parseFloat((_a = route.gasCostUSD) !== null && _a !== void 0 ? _a : '') || 0.01;
47
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", justifyContent: dense ? 'space-between' : 'flex-end', flex: 1, pl: dense ? 0 : 2, mt: dense ? 2 : 0 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: t(`tooltip.estimatedNetworkFee`), placement: "top", enterDelay: 400, arrow: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", alignItems: "center", mr: dense ? 0 : 2 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.EvStationOutlined, { fontSize: dense ? 'medium' : 'small' }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: t(`swap.currency`, { value: gasCostUSD }) }))] })) })), (0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: t(`tooltip.estimatedTime`), placement: "top", enterDelay: 400, arrow: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", alignItems: "center", mr: dense ? 0 : 2 }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.AccessTime, { fontSize: dense ? 'medium' : 'small' }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: t('swap.estimatedTime', {
48
+ value: executionTimeMinutes,
49
+ }) }))] })) })), !dense ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: t(`tooltip.numberOfSteps`), placement: "top", enterDelay: 400, arrow: true }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ display: "flex", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ lineHeight: 0, mr: 0.5, color: "grey.500" }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.LayersOutlined, { fontSize: dense ? 'medium' : 'small' }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 14, color: "text.primary", fontWeight: "500", lineHeight: 1 }, { children: route.steps.length }))] })) }))) : null] })));
49
50
  };
50
51
  exports.SwapRouteCardEssentials = SwapRouteCardEssentials;
@@ -13,14 +13,14 @@ const SwapRouteCard_1 = require("../../components/SwapRouteCard");
13
13
  const hooks_1 = require("../../hooks");
14
14
  const utils_1 = require("../../utils");
15
15
  const SwapRoutes_style_1 = require("./SwapRoutes.style");
16
- const useSetSelectedRoute_1 = require("./useSetSelectedRoute");
16
+ const useSetRecommendedRoute_1 = require("./useSetRecommendedRoute");
17
17
  const SwapRoutes = (props) => {
18
18
  const { t } = (0, react_i18next_1.useTranslation)();
19
19
  const navigate = (0, react_router_dom_1.useNavigate)();
20
20
  const { isValid, isValidating } = (0, react_hook_form_1.useFormState)();
21
21
  const { routes, isLoading, isFetching, isFetched, dataUpdatedAt, refetchTime, refetch, } = (0, hooks_1.useSwapRoutes)();
22
22
  const currentRoute = routes === null || routes === void 0 ? void 0 : routes[0];
23
- (0, useSetSelectedRoute_1.useSetSelectedRoute)(currentRoute, isFetching);
23
+ (0, useSetRecommendedRoute_1.useSetRecommendedRoute)(currentRoute, isFetching);
24
24
  if (!currentRoute && !isLoading && !isFetching && !isFetched) {
25
25
  return null;
26
26
  }
@@ -33,9 +33,9 @@ const SwapRoutes = (props) => {
33
33
  top: 8,
34
34
  right: 8,
35
35
  } }), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ sx: { display: 'flex' } }, { children: [(0, jsx_runtime_1.jsx)(SwapRoutes_style_1.Stack, Object.assign({ direction: "row", spacing: 2, my: 2, ml: 2, mr: routeNotFound ? 2 : 1, sx: {
36
- borderWidth: !routeNotFound && (isFetching || (routes && routes.length > 1))
36
+ borderRightWidth: !routeNotFound && (isFetching || (routes && routes.length > 1))
37
37
  ? 1
38
38
  : 0,
39
- } }, { children: isLoading || isFetching ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { minWidth: "80%", variant: "dense" }), (0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { minWidth: "80%", variant: "dense" })] })) : !currentRoute ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteNotFoundCard, {})) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { minWidth: routes.length > 1 ? '80%' : '100%', route: currentRoute, variant: "dense", active: true }), routes.length > 1 ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { minWidth: "80%", route: routes[1], variant: "dense" })) : null] })) })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: !routeNotFound ? ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ py: 1, pr: 1 }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: handleCardClick, size: "medium", "aria-label": "swap-routes", disabled: isValidating || !isValid }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.KeyboardArrowRight, {}) })) }))) : null }))] }))] })));
39
+ } }, { children: isLoading || isFetching ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { minWidth: "80%", variant: "dense" }), (0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { minWidth: "80%", variant: "dense" })] })) : !currentRoute ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteNotFoundCard, {})) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { minWidth: routes.length > 1 ? '80%' : '100%', route: currentRoute, variant: "dense", active: true }), routes.length > 1 ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { minWidth: "80%", route: routes[1], variant: "dense" })) : null] })) })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ sx: { display: 'flex', alignItems: 'center' } }, { children: !routeNotFound ? ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ py: 1, pr: 1 }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: handleCardClick, size: "medium", disabled: isValidating || !isValid }, { children: (0, jsx_runtime_1.jsx)(icons_material_1.KeyboardArrowRight, {}) })) }))) : null }))] }))] })));
40
40
  };
41
41
  exports.SwapRoutes = SwapRoutes;
@@ -1,2 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  export declare const SwapRoutesExpanded: () => JSX.Element;
3
+ export declare const SwapRoutesExpandedElement: () => JSX.Element;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SwapRoutesExpanded = void 0;
3
+ exports.SwapRoutesExpandedElement = exports.SwapRoutesExpanded = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const material_1 = require("@mui/material");
6
6
  const react_hook_form_1 = require("react-hook-form");
@@ -13,8 +13,19 @@ const utils_1 = require("../../utils");
13
13
  const ProgressToNextUpdate_1 = require("../ProgressToNextUpdate");
14
14
  const SwapRouteCard_1 = require("../SwapRouteCard");
15
15
  const SwapRoutes_style_1 = require("./SwapRoutes.style");
16
- const useSetSelectedRoute_1 = require("./useSetSelectedRoute");
16
+ const useSetRecommendedRoute_1 = require("./useSetRecommendedRoute");
17
+ const timeout = { enter: 225, exit: 225, appear: 0 };
17
18
  const SwapRoutesExpanded = () => {
19
+ const element = (0, react_router_dom_1.useRoutes)([
20
+ {
21
+ path: '/',
22
+ element: null,
23
+ },
24
+ ]);
25
+ return ((0, jsx_runtime_1.jsx)(SwapRoutes_style_1.CollapseContainer, { children: (0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ timeout: timeout, in: !!element, orientation: "horizontal" }, { children: (0, jsx_runtime_1.jsx)(material_1.Grow, Object.assign({ timeout: timeout, in: !!element, mountOnEnter: true, unmountOnExit: true }, { children: (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(exports.SwapRoutesExpandedElement, {}) }) })) })) }));
26
+ };
27
+ exports.SwapRoutesExpanded = SwapRoutesExpanded;
28
+ const SwapRoutesExpandedElement = () => {
18
29
  const { t } = (0, react_i18next_1.useTranslation)();
19
30
  const navigate = (0, react_router_dom_1.useNavigate)();
20
31
  const setExecutableRoute = (0, stores_1.useSetExecutableRoute)();
@@ -22,13 +33,7 @@ const SwapRoutesExpanded = () => {
22
33
  const { isValid, isValidating } = (0, react_hook_form_1.useFormState)();
23
34
  const { routes, isLoading, isFetching, isFetched, dataUpdatedAt, refetchTime, refetch, } = (0, hooks_1.useSwapRoutes)();
24
35
  const currentRoute = routes === null || routes === void 0 ? void 0 : routes[0];
25
- (0, useSetSelectedRoute_1.useSetSelectedRoute)(currentRoute, isFetching);
26
- const { pathname } = (0, react_router_dom_1.useLocation)();
27
- const cleanedPathname = pathname.endsWith('/')
28
- ? pathname.slice(0, -1)
29
- : pathname;
30
- const path = cleanedPathname.substring(cleanedPathname.lastIndexOf('/') + 1);
31
- const hasPath = utils_1.navigationRoutesValues.includes(path);
36
+ (0, useSetRecommendedRoute_1.useSetRecommendedRoute)(currentRoute, isFetching);
32
37
  const handleRouteClick = (route) => {
33
38
  if (isValid && !isValidating) {
34
39
  setExecutableRoute(route);
@@ -37,8 +42,8 @@ const SwapRoutesExpanded = () => {
37
42
  });
38
43
  }
39
44
  };
40
- const expanded = Boolean(currentRoute || isLoading || isFetching || isFetched) && !hasPath;
45
+ const expanded = Boolean(currentRoute || isLoading || isFetching || isFetched);
41
46
  const routeNotFound = !currentRoute && !isLoading && !isFetching && expanded;
42
- return ((0, jsx_runtime_1.jsx)(SwapRoutes_style_1.CollapseContainer, { children: (0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ appear: true, timeout: 225, in: expanded, orientation: "horizontal" }, { children: (0, jsx_runtime_1.jsx)(material_1.Grow, Object.assign({ appear: true, timeout: 225, in: expanded }, { children: (0, jsx_runtime_1.jsx)(SwapRoutes_style_1.Container, Object.assign({ sx: containerStyle, enableColorScheme: true }, { children: (0, jsx_runtime_1.jsxs)(SwapRoutes_style_1.ScrollableContainer, { children: [(0, jsx_runtime_1.jsxs)(SwapRoutes_style_1.Header, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 18, fontWeight: "700", flex: 1, noWrap: true }, { children: t('swap.routes') })), (0, jsx_runtime_1.jsx)(ProgressToNextUpdate_1.ProgressToNextUpdate, { updatedAt: dataUpdatedAt || new Date().getTime(), timeToUpdate: refetchTime, isLoading: isFetching, onClick: () => refetch(), sx: { marginRight: -1 } })] }), (0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ direction: "column", spacing: 2, flex: 1, paddingX: 3, paddingBottom: 3 }, { children: routeNotFound ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteNotFoundCard, {})) : isLoading || isFetching ? (Array.from({ length: 3 }).map((_, index) => ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { variant: "stretched" }, index)))) : (routes === null || routes === void 0 ? void 0 : routes.map((route, index) => ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { route: route, onClick: () => handleRouteClick(route), active: index === 0, variant: "stretched", expanded: (routes === null || routes === void 0 ? void 0 : routes.length) <= 2 }, route.id)))) }))] }) })) })) })) }));
47
+ return ((0, jsx_runtime_1.jsx)(material_1.Collapse, Object.assign({ timeout: timeout.enter, in: expanded, orientation: "horizontal" }, { children: (0, jsx_runtime_1.jsx)(material_1.Grow, Object.assign({ timeout: timeout.enter, in: expanded, mountOnEnter: true, unmountOnExit: true }, { children: (0, jsx_runtime_1.jsx)(SwapRoutes_style_1.Container, Object.assign({ sx: containerStyle, enableColorScheme: true }, { children: (0, jsx_runtime_1.jsxs)(SwapRoutes_style_1.ScrollableContainer, { children: [(0, jsx_runtime_1.jsxs)(SwapRoutes_style_1.Header, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ fontSize: 18, fontWeight: "700", flex: 1, noWrap: true }, { children: t('swap.routes') })), (0, jsx_runtime_1.jsx)(ProgressToNextUpdate_1.ProgressToNextUpdate, { updatedAt: dataUpdatedAt || new Date().getTime(), timeToUpdate: refetchTime, isLoading: isFetching, onClick: () => refetch(), sx: { marginRight: -1 } })] }), (0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ direction: "column", spacing: 2, flex: 1, paddingX: 3, paddingBottom: 3 }, { children: routeNotFound ? ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteNotFoundCard, {})) : isLoading || isFetching ? (Array.from({ length: 3 }).map((_, index) => ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCardSkeleton, { variant: "stretched" }, index)))) : (routes === null || routes === void 0 ? void 0 : routes.map((route, index) => ((0, jsx_runtime_1.jsx)(SwapRouteCard_1.SwapRouteCard, { route: route, onClick: () => handleRouteClick(route), active: index === 0, variant: "stretched", expanded: (routes === null || routes === void 0 ? void 0 : routes.length) <= 2 }, route.id)))) }))] }) })) })) })));
43
48
  };
44
- exports.SwapRoutesExpanded = SwapRoutesExpanded;
49
+ exports.SwapRoutesExpandedElement = SwapRoutesExpandedElement;
@@ -0,0 +1,2 @@
1
+ import type { Route } from '@lifi/sdk';
2
+ export declare const useSetRecommendedRoute: (currentRoute?: Route, isFetching?: boolean) => void;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSetRecommendedRoute = void 0;
4
+ const react_1 = require("react");
5
+ const stores_1 = require("../../stores");
6
+ const useSetRecommendedRoute = (currentRoute, isFetching) => {
7
+ const setRecommendedRoute = (0, stores_1.useRecommendedRouteStore)((state) => state.setRecommendedRoute);
8
+ (0, react_1.useEffect)(() => {
9
+ setRecommendedRoute(!isFetching ? currentRoute : undefined);
10
+ return () => setRecommendedRoute(undefined);
11
+ }, [currentRoute, isFetching, setRecommendedRoute]);
12
+ };
13
+ exports.useSetRecommendedRoute = useSetRecommendedRoute;
@@ -39,23 +39,26 @@ const TokenList = ({ formType, height, onClick, }) => {
39
39
  : filteredTokens;
40
40
  const handleTokenClick = (0, react_1.useCallback)((tokenAddress) => {
41
41
  setValue(providers_1.SwapFormKeyHelper.getTokenKey(formType), tokenAddress, {
42
- shouldDirty: true,
42
+ shouldTouch: true,
43
+ });
44
+ // Set chain again to trigger URL builder update
45
+ setValue(providers_1.SwapFormKeyHelper.getChainKey(formType), selectedChainId, {
46
+ shouldTouch: true,
43
47
  });
44
48
  setValue(providers_1.SwapFormKeyHelper.getAmountKey(formType), '');
45
49
  const oppositeFormType = formType === 'from' ? 'to' : 'from';
46
- const [selectedOppositeToken, selectedOppositeChain, selectedChain] = getValues([
50
+ const [selectedOppositeToken, selectedOppositeChainId] = getValues([
47
51
  providers_1.SwapFormKeyHelper.getTokenKey(oppositeFormType),
48
52
  providers_1.SwapFormKeyHelper.getChainKey(oppositeFormType),
49
- providers_1.SwapFormKeyHelper.getChainKey(formType),
50
53
  ]);
51
54
  if (selectedOppositeToken === tokenAddress &&
52
- selectedOppositeChain === selectedChain) {
55
+ selectedOppositeChainId === selectedChainId) {
53
56
  setValue(providers_1.SwapFormKeyHelper.getTokenKey(oppositeFormType), '', {
54
- shouldDirty: false,
57
+ shouldTouch: true,
55
58
  });
56
59
  }
57
60
  onClick === null || onClick === void 0 ? void 0 : onClick();
58
- }, [formType, getValues, onClick, setValue]);
61
+ }, [formType, getValues, onClick, selectedChainId, setValue]);
59
62
  return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ ref: parentRef, style: { height, overflow: 'auto' } }, { children: [!tokens.length && !isLoading ? ((0, jsx_runtime_1.jsx)(TokenNotFound_1.TokenNotFound, { formType: formType })) : null, (0, jsx_runtime_1.jsx)(VirtualizedTokenList_1.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 })] })));
60
63
  };
61
64
  exports.TokenList = TokenList;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTheme = void 0;
4
+ const LoadingButton_1 = require("@mui/lab/LoadingButton");
4
5
  const colors_1 = require("@mui/material/colors");
5
6
  const DialogActions_1 = require("@mui/material/DialogActions");
6
7
  const styles_1 = require("@mui/material/styles");
@@ -48,6 +49,9 @@ const createTheme = (mode, theme = {}) => {
48
49
  const primaryMainColor = (_c = (_b = (_a = theme.palette) === null || _a === void 0 ? void 0 : _a.primary) === null || _b === void 0 ? void 0 : _b.main) !== null && _c !== void 0 ? _c : palette.primary.main;
49
50
  const primaryLightColor = (0, styles_1.lighten)((_f = (_e = (_d = theme.palette) === null || _d === void 0 ? void 0 : _d.primary) === null || _e === void 0 ? void 0 : _e.main) !== null && _f !== void 0 ? _f : palette.primary.main, 0.5);
50
51
  const primaryDarkColor = (0, styles_1.darken)((_j = (_h = (_g = theme.palette) === null || _g === void 0 ? void 0 : _g.primary) === null || _h === void 0 ? void 0 : _h.main) !== null && _j !== void 0 ? _j : palette.primary.main, 0.2);
52
+ const contrastButtonColor = (0, styles_1.getContrastRatio)(colors_1.common.white, primaryMainColor) >= 3
53
+ ? colors_1.common.white
54
+ : colors_1.common.black;
51
55
  return (0, styles_1.createTheme)({
52
56
  typography: Object.assign({ fontFamily: 'Inter var, Inter, sans-serif' }, theme.typography),
53
57
  palette: Object.assign(Object.assign(Object.assign({ mode }, palette), { primary: {
@@ -83,13 +87,25 @@ const createTheme = (mode, theme = {}) => {
83
87
  borderRadius: (_v = (_u = theme.shape) === null || _u === void 0 ? void 0 : _u.borderRadiusSecondary) !== null && _v !== void 0 ? _v : shape.borderRadiusSecondary,
84
88
  textTransform: 'none',
85
89
  fontSize: '1rem',
86
- '&.Mui-disabled, &.Mui-disabled:hover': {
90
+ [`&.Mui-disabled, &.Mui-disabled:hover`]: {
87
91
  color: mode === 'light'
88
- ? 'rgb(0 0 0 / 70%)'
89
- : 'rgb(255 255 255 / 70%)',
92
+ ? 'rgb(0 0 0 / 56%)'
93
+ : 'rgb(255 255 255 / 56%)',
90
94
  cursor: 'not-allowed',
91
95
  pointerEvents: 'auto',
92
96
  },
97
+ [`&.${LoadingButton_1.loadingButtonClasses.loading}.Mui-disabled`]: {
98
+ backgroundColor: primaryMainColor,
99
+ color: contrastButtonColor,
100
+ cursor: 'auto',
101
+ pointerEvents: 'auto',
102
+ },
103
+ [`.${LoadingButton_1.loadingButtonClasses.loadingIndicator}`]: {
104
+ color: contrastButtonColor,
105
+ },
106
+ [`&.${LoadingButton_1.loadingButtonClasses.root}.${LoadingButton_1.loadingButtonClasses.loading}`]: {
107
+ color: 'transparent',
108
+ },
93
109
  }, text: {
94
110
  backgroundColor: (0, styles_1.alpha)(primaryMainColor, 0.08),
95
111
  '&:hover': {
@@ -97,9 +113,7 @@ const createTheme = (mode, theme = {}) => {
97
113
  },
98
114
  }, contained: {
99
115
  '&:hover': {
100
- color: (0, styles_1.getContrastRatio)(colors_1.common.white, primaryMainColor) >= 3
101
- ? colors_1.common.white
102
- : colors_1.common.black,
116
+ color: contrastButtonColor,
103
117
  },
104
118
  }, sizeMedium: {
105
119
  padding: '10px 16px',
@@ -117,10 +131,10 @@ const createTheme = (mode, theme = {}) => {
117
131
  },
118
132
  },
119
133
  text: {
120
- backgroundColor: paletteDark.background.paper,
134
+ backgroundColor: (0, styles_1.lighten)(paletteDark.background.paper, 0.08),
121
135
  color: colors_1.common.white,
122
136
  '&:hover': {
123
- backgroundColor: (0, styles_1.lighten)(paletteDark.background.paper, 0.02),
137
+ backgroundColor: (0, styles_1.lighten)(paletteDark.background.paper, 0.12),
124
138
  },
125
139
  },
126
140
  }
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "1.18.9";
2
+ export declare const version = "1.20.0";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = exports.name = void 0;
4
4
  exports.name = '@lifi/widget';
5
- exports.version = '1.18.9';
5
+ exports.version = '1.20.0';
@@ -2,6 +2,7 @@ export * from './useChain';
2
2
  export * from './useChains';
3
3
  export * from './useContentHeight';
4
4
  export * from './useDebouncedWatch';
5
+ export * from './useExpandableVariant';
5
6
  export * from './useFeaturedTokens';
6
7
  export * from './useGasSufficiency';
7
8
  export * from './useInitializer';
@@ -18,6 +18,7 @@ __exportStar(require("./useChain"), exports);
18
18
  __exportStar(require("./useChains"), exports);
19
19
  __exportStar(require("./useContentHeight"), exports);
20
20
  __exportStar(require("./useDebouncedWatch"), exports);
21
+ __exportStar(require("./useExpandableVariant"), exports);
21
22
  __exportStar(require("./useFeaturedTokens"), exports);
22
23
  __exportStar(require("./useGasSufficiency"), exports);
23
24
  __exportStar(require("./useInitializer"), exports);
@@ -1 +1,3 @@
1
+ import type { MutableRefObject } from 'react';
1
2
  export declare const useContentHeight: () => number;
3
+ export declare const useSetContentHeight: (ref: MutableRefObject<HTMLElement | undefined>) => void;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useContentHeight = void 0;
3
+ exports.useSetContentHeight = exports.useContentHeight = void 0;
4
4
  const react_1 = require("react");
5
5
  const utils_1 = require("../utils");
6
+ const useScrollableContainer_1 = require("./useScrollableContainer");
6
7
  const getContentHeight = () => {
7
8
  const headerElement = document.getElementById(utils_1.ElementId.Header);
8
9
  const containerElement = document.getElementById(utils_1.ElementId.ScrollableContainer);
@@ -25,3 +26,19 @@ const useContentHeight = () => {
25
26
  return contentHeight;
26
27
  };
27
28
  exports.useContentHeight = useContentHeight;
29
+ const useSetContentHeight = (ref) => {
30
+ (0, react_1.useLayoutEffect)(() => {
31
+ var _a;
32
+ const scrollableContainer = (0, useScrollableContainer_1.getScrollableContainer)();
33
+ if (!scrollableContainer ||
34
+ !ref.current ||
35
+ ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.clientHeight) <= (scrollableContainer === null || scrollableContainer === void 0 ? void 0 : scrollableContainer.clientHeight)) {
36
+ return;
37
+ }
38
+ scrollableContainer.style.height = `${ref.current.clientHeight}px`;
39
+ return () => {
40
+ scrollableContainer.style.removeProperty('height');
41
+ };
42
+ }, [ref]);
43
+ };
44
+ exports.useSetContentHeight = useSetContentHeight;
@@ -0,0 +1 @@
1
+ export declare const useExpandableVariant: () => boolean;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useExpandableVariant = void 0;
4
+ const material_1 = require("@mui/material");
5
+ const providers_1 = require("../providers");
6
+ const defaultExpandableWidth = 852;
7
+ const useExpandableVariant = () => {
8
+ const { variant } = (0, providers_1.useWidgetConfig)();
9
+ const expandableAllowed = (0, material_1.useMediaQuery)((theme) => {
10
+ return theme.breakpoints.up(defaultExpandableWidth);
11
+ });
12
+ return variant === 'expandable' && expandableAllowed;
13
+ };
14
+ exports.useExpandableVariant = useExpandableVariant;
@@ -9,7 +9,8 @@ interface GasSufficiency {
9
9
  chain?: EVMChain;
10
10
  }
11
11
  export declare const useGasSufficiency: (route?: Route) => {
12
- insufficientGas: GasSufficiency[] | undefined;
13
- insufficientFunds: boolean;
12
+ insufficientGas: GasSufficiency[] | null | undefined;
13
+ insufficientFunds: boolean | null | undefined;
14
+ isLoading: boolean;
14
15
  };
15
16
  export {};
@@ -10,23 +10,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.useGasSufficiency = void 0;
13
+ const react_query_1 = require("@tanstack/react-query");
13
14
  const big_js_1 = require("big.js");
14
- const react_1 = require("react");
15
15
  const _1 = require(".");
16
16
  const providers_1 = require("../providers");
17
+ const stores_1 = require("../stores");
17
18
  const useTokenBalance_1 = require("./useTokenBalance");
19
+ const refetchInterval = 30000;
18
20
  const useGasSufficiency = (route) => {
19
21
  const { account } = (0, providers_1.useWallet)();
20
22
  const { getChainById } = (0, _1.useChains)();
21
23
  const { token: fromToken, getTokenBalancesWithRetry } = (0, useTokenBalance_1.useTokenBalance)(route === null || route === void 0 ? void 0 : route.fromToken);
22
- const [insufficientGas, setInsufficientGas] = (0, react_1.useState)();
23
- const checkInsufficientGas = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
24
+ const { data: insufficientGas, isInitialLoading: insufficientGasLoading } = (0, react_query_1.useQuery)(['gas-sufficiency-check', account.address, route === null || route === void 0 ? void 0 : route.id], () => __awaiter(void 0, void 0, void 0, function* () {
24
25
  var _a, _b;
25
26
  if (!account.address || !route) {
26
- setInsufficientGas(undefined);
27
- return;
27
+ return null;
28
28
  }
29
- const gasCosts = route.steps.reduce((groupedGasCosts, step) => {
29
+ const gasCosts = route.steps
30
+ .filter((step) => !step.execution || step.execution.status !== 'DONE')
31
+ .reduce((groupedGasCosts, step) => {
30
32
  if (step.estimate.gasCosts) {
31
33
  const { token } = step.estimate.gasCosts[0];
32
34
  const gasCostAmount = step.estimate.gasCosts
@@ -40,7 +42,6 @@ const useGasSufficiency = (route) => {
40
42
  gasAmount,
41
43
  tokenAmount: gasAmount,
42
44
  token,
43
- chain: getChainById(token.chainId),
44
45
  };
45
46
  return groupedGasCosts;
46
47
  }
@@ -51,42 +52,65 @@ const useGasSufficiency = (route) => {
51
52
  }
52
53
  const tokenBalances = yield getTokenBalancesWithRetry(account.address, Object.values(gasCosts).map((item) => item.token));
53
54
  if (!(tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.length)) {
54
- setInsufficientGas(undefined);
55
- return;
55
+ return null;
56
56
  }
57
57
  [route.fromChainId, route.toChainId].forEach((chainId) => {
58
58
  var _a, _b, _c, _d, _e, _f;
59
59
  if (gasCosts[chainId]) {
60
60
  const gasTokenBalance = (0, big_js_1.default)((_b = (_a = tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances.find((t) => t.chainId === gasCosts[chainId].token.chainId &&
61
61
  t.address === gasCosts[chainId].token.address)) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0);
62
- const insufficientFromChainGas = gasTokenBalance.lte(0) ||
62
+ const insufficient = gasTokenBalance.lte(0) ||
63
63
  gasTokenBalance.lt((_c = gasCosts[chainId].gasAmount) !== null && _c !== void 0 ? _c : (0, big_js_1.default)(0)) ||
64
64
  gasTokenBalance.lt((_d = gasCosts[chainId].tokenAmount) !== null && _d !== void 0 ? _d : (0, big_js_1.default)(0));
65
- const insufficientFromChainGasAmount = insufficientFromChainGas
65
+ const insufficientAmount = insufficient
66
66
  ? (_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
67
  : undefined;
68
- gasCosts[chainId] = Object.assign(Object.assign({}, gasCosts[chainId]), { insufficient: insufficientFromChainGas, insufficientAmount: insufficientFromChainGasAmount === null || insufficientFromChainGasAmount === void 0 ? void 0 : insufficientFromChainGasAmount.round(5, big_js_1.default.roundUp) });
68
+ gasCosts[chainId] = Object.assign(Object.assign({}, gasCosts[chainId]), { insufficient, insufficientAmount: insufficientAmount === null || insufficientAmount === void 0 ? void 0 : insufficientAmount.round(5, big_js_1.default.roundUp), chain: insufficient ? getChainById(chainId) : undefined });
69
69
  }
70
70
  });
71
71
  const gasCostResult = Object.values(gasCosts).filter((gasCost) => gasCost.insufficient);
72
- setInsufficientGas(gasCostResult);
73
- }), [account.address, getChainById, getTokenBalancesWithRetry, route]);
74
- const insufficientFunds = (0, react_1.useMemo)(() => {
75
- var _a;
76
- if (!account.isActive || !fromToken || !route) {
77
- return false;
72
+ return gasCostResult;
73
+ }), {
74
+ enabled: Boolean(account.address && route),
75
+ refetchIntervalInBackground: true,
76
+ refetchInterval,
77
+ staleTime: refetchInterval,
78
+ cacheTime: refetchInterval,
79
+ });
80
+ const { data: insufficientFunds, isInitialLoading: insufficientFundsLoading, } = (0, react_query_1.useQuery)(['funds-sufficiency-check', account.address, route === null || route === void 0 ? void 0 : route.id], () => __awaiter(void 0, void 0, void 0, function* () {
81
+ var _c, _d, _e, _f;
82
+ if (!account.address || !fromToken || !route || (0, stores_1.isRouteCompleted)(route)) {
83
+ return null;
84
+ }
85
+ let currentTokenBalance = (0, big_js_1.default)((_c = fromToken === null || fromToken === void 0 ? void 0 : fromToken.amount) !== null && _c !== void 0 ? _c : 0);
86
+ const currentAction = (_d = route.steps.filter((step) => !step.execution || step.execution.status !== 'DONE')[0]) === null || _d === void 0 ? void 0 : _d.action;
87
+ if (fromToken.chainId === currentAction.fromToken.chainId &&
88
+ fromToken.address === currentAction.fromToken.address &&
89
+ currentTokenBalance.gt(0)) {
90
+ const insufficientFunds = (0, big_js_1.default)(route.fromAmount)
91
+ .div(Math.pow(10, route.fromToken.decimals))
92
+ .gt(currentTokenBalance);
93
+ return insufficientFunds;
78
94
  }
79
- const balance = (0, big_js_1.default)((_a = fromToken === null || fromToken === void 0 ? void 0 : fromToken.amount) !== null && _a !== void 0 ? _a : 0);
80
- return (0, big_js_1.default)(route.fromAmount)
81
- .div(Math.pow(10, route.fromToken.decimals))
82
- .gt(balance);
83
- }, [account.isActive, fromToken, route]);
84
- (0, react_1.useEffect)(() => {
85
- checkInsufficientGas();
86
- }, [checkInsufficientGas]);
95
+ const tokenBalances = yield getTokenBalancesWithRetry(account.address, [
96
+ currentAction.fromToken,
97
+ ]);
98
+ currentTokenBalance = (0, big_js_1.default)((_f = (_e = tokenBalances === null || tokenBalances === void 0 ? void 0 : tokenBalances[0]) === null || _e === void 0 ? void 0 : _e.amount) !== null && _f !== void 0 ? _f : 0);
99
+ const insufficientFunds = (0, big_js_1.default)(currentAction.fromAmount)
100
+ .div(Math.pow(10, currentAction.fromToken.decimals))
101
+ .gt(currentTokenBalance);
102
+ return insufficientFunds;
103
+ }), {
104
+ enabled: Boolean(account.address && route && fromToken),
105
+ refetchIntervalInBackground: true,
106
+ refetchInterval,
107
+ staleTime: refetchInterval,
108
+ cacheTime: refetchInterval,
109
+ });
87
110
  return {
88
111
  insufficientGas,
89
112
  insufficientFunds,
113
+ isLoading: insufficientGasLoading || insufficientFundsLoading,
90
114
  };
91
115
  };
92
116
  exports.useGasSufficiency = useGasSufficiency;
@@ -77,16 +77,18 @@ const useSwapRoutes = () => {
77
77
  catch (_d) {
78
78
  toWalletAddress = (0, address_1.isAddress)(toAddress) ? toAddress : fromAddress;
79
79
  }
80
+ const fromAmount = (0, big_js_1.default)(Number(fromTokenAmount) * Math.pow(10, ((_c = token === null || token === void 0 ? void 0 : token.decimals) !== null && _c !== void 0 ? _c : 0))).toString();
81
+ const formattedSlippage = parseFloat(slippage) / 100;
80
82
  return lifi.getRoutes({
81
83
  fromChainId,
82
- fromAmount: (0, big_js_1.default)(Number(fromTokenAmount) * Math.pow(10, ((_c = token === null || token === void 0 ? void 0 : token.decimals) !== null && _c !== void 0 ? _c : 0))).toString(),
84
+ fromAmount,
83
85
  fromTokenAddress,
84
86
  toChainId,
85
87
  toTokenAddress,
86
88
  fromAddress,
87
89
  toAddress: toWalletAddress,
88
90
  options: {
89
- slippage: slippage / 100,
91
+ slippage: formattedSlippage,
90
92
  bridges: {
91
93
  allow: enabledBridges,
92
94
  },
@@ -24,12 +24,12 @@ const useTokenBalance = (token, accountAddress) => {
24
24
  try {
25
25
  const tokenBalances = yield lifi.getTokenBalances(accountAddress, tokens);
26
26
  if (!tokenBalances.every((token) => token.blockNumber)) {
27
- if (depth > 5) {
27
+ if (depth > 10) {
28
28
  console.warn('Token balance backoff depth exceeded.');
29
29
  return undefined;
30
30
  }
31
31
  yield new Promise((resolve) => {
32
- setTimeout(resolve, depth * 100);
32
+ setTimeout(resolve, Math.pow(1.5, depth) * 100);
33
33
  });
34
34
  return getTokenBalancesWithRetry(accountAddress, tokens, depth + 1);
35
35
  }