@lifi/widget 3.0.2 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/_esm/components/Card/CardIconButton.js +1 -0
- package/_esm/components/Card/CardIconButton.js.map +1 -1
- package/_esm/components/Card/CardLabel.d.ts +1 -1
- package/_esm/components/Card/CardLabel.js +8 -12
- package/_esm/components/Card/CardLabel.js.map +1 -1
- package/_esm/components/ChainSelect/ChainSelect.js +1 -1
- package/_esm/components/ChainSelect/ChainSelect.js.map +1 -1
- package/_esm/components/FeeBreakdownTooltip.d.ts +12 -0
- package/_esm/components/FeeBreakdownTooltip.js +13 -0
- package/_esm/components/FeeBreakdownTooltip.js.map +1 -0
- package/_esm/components/GasMessage/GasRefuelMessage.js +1 -1
- package/_esm/components/GasMessage/GasRefuelMessage.js.map +1 -1
- package/_esm/components/Header/CloseDrawerButton.js +1 -1
- package/_esm/components/Header/CloseDrawerButton.js.map +1 -1
- package/_esm/components/Header/SettingsButton.js +1 -1
- package/_esm/components/Header/SettingsButton.js.map +1 -1
- package/_esm/components/Header/TransactionHistoryButton.js +1 -1
- package/_esm/components/Header/TransactionHistoryButton.js.map +1 -1
- package/_esm/components/IconTypography.d.ts +3 -0
- package/_esm/components/IconTypography.js +8 -0
- package/_esm/components/IconTypography.js.map +1 -0
- package/_esm/components/PoweredBy/PoweredBy.js +1 -1
- package/_esm/components/PoweredBy/PoweredBy.js.map +1 -1
- package/_esm/components/ProgressToNextUpdate.js +1 -1
- package/_esm/components/ProgressToNextUpdate.js.map +1 -1
- package/_esm/components/RouteCard/RouteCard.js +7 -16
- package/_esm/components/RouteCard/RouteCard.js.map +1 -1
- package/_esm/components/RouteCard/RouteCard.style.d.ts +0 -3
- package/_esm/components/RouteCard/RouteCard.style.js +1 -7
- package/_esm/components/RouteCard/RouteCard.style.js.map +1 -1
- package/_esm/components/RouteCard/RouteCardEssentials.js +13 -14
- package/_esm/components/RouteCard/RouteCardEssentials.js.map +1 -1
- package/_esm/components/RouteCard/RouteCardEssentialsExpanded.js +4 -20
- package/_esm/components/RouteCard/RouteCardEssentialsExpanded.js.map +1 -1
- package/_esm/components/RouteCard/types.d.ts +1 -6
- package/_esm/components/Routes/RoutesExpanded.js +2 -4
- package/_esm/components/Routes/RoutesExpanded.js.map +1 -1
- package/_esm/components/SendToWallet/SendToWalletExpandButton.js +1 -1
- package/_esm/components/SendToWallet/SendToWalletExpandButton.js.map +1 -1
- package/_esm/components/Step/Step.d.ts +1 -0
- package/_esm/components/Step/Step.js +2 -2
- package/_esm/components/Step/Step.js.map +1 -1
- package/_esm/components/Step/StepList.js +16 -7
- package/_esm/components/Step/StepList.js.map +1 -1
- package/_esm/components/Step/StepTimer.js +3 -3
- package/_esm/components/Step/StepTimer.js.map +1 -1
- package/_esm/components/StepActions/StepActions.js +5 -4
- package/_esm/components/StepActions/StepActions.js.map +1 -1
- package/_esm/components/StepActions/StepActions.style.js +4 -4
- package/_esm/components/StepActions/StepActions.style.js.map +1 -1
- package/_esm/components/Token/Token.d.ts +2 -0
- package/_esm/components/Token/Token.js +22 -8
- package/_esm/components/Token/Token.js.map +1 -1
- package/_esm/components/Token/Token.style.js +1 -0
- package/_esm/components/Token/Token.style.js.map +1 -1
- package/_esm/components/TokenRate.d.ts +7 -0
- package/_esm/components/TokenRate.js +41 -0
- package/_esm/components/TokenRate.js.map +1 -0
- package/_esm/components/TransactionDetails.d.ts +7 -0
- package/_esm/components/TransactionDetails.js +46 -0
- package/_esm/components/TransactionDetails.js.map +1 -0
- package/_esm/config/version.d.ts +1 -1
- package/_esm/config/version.js +1 -1
- package/_esm/hooks/timer/useInterval.d.ts +1 -0
- package/_esm/hooks/timer/useInterval.js +18 -0
- package/_esm/hooks/timer/useInterval.js.map +1 -0
- package/_esm/hooks/timer/useTimer.d.ts +18 -0
- package/_esm/hooks/timer/useTimer.js +61 -0
- package/_esm/hooks/timer/useTimer.js.map +1 -0
- package/_esm/hooks/timer/utils.d.ts +11 -0
- package/_esm/hooks/timer/utils.js +46 -0
- package/_esm/hooks/timer/utils.js.map +1 -0
- package/_esm/hooks/useAccount.js +4 -5
- package/_esm/hooks/useAccount.js.map +1 -1
- package/_esm/hooks/useAvailableChains.js +1 -0
- package/_esm/hooks/useAvailableChains.js.map +1 -1
- package/_esm/hooks/useGasRecommendation.js +1 -0
- package/_esm/hooks/useGasRecommendation.js.map +1 -1
- package/_esm/hooks/useProcessMessage.js +8 -0
- package/_esm/hooks/useProcessMessage.js.map +1 -1
- package/_esm/hooks/useRoutes.d.ts +4 -2
- package/_esm/hooks/useRoutes.js +17 -10
- package/_esm/hooks/useRoutes.js.map +1 -1
- package/_esm/hooks/useTokens.js +1 -0
- package/_esm/hooks/useTokens.js.map +1 -1
- package/_esm/hooks/useTools.js +1 -0
- package/_esm/hooks/useTools.js.map +1 -1
- package/_esm/hooks/useTransactionDetails.d.ts +1 -1
- package/_esm/hooks/useTransactionDetails.js +1 -1
- package/_esm/hooks/useTransactionDetails.js.map +1 -1
- package/_esm/hooks/useTransactionHistory.js.map +1 -1
- package/_esm/i18n/en.json +19 -21
- package/_esm/i18n/index.js +15 -15
- package/_esm/i18n/index.js.map +1 -1
- package/_esm/index.d.ts +2 -1
- package/_esm/index.js +1 -4
- package/_esm/index.js.map +1 -1
- package/_esm/pages/MainPage/ReviewButton.js +2 -4
- package/_esm/pages/MainPage/ReviewButton.js.map +1 -1
- package/_esm/pages/RoutesPage/RoutesPage.js +2 -4
- package/_esm/pages/RoutesPage/RoutesPage.js.map +1 -1
- package/_esm/pages/SelectEnabledToolsPage.js +1 -1
- package/_esm/pages/SelectEnabledToolsPage.js.map +1 -1
- package/_esm/pages/SendToWallet/SendToWalletPage.js +1 -1
- package/_esm/pages/SendToWallet/SendToWalletPage.js.map +1 -1
- package/_esm/pages/SettingsPage/ThemeSettings.js +1 -1
- package/_esm/pages/SettingsPage/ThemeSettings.js.map +1 -1
- package/_esm/pages/TransactionDetailsPage/TransactionDetailsPage.js +5 -7
- package/_esm/pages/TransactionDetailsPage/TransactionDetailsPage.js.map +1 -1
- package/_esm/pages/TransactionHistoryPage/TransactionHistoryItem.js +2 -2
- package/_esm/pages/TransactionHistoryPage/TransactionHistoryItem.js.map +1 -1
- package/_esm/pages/TransactionPage/ExchangeRateBottomSheet.js +2 -2
- package/_esm/pages/TransactionPage/ExchangeRateBottomSheet.js.map +1 -1
- package/_esm/pages/TransactionPage/RouteTracker.d.ts +7 -0
- package/_esm/pages/TransactionPage/RouteTracker.js +39 -0
- package/_esm/pages/TransactionPage/RouteTracker.js.map +1 -0
- package/_esm/pages/TransactionPage/StartTransactionButton.d.ts +0 -1
- package/_esm/pages/TransactionPage/StartTransactionButton.js +0 -9
- package/_esm/pages/TransactionPage/StartTransactionButton.js.map +1 -1
- package/_esm/pages/TransactionPage/TransactionPage.js +10 -21
- package/_esm/pages/TransactionPage/TransactionPage.js.map +1 -1
- package/_esm/pages/TransactionPage/types.d.ts +0 -1
- package/_esm/providers/I18nProvider/I18nProvider.js +2 -0
- package/_esm/providers/I18nProvider/I18nProvider.js.map +1 -1
- package/_esm/providers/I18nProvider/currencyExtendedFormatter.d.ts +1 -0
- package/_esm/providers/I18nProvider/currencyExtendedFormatter.js +13 -0
- package/_esm/providers/I18nProvider/currencyExtendedFormatter.js.map +1 -0
- package/_esm/providers/WalletProvider/EVMBaseProvider.js +18 -12
- package/_esm/providers/WalletProvider/EVMBaseProvider.js.map +1 -1
- package/_esm/stores/routes/createRouteExecutionStore.js +2 -2
- package/_esm/stores/routes/createRouteExecutionStore.js.map +1 -1
- package/_esm/stores/routes/types.d.ts +1 -1
- package/_esm/stores/routes/useSetExecutableRoute.d.ts +1 -1
- package/_esm/themes/createTheme.js +6 -0
- package/_esm/themes/createTheme.js.map +1 -1
- package/_esm/types/widget.d.ts +1 -2
- package/_esm/utils/converters.js +5 -13
- package/_esm/utils/converters.js.map +1 -1
- package/_esm/utils/fees.d.ts +3 -3
- package/_esm/utils/fees.js +22 -14
- package/_esm/utils/fees.js.map +1 -1
- package/_esm/utils/format.d.ts +13 -4
- package/_esm/utils/format.js +51 -13
- package/_esm/utils/format.js.map +1 -1
- package/components/Card/CardIconButton.tsx +1 -0
- package/components/Card/CardLabel.tsx +13 -29
- package/components/ChainSelect/ChainSelect.tsx +1 -9
- package/components/FeeBreakdownTooltip.tsx +66 -0
- package/components/GasMessage/GasRefuelMessage.tsx +1 -1
- package/components/Header/CloseDrawerButton.tsx +1 -1
- package/components/Header/SettingsButton.tsx +1 -1
- package/components/Header/TransactionHistoryButton.tsx +1 -1
- package/components/IconTypography.ts +9 -0
- package/components/PoweredBy/PoweredBy.tsx +1 -1
- package/components/ProgressToNextUpdate.tsx +0 -3
- package/components/RouteCard/RouteCard.style.ts +1 -9
- package/components/RouteCard/RouteCard.tsx +15 -71
- package/components/RouteCard/RouteCardEssentials.tsx +52 -81
- package/components/RouteCard/RouteCardEssentialsExpanded.tsx +17 -107
- package/components/RouteCard/types.ts +1 -7
- package/components/Routes/RoutesExpanded.tsx +3 -4
- package/components/SendToWallet/SendToWalletExpandButton.tsx +1 -6
- package/components/Step/Step.tsx +11 -2
- package/components/Step/StepList.tsx +19 -10
- package/components/Step/StepTimer.tsx +9 -6
- package/components/StepActions/StepActions.style.tsx +4 -4
- package/components/StepActions/StepActions.tsx +11 -14
- package/components/Token/Token.style.tsx +1 -0
- package/components/Token/Token.tsx +49 -9
- package/components/TokenRate.tsx +79 -0
- package/components/TransactionDetails.tsx +182 -0
- package/config/version.ts +1 -1
- package/hooks/timer/useInterval.ts +21 -0
- package/hooks/timer/useTimer.ts +91 -0
- package/hooks/timer/utils.ts +54 -0
- package/hooks/useAccount.ts +8 -5
- package/hooks/useAvailableChains.ts +2 -1
- package/hooks/useGasRecommendation.ts +1 -0
- package/hooks/useProcessMessage.ts +8 -0
- package/hooks/useRoutes.ts +23 -13
- package/hooks/useTokens.ts +1 -0
- package/hooks/useTools.ts +2 -1
- package/hooks/useTransactionDetails.ts +3 -3
- package/hooks/useTransactionHistory.ts +1 -1
- package/i18n/en.json +19 -21
- package/i18n/index.ts +15 -15
- package/index.ts +2 -5
- package/package.json +18 -19
- package/pages/MainPage/ReviewButton.tsx +2 -4
- package/pages/RoutesPage/RoutesPage.tsx +3 -4
- package/pages/SelectEnabledToolsPage.tsx +1 -1
- package/pages/SendToWallet/SendToWalletPage.tsx +1 -1
- package/pages/SettingsPage/ThemeSettings.tsx +1 -1
- package/pages/TransactionDetailsPage/TransactionDetailsPage.tsx +9 -20
- package/pages/TransactionHistoryPage/TransactionHistoryItem.tsx +3 -5
- package/pages/TransactionPage/ExchangeRateBottomSheet.tsx +0 -2
- package/pages/TransactionPage/RouteTracker.tsx +68 -0
- package/pages/TransactionPage/StartTransactionButton.tsx +0 -24
- package/pages/TransactionPage/TransactionPage.tsx +21 -48
- package/pages/TransactionPage/types.ts +0 -1
- package/providers/I18nProvider/I18nProvider.tsx +6 -0
- package/providers/I18nProvider/currencyExtendedFormatter.ts +15 -0
- package/providers/WalletProvider/EVMBaseProvider.tsx +13 -7
- package/stores/routes/createRouteExecutionStore.ts +2 -2
- package/stores/routes/types.ts +1 -1
- package/themes/createTheme.ts +6 -0
- package/types/widget.ts +1 -2
- package/utils/converters.ts +5 -13
- package/utils/fees.ts +30 -25
- package/utils/format.ts +67 -20
- package/_esm/components/Insurance/Insurance.d.ts +0 -2
- package/_esm/components/Insurance/Insurance.js +0 -8
- package/_esm/components/Insurance/Insurance.js.map +0 -1
- package/_esm/components/Insurance/InsuranceCard.d.ts +0 -2
- package/_esm/components/Insurance/InsuranceCard.js +0 -36
- package/_esm/components/Insurance/InsuranceCard.js.map +0 -1
- package/_esm/components/Insurance/InsuranceCollapsed.d.ts +0 -2
- package/_esm/components/Insurance/InsuranceCollapsed.js +0 -29
- package/_esm/components/Insurance/InsuranceCollapsed.js.map +0 -1
- package/_esm/components/Insurance/types.d.ts +0 -19
- package/_esm/components/Insurance/types.js +0 -2
- package/_esm/components/Insurance/types.js.map +0 -1
- package/_esm/components/StepActions/StepFeeBreakdown.d.ts +0 -4
- package/_esm/components/StepActions/StepFeeBreakdown.js +0 -42
- package/_esm/components/StepActions/StepFeeBreakdown.js.map +0 -1
- package/_esm/icons/InsuraceLogo.d.ts +0 -2
- package/_esm/icons/InsuraceLogo.js +0 -8
- package/_esm/icons/InsuraceLogo.js.map +0 -1
- package/components/Insurance/Insurance.tsx +0 -22
- package/components/Insurance/InsuranceCard.tsx +0 -119
- package/components/Insurance/InsuranceCollapsed.tsx +0 -59
- package/components/Insurance/types.ts +0 -24
- package/components/StepActions/StepFeeBreakdown.tsx +0 -108
- package/icons/InsuraceLogo.tsx +0 -46
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { RouteExtended } from '@lifi/sdk';
|
|
2
|
+
import {
|
|
3
|
+
ExpandLess,
|
|
4
|
+
ExpandMore,
|
|
5
|
+
LocalGasStationRounded,
|
|
6
|
+
} from '@mui/icons-material';
|
|
7
|
+
import type { CardProps } from '@mui/material';
|
|
8
|
+
import { Box, Collapse, Tooltip, Typography } from '@mui/material';
|
|
9
|
+
import { useState } from 'react';
|
|
10
|
+
import { useTranslation } from 'react-i18next';
|
|
11
|
+
import { isRouteDone } from '../stores/routes/utils.js';
|
|
12
|
+
import { getFeeCostsBreakdown, getGasCostsBreakdown } from '../utils/fees.js';
|
|
13
|
+
import {
|
|
14
|
+
convertToSubscriptFormat,
|
|
15
|
+
formatTokenAmount,
|
|
16
|
+
formatTokenPrice,
|
|
17
|
+
} from '../utils/format.js';
|
|
18
|
+
import { Card } from './Card/Card.js';
|
|
19
|
+
import { CardIconButton } from './Card/CardIconButton.js';
|
|
20
|
+
import { FeeBreakdownTooltip } from './FeeBreakdownTooltip.js';
|
|
21
|
+
import { IconTypography } from './IconTypography.js';
|
|
22
|
+
import { TokenRate } from './TokenRate.js';
|
|
23
|
+
|
|
24
|
+
interface TransactionDetailsProps extends CardProps {
|
|
25
|
+
route: RouteExtended;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const TransactionDetails: React.FC<TransactionDetailsProps> = ({
|
|
29
|
+
route,
|
|
30
|
+
...props
|
|
31
|
+
}) => {
|
|
32
|
+
const { t } = useTranslation();
|
|
33
|
+
const [cardExpanded, setCardExpanded] = useState(false);
|
|
34
|
+
|
|
35
|
+
const toggleCard = () => {
|
|
36
|
+
setCardExpanded((cardExpanded) => !cardExpanded);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const gasCosts = getGasCostsBreakdown(route);
|
|
40
|
+
const feeCosts = getFeeCostsBreakdown(route, false);
|
|
41
|
+
const gasCostUSD = gasCosts.reduce(
|
|
42
|
+
(sum, gasCost) => sum + gasCost.amountUSD,
|
|
43
|
+
0,
|
|
44
|
+
);
|
|
45
|
+
const feeCostUSD = feeCosts.reduce(
|
|
46
|
+
(sum, feeCost) => sum + feeCost.amountUSD,
|
|
47
|
+
0,
|
|
48
|
+
);
|
|
49
|
+
const fees = gasCostUSD + feeCostUSD;
|
|
50
|
+
|
|
51
|
+
const fromTokenAmount = formatTokenAmount(
|
|
52
|
+
BigInt(route.fromAmount),
|
|
53
|
+
route.fromToken.decimals,
|
|
54
|
+
);
|
|
55
|
+
const fromTokenPrice = formatTokenPrice(
|
|
56
|
+
fromTokenAmount,
|
|
57
|
+
route.fromToken.priceUSD,
|
|
58
|
+
);
|
|
59
|
+
const toTokenAmount = formatTokenAmount(
|
|
60
|
+
BigInt(route.toAmount),
|
|
61
|
+
route.toToken.decimals,
|
|
62
|
+
);
|
|
63
|
+
const toTokenPrice =
|
|
64
|
+
formatTokenPrice(toTokenAmount, route.toToken.priceUSD) || 0.01;
|
|
65
|
+
|
|
66
|
+
const impact = (toTokenPrice / fromTokenPrice - 1) * 100;
|
|
67
|
+
|
|
68
|
+
const priceImpact = convertToSubscriptFormat(impact, {
|
|
69
|
+
notation: 'standard',
|
|
70
|
+
roundingPriority: 'morePrecision',
|
|
71
|
+
maximumSignificantDigits: 2,
|
|
72
|
+
maximumFractionDigits: 2,
|
|
73
|
+
useGrouping: false,
|
|
74
|
+
roundingMode: 'trunc',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<Card selectionColor="secondary" {...props}>
|
|
79
|
+
<Box display="flex" alignItems="center" px={2} py={1.75}>
|
|
80
|
+
<Box display="flex" flex={1} alignItems="center" justifyContent="left">
|
|
81
|
+
<TokenRate route={route} />
|
|
82
|
+
</Box>
|
|
83
|
+
<FeeBreakdownTooltip
|
|
84
|
+
route={route}
|
|
85
|
+
gasCosts={gasCosts}
|
|
86
|
+
feeCosts={feeCosts}
|
|
87
|
+
>
|
|
88
|
+
<Box
|
|
89
|
+
display="flex"
|
|
90
|
+
alignItems="center"
|
|
91
|
+
onClick={toggleCard}
|
|
92
|
+
role="button"
|
|
93
|
+
sx={{ cursor: 'pointer' }}
|
|
94
|
+
px={1}
|
|
95
|
+
>
|
|
96
|
+
<IconTypography mr={0.5} fontSize={16}>
|
|
97
|
+
<LocalGasStationRounded fontSize="inherit" />
|
|
98
|
+
</IconTypography>
|
|
99
|
+
<Typography
|
|
100
|
+
fontSize={14}
|
|
101
|
+
color="text.primary"
|
|
102
|
+
fontWeight="600"
|
|
103
|
+
lineHeight={1.429}
|
|
104
|
+
>
|
|
105
|
+
{t(`format.currency`, { value: fees })}
|
|
106
|
+
</Typography>
|
|
107
|
+
</Box>
|
|
108
|
+
</FeeBreakdownTooltip>
|
|
109
|
+
<CardIconButton onClick={toggleCard} size="small">
|
|
110
|
+
{cardExpanded ? (
|
|
111
|
+
<ExpandLess fontSize="inherit" />
|
|
112
|
+
) : (
|
|
113
|
+
<ExpandMore fontSize="inherit" />
|
|
114
|
+
)}
|
|
115
|
+
</CardIconButton>
|
|
116
|
+
</Box>
|
|
117
|
+
<Collapse timeout={225} in={cardExpanded} mountOnEnter>
|
|
118
|
+
<Box px={2} pb={2}>
|
|
119
|
+
<Box display="flex" justifyContent="space-between" mb={0.5}>
|
|
120
|
+
<Typography variant="body2">{t('main.fees.network')}</Typography>
|
|
121
|
+
<FeeBreakdownTooltip route={route} feeCosts={[]}>
|
|
122
|
+
<Typography variant="body2">
|
|
123
|
+
{t(`format.currency`, {
|
|
124
|
+
value: gasCostUSD,
|
|
125
|
+
})}
|
|
126
|
+
</Typography>
|
|
127
|
+
</FeeBreakdownTooltip>
|
|
128
|
+
</Box>
|
|
129
|
+
{feeCosts.length ? (
|
|
130
|
+
<Box display="flex" justifyContent="space-between" mb={0.5}>
|
|
131
|
+
<Typography variant="body2">{t('main.fees.provider')}</Typography>
|
|
132
|
+
<FeeBreakdownTooltip
|
|
133
|
+
route={route}
|
|
134
|
+
gasCosts={[]}
|
|
135
|
+
feeCosts={feeCosts}
|
|
136
|
+
>
|
|
137
|
+
<Typography variant="body2">
|
|
138
|
+
{t(`format.currency`, {
|
|
139
|
+
value: feeCostUSD,
|
|
140
|
+
})}
|
|
141
|
+
</Typography>
|
|
142
|
+
</FeeBreakdownTooltip>
|
|
143
|
+
</Box>
|
|
144
|
+
) : null}
|
|
145
|
+
<Box display="flex" justifyContent="space-between" mb={0.5}>
|
|
146
|
+
<Typography variant="body2">{t('main.priceImpact')}</Typography>
|
|
147
|
+
<Tooltip title={t('tooltip.priceImpact')} sx={{ cursor: 'help' }}>
|
|
148
|
+
<Typography variant="body2">{priceImpact}%</Typography>
|
|
149
|
+
</Tooltip>
|
|
150
|
+
</Box>
|
|
151
|
+
{!isRouteDone(route) ? (
|
|
152
|
+
<>
|
|
153
|
+
<Box display="flex" justifyContent="space-between" mb={0.5}>
|
|
154
|
+
<Typography variant="body2">{t('main.maxSlippage')}</Typography>
|
|
155
|
+
<Typography variant="body2">
|
|
156
|
+
{route.steps[0].action.slippage * 100}%
|
|
157
|
+
</Typography>
|
|
158
|
+
</Box>
|
|
159
|
+
<Box display="flex" justifyContent="space-between">
|
|
160
|
+
<Typography variant="body2">{t('main.minReceived')}</Typography>
|
|
161
|
+
<Tooltip
|
|
162
|
+
title={t('tooltip.minReceived')}
|
|
163
|
+
sx={{ cursor: 'help' }}
|
|
164
|
+
>
|
|
165
|
+
<Typography variant="body2">
|
|
166
|
+
{t('format.number', {
|
|
167
|
+
value: formatTokenAmount(
|
|
168
|
+
BigInt(route.toAmountMin),
|
|
169
|
+
route.toToken.decimals,
|
|
170
|
+
),
|
|
171
|
+
})}{' '}
|
|
172
|
+
{route.toToken.symbol}
|
|
173
|
+
</Typography>
|
|
174
|
+
</Tooltip>
|
|
175
|
+
</Box>
|
|
176
|
+
</>
|
|
177
|
+
) : null}
|
|
178
|
+
</Box>
|
|
179
|
+
</Collapse>
|
|
180
|
+
</Card>
|
|
181
|
+
);
|
|
182
|
+
};
|
package/config/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget';
|
|
2
|
-
export const version = '3.
|
|
2
|
+
export const version = '3.1.1';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useInterval(callback: Function, delay: number) {
|
|
4
|
+
const callbacRef = useRef<Function>();
|
|
5
|
+
|
|
6
|
+
// update callback function with current render callback that has access to latest props and state
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
callbacRef.current = callback;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!delay) {
|
|
13
|
+
return () => {};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const interval = setInterval(() => {
|
|
17
|
+
callbacRef.current && callbacRef.current();
|
|
18
|
+
}, delay);
|
|
19
|
+
return () => clearInterval(interval);
|
|
20
|
+
}, [delay]);
|
|
21
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
import { useInterval } from './useInterval.js';
|
|
3
|
+
import {
|
|
4
|
+
getDelayFromExpiryTimestamp,
|
|
5
|
+
getSecondsFromExpiry,
|
|
6
|
+
getTimeFromSeconds,
|
|
7
|
+
validateOnExpire,
|
|
8
|
+
} from './utils.js';
|
|
9
|
+
|
|
10
|
+
const DEFAULT_DELAY = 1000;
|
|
11
|
+
|
|
12
|
+
interface UseTimerProps {
|
|
13
|
+
expiryTimestamp: Date;
|
|
14
|
+
onExpire: Function;
|
|
15
|
+
autoStart?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// This implementation was taken from the common js project - https://www.npmjs.com/package/react-timer-hook
|
|
19
|
+
// modified to work in the Widget codebase with Typescript
|
|
20
|
+
export function useTimer({
|
|
21
|
+
expiryTimestamp: expiry,
|
|
22
|
+
onExpire,
|
|
23
|
+
autoStart = true,
|
|
24
|
+
}: UseTimerProps) {
|
|
25
|
+
const [expiryTimestamp, setExpiryTimestamp] = useState(expiry);
|
|
26
|
+
const [seconds, setSeconds] = useState(getSecondsFromExpiry(expiryTimestamp));
|
|
27
|
+
const [isRunning, setIsRunning] = useState(autoStart);
|
|
28
|
+
const [didStart, setDidStart] = useState(autoStart);
|
|
29
|
+
const [delay, setDelay] = useState(
|
|
30
|
+
getDelayFromExpiryTimestamp(expiryTimestamp, DEFAULT_DELAY),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const handleExpire = useCallback(() => {
|
|
34
|
+
validateOnExpire(onExpire) && onExpire();
|
|
35
|
+
setIsRunning(false);
|
|
36
|
+
setDelay(0);
|
|
37
|
+
}, [onExpire]);
|
|
38
|
+
|
|
39
|
+
const pause = useCallback(() => {
|
|
40
|
+
setIsRunning(false);
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
const restart = useCallback(
|
|
44
|
+
(newExpiryTimestamp: Date, newAutoStart = true) => {
|
|
45
|
+
setDelay(getDelayFromExpiryTimestamp(newExpiryTimestamp, DEFAULT_DELAY));
|
|
46
|
+
setDidStart(newAutoStart);
|
|
47
|
+
setIsRunning(newAutoStart);
|
|
48
|
+
setExpiryTimestamp(newExpiryTimestamp);
|
|
49
|
+
setSeconds(getSecondsFromExpiry(newExpiryTimestamp));
|
|
50
|
+
},
|
|
51
|
+
[],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const resume = useCallback(() => {
|
|
55
|
+
const time = new Date();
|
|
56
|
+
time.setMilliseconds(time.getMilliseconds() + seconds * 1000);
|
|
57
|
+
restart(time);
|
|
58
|
+
}, [seconds, restart]);
|
|
59
|
+
|
|
60
|
+
const start = useCallback(() => {
|
|
61
|
+
if (didStart) {
|
|
62
|
+
setSeconds(getSecondsFromExpiry(expiryTimestamp));
|
|
63
|
+
setIsRunning(true);
|
|
64
|
+
} else {
|
|
65
|
+
resume();
|
|
66
|
+
}
|
|
67
|
+
}, [expiryTimestamp, didStart, resume]);
|
|
68
|
+
|
|
69
|
+
useInterval(
|
|
70
|
+
() => {
|
|
71
|
+
if (delay !== DEFAULT_DELAY) {
|
|
72
|
+
setDelay(DEFAULT_DELAY);
|
|
73
|
+
}
|
|
74
|
+
const secondsValue = getSecondsFromExpiry(expiryTimestamp);
|
|
75
|
+
setSeconds(secondsValue);
|
|
76
|
+
if (secondsValue <= 0) {
|
|
77
|
+
handleExpire();
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
isRunning ? delay : 0,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
...getTimeFromSeconds(seconds),
|
|
85
|
+
start,
|
|
86
|
+
pause,
|
|
87
|
+
resume,
|
|
88
|
+
restart,
|
|
89
|
+
isRunning,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export function getTimeFromSeconds(secs: number) {
|
|
2
|
+
const totalSeconds = Math.ceil(secs);
|
|
3
|
+
const days = Math.floor(totalSeconds / (60 * 60 * 24));
|
|
4
|
+
const hours = Math.floor((totalSeconds % (60 * 60 * 24)) / (60 * 60));
|
|
5
|
+
const minutes = Math.floor((totalSeconds % (60 * 60)) / 60);
|
|
6
|
+
const seconds = Math.floor(totalSeconds % 60);
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
totalSeconds,
|
|
10
|
+
seconds,
|
|
11
|
+
minutes,
|
|
12
|
+
hours,
|
|
13
|
+
days,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getSecondsFromExpiry(expiry: Date, shouldRound?: boolean) {
|
|
18
|
+
const now = new Date().getTime();
|
|
19
|
+
const milliSecondsDistance = expiry.getTime() - now;
|
|
20
|
+
if (milliSecondsDistance > 0) {
|
|
21
|
+
const val = milliSecondsDistance / 1000;
|
|
22
|
+
return shouldRound ? Math.round(val) : val;
|
|
23
|
+
}
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function validateExpiryTimestamp(expiryTimestamp: Date) {
|
|
28
|
+
const isValid = new Date(expiryTimestamp).getTime() > 0;
|
|
29
|
+
if (!isValid) {
|
|
30
|
+
console.warn('useTimer Invalid expiryTimestamp settings', expiryTimestamp); // eslint-disable-line
|
|
31
|
+
}
|
|
32
|
+
return isValid;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function validateOnExpire(onExpire: Function) {
|
|
36
|
+
const isValid = onExpire && typeof onExpire === 'function';
|
|
37
|
+
if (onExpire && !isValid) {
|
|
38
|
+
console.warn('useTimer Invalid onExpire settings function', onExpire);
|
|
39
|
+
}
|
|
40
|
+
return isValid;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getDelayFromExpiryTimestamp(
|
|
44
|
+
expiryTimestamp: Date,
|
|
45
|
+
defaultDelay: number,
|
|
46
|
+
) {
|
|
47
|
+
if (!validateExpiryTimestamp(expiryTimestamp)) {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const seconds = getSecondsFromExpiry(expiryTimestamp);
|
|
52
|
+
const extraMilliSeconds = Math.floor((seconds - Math.floor(seconds)) * 1000);
|
|
53
|
+
return extraMilliSeconds > 0 ? extraMilliSeconds : defaultDelay;
|
|
54
|
+
}
|
package/hooks/useAccount.ts
CHANGED
|
@@ -92,13 +92,16 @@ export const useAccount = (args?: UseAccountArgs): AccountResult => {
|
|
|
92
92
|
const evm: Account = { ...account, chainType: ChainType.EVM };
|
|
93
93
|
const accounts = [evm, svm];
|
|
94
94
|
const connectedAccounts = [evm, svm].filter(
|
|
95
|
-
(account) => account.isConnected,
|
|
95
|
+
(account) => account.isConnected && account.address,
|
|
96
96
|
);
|
|
97
97
|
return {
|
|
98
|
-
account:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
account:
|
|
99
|
+
accounts.find(
|
|
100
|
+
(account) =>
|
|
101
|
+
(!hasChainTypeArgs || account.chainType === args?.chainType) &&
|
|
102
|
+
account.isConnected &&
|
|
103
|
+
account.address,
|
|
104
|
+
) ?? defaultAccount,
|
|
102
105
|
// We need to return only connected account list
|
|
103
106
|
accounts: connectedAccounts,
|
|
104
107
|
};
|
|
@@ -173,6 +173,14 @@ export function getProcessMessage(
|
|
|
173
173
|
title = t(`error.title.transactionFailed`);
|
|
174
174
|
message = t(`error.message.transactionFailed`);
|
|
175
175
|
break;
|
|
176
|
+
case LiFiErrorCode.TransactionExpired:
|
|
177
|
+
title = t(`error.title.transactionExpired`);
|
|
178
|
+
message = t(`error.message.transactionExpired`);
|
|
179
|
+
break;
|
|
180
|
+
case LiFiErrorCode.TransactionSimulationFailed:
|
|
181
|
+
title = t(`error.title.transactionSimulationFailed`);
|
|
182
|
+
message = t(`error.message.transactionSimulationFailed`);
|
|
183
|
+
break;
|
|
176
184
|
case LiFiErrorCode.WalletChangedDuringExecution:
|
|
177
185
|
title = t(`error.title.walletMismatch`);
|
|
178
186
|
message = t(`error.message.walletChangedDuringExecution`);
|
package/hooks/useRoutes.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
5
5
|
import { parseUnits } from 'viem';
|
|
6
6
|
import { useWidgetConfig } from '../providers/WidgetProvider/WidgetProvider.js';
|
|
7
7
|
import { useFieldValues } from '../stores/form/useFieldValues.js';
|
|
8
|
+
import { useSetExecutableRoute } from '../stores/routes/useSetExecutableRoute.js';
|
|
8
9
|
import { useSettings } from '../stores/settings/useSettings.js';
|
|
9
10
|
import { defaultSlippage } from '../stores/settings/useSettingsStore.js';
|
|
10
11
|
import { WidgetEvent } from '../types/events.js';
|
|
@@ -20,12 +21,13 @@ import { useWidgetEvents } from './useWidgetEvents.js';
|
|
|
20
21
|
const refetchTime = 60_000;
|
|
21
22
|
|
|
22
23
|
interface RoutesProps {
|
|
23
|
-
|
|
24
|
+
observableRoute?: Route;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
export const useRoutes = ({
|
|
27
|
-
const { subvariant, sdkConfig,
|
|
27
|
+
export const useRoutes = ({ observableRoute }: RoutesProps = {}) => {
|
|
28
|
+
const { subvariant, sdkConfig, contractTool, bridges, exchanges } =
|
|
28
29
|
useWidgetConfig();
|
|
30
|
+
const setExecutableRoute = useSetExecutableRoute();
|
|
29
31
|
const queryClient = useQueryClient();
|
|
30
32
|
const emitter = useWidgetEvents();
|
|
31
33
|
const swapOnly = useSwapOnly();
|
|
@@ -135,8 +137,7 @@ export const useRoutes = ({ insurableRoute }: RoutesProps = {}) => {
|
|
|
135
137
|
sdkConfig?.routeOptions?.allowSwitchChain,
|
|
136
138
|
enabledRefuel && enabledAutoRefuel,
|
|
137
139
|
gasRecommendationFromAmount,
|
|
138
|
-
|
|
139
|
-
insurableRoute?.id,
|
|
140
|
+
observableRoute?.id,
|
|
140
141
|
] as const;
|
|
141
142
|
|
|
142
143
|
const { data, isLoading, isFetching, isFetched, dataUpdatedAt, refetch } =
|
|
@@ -165,8 +166,7 @@ export const useRoutes = ({ insurableRoute }: RoutesProps = {}) => {
|
|
|
165
166
|
allowSwitchChain,
|
|
166
167
|
enabledRefuel,
|
|
167
168
|
gasRecommendationFromAmount,
|
|
168
|
-
|
|
169
|
-
insurableRouteId,
|
|
169
|
+
observableRouteId,
|
|
170
170
|
],
|
|
171
171
|
signal,
|
|
172
172
|
}) => {
|
|
@@ -178,8 +178,8 @@ export const useRoutes = ({ insurableRoute }: RoutesProps = {}) => {
|
|
|
178
178
|
|
|
179
179
|
const allowBridges = swapOnly
|
|
180
180
|
? []
|
|
181
|
-
:
|
|
182
|
-
?
|
|
181
|
+
: observableRoute
|
|
182
|
+
? observableRoute.steps.flatMap((step) =>
|
|
183
183
|
step.includedSteps.reduce((toolKeys, includedStep) => {
|
|
184
184
|
if (includedStep.type === 'cross') {
|
|
185
185
|
toolKeys.push(includedStep.toolDetails.key);
|
|
@@ -188,9 +188,8 @@ export const useRoutes = ({ insurableRoute }: RoutesProps = {}) => {
|
|
|
188
188
|
}, [] as string[]),
|
|
189
189
|
)
|
|
190
190
|
: allowedBridges;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
? insurableRoute.steps.flatMap((step) =>
|
|
191
|
+
const allowExchanges = observableRoute
|
|
192
|
+
? observableRoute.steps.flatMap((step) =>
|
|
194
193
|
step.includedSteps.reduce((toolKeys, includedStep) => {
|
|
195
194
|
if (includedStep.type === 'swap') {
|
|
196
195
|
toolKeys.push(includedStep.toolDetails.key);
|
|
@@ -299,7 +298,6 @@ export const useRoutes = ({ insurableRoute }: RoutesProps = {}) => {
|
|
|
299
298
|
: undefined,
|
|
300
299
|
}
|
|
301
300
|
: undefined,
|
|
302
|
-
insurance: insurance ? Boolean(insurableRoute) : undefined,
|
|
303
301
|
order: routePriority,
|
|
304
302
|
slippage: formattedSlippage,
|
|
305
303
|
},
|
|
@@ -350,6 +348,16 @@ export const useRoutes = ({ insurableRoute }: RoutesProps = {}) => {
|
|
|
350
348
|
},
|
|
351
349
|
});
|
|
352
350
|
|
|
351
|
+
const setReviewableRoute = (route: Route) => {
|
|
352
|
+
const queryDataKey = queryKey.toSpliced(queryKey.length - 1, 1, route.id);
|
|
353
|
+
queryClient.setQueryData(
|
|
354
|
+
queryDataKey,
|
|
355
|
+
{ routes: [route] },
|
|
356
|
+
{ updatedAt: dataUpdatedAt },
|
|
357
|
+
);
|
|
358
|
+
setExecutableRoute(route);
|
|
359
|
+
};
|
|
360
|
+
|
|
353
361
|
return {
|
|
354
362
|
routes: data?.routes,
|
|
355
363
|
isLoading: isEnabled && isLoading,
|
|
@@ -360,5 +368,7 @@ export const useRoutes = ({ insurableRoute }: RoutesProps = {}) => {
|
|
|
360
368
|
refetch,
|
|
361
369
|
fromChain,
|
|
362
370
|
toChain,
|
|
371
|
+
queryKey,
|
|
372
|
+
setReviewableRoute,
|
|
363
373
|
};
|
|
364
374
|
};
|
package/hooks/useTokens.ts
CHANGED
package/hooks/useTools.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '@tanstack/react-query';
|
|
8
8
|
import { useAccount } from './useAccount.js';
|
|
9
9
|
|
|
10
|
-
export const useTransactionDetails = (transactionHash
|
|
10
|
+
export const useTransactionDetails = (transactionHash?: string) => {
|
|
11
11
|
const { account, accounts } = useAccount();
|
|
12
12
|
const queryClient = useQueryClient();
|
|
13
13
|
|
|
@@ -51,8 +51,8 @@ export const useTransactionDetails = (transactionHash: string) => {
|
|
|
51
51
|
return transaction;
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
|
-
refetchInterval:
|
|
55
|
-
enabled:
|
|
54
|
+
refetchInterval: 300_000,
|
|
55
|
+
enabled: account.isConnected && Boolean(transactionHash),
|
|
56
56
|
initialData: () => {
|
|
57
57
|
for (const account of accounts) {
|
|
58
58
|
const transaction = queryClient
|
|
@@ -28,7 +28,7 @@ export const useTransactionHistory = () => {
|
|
|
28
28
|
|
|
29
29
|
return response.transfers;
|
|
30
30
|
}) as QueryFunction<StatusResponse[], (string | undefined)[], never>,
|
|
31
|
-
refetchInterval:
|
|
31
|
+
refetchInterval: 300_000,
|
|
32
32
|
enabled: Boolean(account.address),
|
|
33
33
|
})),
|
|
34
34
|
combine: (results) => {
|