@lifi/widget 3.26.0 → 3.26.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 +7 -0
- package/dist/esm/components/Chains/ChainsExpanded.d.ts +1 -1
- package/dist/esm/components/Chains/ChainsExpanded.js +3 -2
- package/dist/esm/components/Chains/ChainsExpanded.js.map +1 -1
- package/dist/esm/components/Chains/ChainsExpanded.style.js +1 -2
- package/dist/esm/components/Chains/ChainsExpanded.style.js.map +1 -1
- package/dist/esm/components/Chains/SelectChainContent.d.ts +1 -1
- package/dist/esm/components/Chains/SelectChainContent.js +3 -2
- package/dist/esm/components/Chains/SelectChainContent.js.map +1 -1
- package/dist/esm/components/Expansion/Expansion.js +5 -16
- package/dist/esm/components/Expansion/Expansion.js.map +1 -1
- package/dist/esm/components/Expansion/Expansion.style.d.ts +32 -0
- package/dist/esm/components/Expansion/Expansion.style.js +40 -0
- package/dist/esm/components/Expansion/Expansion.style.js.map +1 -0
- package/dist/esm/components/Expansion/ExpansionTransition.d.ts +0 -1
- package/dist/esm/components/Expansion/ExpansionTransition.js +1 -30
- package/dist/esm/components/Expansion/ExpansionTransition.js.map +1 -1
- package/dist/esm/components/Routes/RoutesContent.d.ts +2 -3
- package/dist/esm/components/Routes/RoutesContent.js +5 -21
- package/dist/esm/components/Routes/RoutesContent.js.map +1 -1
- package/dist/esm/components/Routes/RoutesExpanded.d.ts +2 -3
- package/dist/esm/components/Routes/RoutesExpanded.js +24 -8
- package/dist/esm/components/Routes/RoutesExpanded.js.map +1 -1
- package/dist/esm/components/Routes/RoutesExpanded.style.js +1 -2
- package/dist/esm/components/Routes/RoutesExpanded.style.js.map +1 -1
- package/dist/esm/config/version.d.ts +1 -1
- package/dist/esm/config/version.js +1 -1
- package/dist/esm/hooks/useRoutes.js +32 -4
- package/dist/esm/hooks/useRoutes.js.map +1 -1
- package/package.json +5 -5
- package/package.json.tmp +4 -4
- package/src/components/Chains/ChainsExpanded.style.tsx +1 -2
- package/src/components/Chains/ChainsExpanded.tsx +6 -2
- package/src/components/Chains/SelectChainContent.tsx +81 -82
- package/src/components/Expansion/Expansion.style.tsx +43 -0
- package/src/components/Expansion/Expansion.tsx +8 -23
- package/src/components/Expansion/ExpansionTransition.tsx +5 -33
- package/src/components/Routes/RoutesContent.tsx +8 -29
- package/src/components/Routes/RoutesExpanded.style.ts +1 -2
- package/src/components/Routes/RoutesExpanded.tsx +33 -13
- package/src/config/version.ts +1 -1
- package/src/hooks/useRoutes.ts +68 -33
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
import type { Route } from '@lifi/sdk'
|
|
2
|
-
import { useEffect, useRef } from 'react'
|
|
2
|
+
import { memo, useCallback, useEffect, useLayoutEffect, useRef } from 'react'
|
|
3
|
+
import { useNavigate } from 'react-router-dom'
|
|
3
4
|
import { useRoutes } from '../../hooks/useRoutes.js'
|
|
4
|
-
import {
|
|
5
|
+
import { useWidgetEvents } from '../../hooks/useWidgetEvents.js'
|
|
6
|
+
import { WidgetEvent } from '../../types/events.js'
|
|
7
|
+
import { navigationRoutes } from '../../utils/navigationRoutes.js'
|
|
5
8
|
import { ExpansionTransition } from '../Expansion/ExpansionTransition.js'
|
|
6
9
|
import { RoutesContent } from './RoutesContent.js'
|
|
7
10
|
import { routesExpansionWidth } from './RoutesExpanded.style.js'
|
|
8
11
|
|
|
9
12
|
interface RoutesExpandedProps {
|
|
10
|
-
|
|
13
|
+
canOpen: boolean
|
|
11
14
|
setOpenExpansion: (open: boolean) => void
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
export const RoutesExpanded = ({
|
|
15
|
-
|
|
17
|
+
export const RoutesExpanded = memo(function RoutesExpanded({
|
|
18
|
+
canOpen,
|
|
16
19
|
setOpenExpansion,
|
|
17
|
-
}: RoutesExpandedProps)
|
|
20
|
+
}: RoutesExpandedProps) {
|
|
21
|
+
const emitter = useWidgetEvents()
|
|
22
|
+
const navigate = useNavigate()
|
|
18
23
|
const routesRef = useRef<Route[]>(undefined)
|
|
19
|
-
|
|
20
24
|
const routesActiveRef = useRef(false)
|
|
25
|
+
|
|
21
26
|
const {
|
|
22
27
|
routes,
|
|
23
28
|
isLoading,
|
|
@@ -45,13 +50,29 @@ export const RoutesExpanded = ({
|
|
|
45
50
|
|
|
46
51
|
const expanded =
|
|
47
52
|
Boolean(routesActiveRef.current || isLoading || isFetching || isFetched) &&
|
|
48
|
-
|
|
53
|
+
canOpen
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: stable navigation callback that won't cause rerenders in RoutesContent
|
|
56
|
+
const onRouteClick = useCallback(
|
|
57
|
+
(route: Route) => {
|
|
58
|
+
setReviewableRoute(route)
|
|
59
|
+
navigate(navigationRoutes.transactionExecution, {
|
|
60
|
+
state: { routeId: route.id },
|
|
61
|
+
})
|
|
62
|
+
emitter.emit(WidgetEvent.RouteSelected, { route, routes: routes! })
|
|
63
|
+
},
|
|
64
|
+
[emitter, routes, setReviewableRoute]
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
// Use layout effect to update parent's width when expansion changes
|
|
68
|
+
useLayoutEffect(() => {
|
|
52
69
|
setOpenExpansion(expanded)
|
|
53
70
|
}, [expanded, setOpenExpansion])
|
|
54
71
|
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
emitter.emit(WidgetEvent.WidgetExpanded, expanded)
|
|
74
|
+
}, [emitter, expanded])
|
|
75
|
+
|
|
55
76
|
return (
|
|
56
77
|
<ExpansionTransition
|
|
57
78
|
in={expanded}
|
|
@@ -62,13 +83,12 @@ export const RoutesExpanded = ({
|
|
|
62
83
|
routes={routesRef.current || []}
|
|
63
84
|
isFetching={isFetching}
|
|
64
85
|
isLoading={isLoading}
|
|
65
|
-
expanded={expanded}
|
|
66
|
-
setReviewableRoute={setReviewableRoute}
|
|
67
86
|
dataUpdatedAt={dataUpdatedAt}
|
|
68
87
|
refetchTime={refetchTime}
|
|
69
88
|
fromChain={fromChain}
|
|
70
89
|
refetch={refetch}
|
|
90
|
+
onRouteClick={onRouteClick}
|
|
71
91
|
/>
|
|
72
92
|
</ExpansionTransition>
|
|
73
93
|
)
|
|
74
|
-
}
|
|
94
|
+
})
|
package/src/config/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget'
|
|
2
|
-
export const version = '3.26.
|
|
2
|
+
export const version = '3.26.1'
|
package/src/hooks/useRoutes.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from '@lifi/sdk'
|
|
11
11
|
import { useAccount } from '@lifi/wallet-management'
|
|
12
12
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
13
|
+
import { useCallback, useMemo } from 'react'
|
|
13
14
|
import { parseUnits } from 'viem'
|
|
14
15
|
import { useWidgetConfig } from '../providers/WidgetProvider/WidgetProvider.js'
|
|
15
16
|
import { useFieldValues } from '../stores/form/useFieldValues.js'
|
|
@@ -137,32 +138,63 @@ export const useRoutes = ({ observableRoute }: RoutesProps = {}) => {
|
|
|
137
138
|
!isBatchingSupportedLoading
|
|
138
139
|
|
|
139
140
|
// Some values should be strictly typed and isEnabled ensures that
|
|
140
|
-
const queryKey =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
141
|
+
const queryKey = useMemo(
|
|
142
|
+
() =>
|
|
143
|
+
[
|
|
144
|
+
getQueryKey('routes', keyPrefix),
|
|
145
|
+
account.address,
|
|
146
|
+
fromChain?.id as number,
|
|
147
|
+
fromToken?.address as string,
|
|
148
|
+
fromTokenAmount,
|
|
149
|
+
toWalletAddress,
|
|
150
|
+
toChain?.id as number,
|
|
151
|
+
toToken?.address as string,
|
|
152
|
+
toTokenAmount,
|
|
153
|
+
contractCalls,
|
|
154
|
+
slippage,
|
|
155
|
+
swapOnly,
|
|
156
|
+
disabledBridges,
|
|
157
|
+
disabledExchanges,
|
|
158
|
+
allowedBridges,
|
|
159
|
+
allowedExchanges,
|
|
160
|
+
routePriority,
|
|
161
|
+
subvariant,
|
|
162
|
+
allowSwitchChain,
|
|
163
|
+
enabledRefuel && enabledAutoRefuel,
|
|
164
|
+
gasRecommendationFromAmount,
|
|
165
|
+
feeConfig?.fee || fee,
|
|
166
|
+
!!isBatchingSupported,
|
|
167
|
+
observableRoute?.id,
|
|
168
|
+
] as const,
|
|
169
|
+
[
|
|
170
|
+
keyPrefix,
|
|
171
|
+
account.address,
|
|
172
|
+
fromChain?.id,
|
|
173
|
+
fromToken?.address,
|
|
174
|
+
fromTokenAmount,
|
|
175
|
+
toWalletAddress,
|
|
176
|
+
toChain?.id,
|
|
177
|
+
toToken?.address,
|
|
178
|
+
toTokenAmount,
|
|
179
|
+
contractCalls,
|
|
180
|
+
slippage,
|
|
181
|
+
swapOnly,
|
|
182
|
+
disabledBridges,
|
|
183
|
+
disabledExchanges,
|
|
184
|
+
allowedBridges,
|
|
185
|
+
allowedExchanges,
|
|
186
|
+
routePriority,
|
|
187
|
+
subvariant,
|
|
188
|
+
allowSwitchChain,
|
|
189
|
+
enabledRefuel,
|
|
190
|
+
enabledAutoRefuel,
|
|
191
|
+
gasRecommendationFromAmount,
|
|
192
|
+
feeConfig?.fee,
|
|
193
|
+
fee,
|
|
194
|
+
isBatchingSupported,
|
|
195
|
+
observableRoute?.id,
|
|
196
|
+
]
|
|
197
|
+
)
|
|
166
198
|
|
|
167
199
|
const { getIntermediateRoutes, setIntermediateRoutes } =
|
|
168
200
|
useIntermediateRoutesStore()
|
|
@@ -496,13 +528,16 @@ export const useRoutes = ({ observableRoute }: RoutesProps = {}) => {
|
|
|
496
528
|
},
|
|
497
529
|
})
|
|
498
530
|
|
|
499
|
-
const setReviewableRoute = (
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
531
|
+
const setReviewableRoute = useCallback(
|
|
532
|
+
(route: Route) => {
|
|
533
|
+
const queryDataKey = queryKey.toSpliced(queryKey.length - 1, 1, route.id)
|
|
534
|
+
queryClient.setQueryData(queryDataKey, [route], {
|
|
535
|
+
updatedAt: dataUpdatedAt || Date.now(),
|
|
536
|
+
})
|
|
537
|
+
setExecutableRoute(route)
|
|
538
|
+
},
|
|
539
|
+
[queryClient, dataUpdatedAt, setExecutableRoute, queryKey]
|
|
540
|
+
)
|
|
506
541
|
|
|
507
542
|
return {
|
|
508
543
|
routes: data || getIntermediateRoutes(queryKey),
|