@lifi/widget 3.16.1 → 3.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/esm/components/ActiveTransactions/ActiveTransactionItem.js +2 -2
- package/dist/esm/components/ActiveTransactions/ActiveTransactionItem.js.map +1 -1
- package/dist/esm/components/SelectChainAndToken.js +2 -1
- package/dist/esm/components/SelectChainAndToken.js.map +1 -1
- package/dist/esm/components/Step/Step.js +1 -1
- package/dist/esm/components/Step/Step.js.map +1 -1
- package/dist/esm/components/Timer/RouteTimer.d.ts +4 -0
- package/dist/esm/components/Timer/RouteTimer.js +14 -0
- package/dist/esm/components/Timer/RouteTimer.js.map +1 -0
- package/dist/esm/components/Timer/StepTimer.js +56 -0
- package/dist/esm/components/Timer/StepTimer.js.map +1 -0
- package/dist/esm/components/Timer/TimerContent.d.ts +2 -0
- package/dist/esm/components/Timer/TimerContent.js +18 -0
- package/dist/esm/components/Timer/TimerContent.js.map +1 -0
- package/dist/esm/config/version.d.ts +1 -1
- package/dist/esm/config/version.js +1 -1
- package/dist/esm/hooks/timer/useStopwatch.d.ts +16 -0
- package/dist/esm/hooks/timer/useStopwatch.js +41 -0
- package/dist/esm/hooks/timer/useStopwatch.js.map +1 -0
- package/dist/esm/hooks/timer/utils.d.ts +1 -0
- package/dist/esm/hooks/timer/utils.js +9 -0
- package/dist/esm/hooks/timer/utils.js.map +1 -1
- package/dist/esm/hooks/useListHeight.d.ts +12 -0
- package/dist/esm/{pages/SelectTokenPage/useTokenListHeight.js → hooks/useListHeight.js} +12 -12
- package/dist/esm/hooks/useListHeight.js.map +1 -0
- package/dist/esm/hooks/useRoutes.js +3 -1
- package/dist/esm/hooks/useRoutes.js.map +1 -1
- package/dist/esm/hooks/useSettingMonitor.d.ts +3 -1
- package/dist/esm/hooks/useSettingMonitor.js +6 -2
- package/dist/esm/hooks/useSettingMonitor.js.map +1 -1
- package/dist/esm/i18n/en.json +2 -1
- package/dist/esm/pages/SelectTokenPage/SelectTokenPage.js +3 -3
- package/dist/esm/pages/SelectTokenPage/SelectTokenPage.js.map +1 -1
- package/dist/esm/pages/SettingsPage/SlippageSettings/SlippageSettings.js +24 -17
- package/dist/esm/pages/SettingsPage/SlippageSettings/SlippageSettings.js.map +1 -1
- package/dist/esm/pages/TransactionHistoryPage/TransactionHistoryPage.d.ts +1 -0
- package/dist/esm/pages/TransactionHistoryPage/TransactionHistoryPage.js +18 -10
- package/dist/esm/pages/TransactionHistoryPage/TransactionHistoryPage.js.map +1 -1
- package/dist/esm/stores/settings/useSettingsStore.d.ts +1 -1
- package/dist/esm/stores/settings/useSettingsStore.js +1 -1
- package/dist/esm/stores/settings/useSettingsStore.js.map +1 -1
- package/dist/esm/types/widget.d.ts +3 -2
- package/dist/esm/types/widget.js +1 -0
- package/dist/esm/types/widget.js.map +1 -1
- package/dist/esm/utils/chainType.d.ts +1 -0
- package/dist/esm/utils/chainType.js +2 -0
- package/dist/esm/utils/chainType.js.map +1 -1
- package/package.json +9 -9
- package/src/components/ActiveTransactions/ActiveTransactionItem.tsx +2 -2
- package/src/components/SelectChainAndToken.tsx +2 -1
- package/src/components/Step/Step.tsx +1 -1
- package/src/components/Timer/RouteTimer.tsx +22 -0
- package/src/components/Timer/StepTimer.tsx +84 -0
- package/src/components/Timer/TimerContent.tsx +35 -0
- package/src/config/version.ts +1 -1
- package/src/hooks/timer/useStopwatch.ts +65 -0
- package/src/hooks/timer/utils.ts +10 -0
- package/src/{pages/SelectTokenPage/useTokenListHeight.ts → hooks/useListHeight.ts} +16 -16
- package/src/hooks/useRoutes.ts +3 -1
- package/src/hooks/useSettingMonitor.ts +11 -2
- package/src/i18n/en.json +2 -1
- package/src/pages/SelectTokenPage/SelectTokenPage.tsx +3 -3
- package/src/pages/SettingsPage/SlippageSettings/SlippageSettings.tsx +38 -26
- package/src/pages/TransactionHistoryPage/TransactionHistoryPage.tsx +48 -31
- package/src/stores/settings/useSettingsStore.ts +1 -1
- package/src/types/widget.ts +2 -1
- package/src/utils/chainType.ts +2 -0
- package/dist/esm/components/Step/StepTimer.js +0 -86
- package/dist/esm/components/Step/StepTimer.js.map +0 -1
- package/dist/esm/pages/SelectTokenPage/useTokenListHeight.d.ts +0 -12
- package/dist/esm/pages/SelectTokenPage/useTokenListHeight.js.map +0 -1
- package/src/components/Step/StepTimer.tsx +0 -137
- /package/dist/esm/components/{Step → Timer}/StepTimer.d.ts +0 -0
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import type { LiFiStepExtended } from '@lifi/sdk'
|
|
2
|
-
import { AccessTimeFilled } from '@mui/icons-material'
|
|
3
|
-
import { Box, Tooltip } from '@mui/material'
|
|
4
|
-
import { type FC, type PropsWithChildren, useEffect, useState } from 'react'
|
|
5
|
-
import { useTranslation } from 'react-i18next'
|
|
6
|
-
import { useTimer } from '../../hooks/timer/useTimer.js'
|
|
7
|
-
import { IconTypography } from '../IconTypography.js'
|
|
8
|
-
|
|
9
|
-
const getExecutionProcess = (step: LiFiStepExtended) =>
|
|
10
|
-
step.execution?.process.findLast(
|
|
11
|
-
(process) =>
|
|
12
|
-
process.type === 'SWAP' ||
|
|
13
|
-
process.type === 'CROSS_CHAIN' ||
|
|
14
|
-
process.type === 'RECEIVING_CHAIN'
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
const getExpiryTimestamp = (step: LiFiStepExtended) =>
|
|
18
|
-
new Date(
|
|
19
|
-
(getExecutionProcess(step)?.startedAt ?? Date.now()) +
|
|
20
|
-
step.estimate.executionDuration * 1000
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
export const StepTimer: React.FC<{
|
|
24
|
-
step: LiFiStepExtended
|
|
25
|
-
hideInProgress?: boolean
|
|
26
|
-
}> = ({ step, hideInProgress }) => {
|
|
27
|
-
const { t, i18n } = useTranslation()
|
|
28
|
-
const [isExpired, setExpired] = useState(false)
|
|
29
|
-
const [isExecutionStarted, setExecutionStarted] = useState(
|
|
30
|
-
() => !!getExecutionProcess(step)
|
|
31
|
-
)
|
|
32
|
-
const [expiryTimestamp, setExpiryTimestamp] = useState(() =>
|
|
33
|
-
getExpiryTimestamp(step)
|
|
34
|
-
)
|
|
35
|
-
const { seconds, minutes, isRunning, pause, resume, restart } = useTimer({
|
|
36
|
-
autoStart: false,
|
|
37
|
-
expiryTimestamp,
|
|
38
|
-
onExpire: () => setExpired(true),
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
const executionProcess = getExecutionProcess(step)
|
|
43
|
-
if (!executionProcess) {
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
const shouldRestart = executionProcess.status === 'FAILED'
|
|
47
|
-
const shouldPause = executionProcess.status === 'ACTION_REQUIRED'
|
|
48
|
-
const shouldStart =
|
|
49
|
-
executionProcess.status === 'STARTED' ||
|
|
50
|
-
executionProcess.status === 'PENDING'
|
|
51
|
-
const shouldResume = executionProcess.status === 'PENDING'
|
|
52
|
-
if (isExecutionStarted && shouldRestart) {
|
|
53
|
-
setExecutionStarted(false)
|
|
54
|
-
setExpired(false)
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
if (isExecutionStarted && isExpired) {
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
if (!isExecutionStarted && shouldStart) {
|
|
61
|
-
const expiryTimestamp = getExpiryTimestamp(step)
|
|
62
|
-
setExecutionStarted(true)
|
|
63
|
-
setExpired(false)
|
|
64
|
-
setExpiryTimestamp(expiryTimestamp)
|
|
65
|
-
restart(expiryTimestamp)
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
if (isRunning && shouldPause) {
|
|
69
|
-
pause()
|
|
70
|
-
} else if (!isRunning && shouldResume) {
|
|
71
|
-
resume()
|
|
72
|
-
}
|
|
73
|
-
}, [isExecutionStarted, isExpired, isRunning, pause, restart, resume, step])
|
|
74
|
-
|
|
75
|
-
if (!isExecutionStarted) {
|
|
76
|
-
const showSeconds = step.estimate.executionDuration < 60
|
|
77
|
-
const duration = showSeconds
|
|
78
|
-
? Math.floor(step.estimate.executionDuration)
|
|
79
|
-
: Math.floor(step.estimate.executionDuration / 60)
|
|
80
|
-
return (
|
|
81
|
-
<StepTimerContent>
|
|
82
|
-
{duration.toLocaleString(i18n.language, {
|
|
83
|
-
style: 'unit',
|
|
84
|
-
unit: showSeconds ? 'second' : 'minute',
|
|
85
|
-
unitDisplay: 'narrow',
|
|
86
|
-
})}
|
|
87
|
-
</StepTimerContent>
|
|
88
|
-
)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const isTimerExpired = isExpired || (!minutes && !seconds)
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
step.execution?.status === 'DONE' ||
|
|
95
|
-
step.execution?.status === 'FAILED' ||
|
|
96
|
-
(isTimerExpired && hideInProgress)
|
|
97
|
-
) {
|
|
98
|
-
return null
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return isTimerExpired ? (
|
|
102
|
-
t('main.inProgress')
|
|
103
|
-
) : (
|
|
104
|
-
<StepTimerContent>
|
|
105
|
-
{`${minutes}:${seconds < 10 ? `0${seconds}` : seconds}`}
|
|
106
|
-
</StepTimerContent>
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const StepTimerContent: FC<PropsWithChildren> = ({ children }) => {
|
|
111
|
-
const { t } = useTranslation()
|
|
112
|
-
return (
|
|
113
|
-
<Tooltip title={t('tooltip.estimatedTime')} sx={{ cursor: 'help' }}>
|
|
114
|
-
<Box
|
|
115
|
-
component="span"
|
|
116
|
-
sx={{
|
|
117
|
-
display: 'flex',
|
|
118
|
-
alignItems: 'center',
|
|
119
|
-
height: 14,
|
|
120
|
-
}}
|
|
121
|
-
>
|
|
122
|
-
<IconTypography as="span" sx={{ marginRight: 0.5, fontSize: 16 }}>
|
|
123
|
-
<AccessTimeFilled fontSize="inherit" />
|
|
124
|
-
</IconTypography>
|
|
125
|
-
<Box
|
|
126
|
-
component="span"
|
|
127
|
-
sx={{
|
|
128
|
-
fontVariantNumeric: 'tabular-nums',
|
|
129
|
-
cursor: 'help',
|
|
130
|
-
}}
|
|
131
|
-
>
|
|
132
|
-
{children}
|
|
133
|
-
</Box>
|
|
134
|
-
</Box>
|
|
135
|
-
</Tooltip>
|
|
136
|
-
)
|
|
137
|
-
}
|
|
File without changes
|