@@ -4,28 +4,26 @@ import { ChainSelect } from "@/components/ChainSelect";
4
4
import { Divider } from "@/components/Divider" ;
5
5
import { TokenSelect } from "@/components/TokenSelect" ;
6
6
import { Button , Label , Skeleton } from "@/components/ui" ;
7
- import { useAvailableRoutes } from "@/lib/hooks/useAvailableRoutes" ;
8
- import { useInputTokens } from "@/lib/hooks/useInputTokens" ;
9
- import { useOutputTokens } from "@/lib/hooks/useOutputTokens" ;
10
- import { useQuote } from "@/lib/hooks/useQuote" ;
11
- import { useSupportedAcrossChains } from "@/lib/hooks/useSupportedAcrossChains" ;
7
+ import { useSwapQuote } from "@/lib/hooks/useSwapQuote" ;
12
8
import { getExplorerLink , isNativeToken } from "@/lib/utils" ;
13
9
import { TokenInfo } from "@across-protocol/app-sdk" ;
14
- import { useEffect , useState } from "react" ;
10
+ import { useState } from "react" ;
15
11
import { formatUnits , parseUnits } from "viem" ;
16
12
import { useAccount , useBalance , useChains } from "wagmi" ;
17
13
import { useDebounceValue } from "usehooks-ts" ;
18
- import { useExecuteQuote } from "@/lib/hooks/useExecuteQuote " ;
14
+ import { useExecuteSwapQuote } from "@/lib/hooks/useExecuteSwapQuote " ;
19
15
import { Progress } from "./Progress" ;
20
16
import { TokenInput } from "@/components/TokenInput" ;
21
17
import { ExternalLink } from "@/components/ExternalLink" ;
22
18
import { useAcrossChains } from "@/lib/hooks/useAcrossChains" ;
19
+ import { useSwapTokens } from "@/lib/hooks/useSwapTokens" ;
20
+ import { useSwapChains } from "@/lib/hooks/useSwapChains" ;
23
21
24
22
export function Bridge ( ) {
25
23
const { address } = useAccount ( ) ;
26
24
const chains = useChains ( ) ;
27
25
// CHAINS
28
- const { supportedChains } = useSupportedAcrossChains ( { } ) ;
26
+ const { swapChains : supportedChains } = useSwapChains ( { } ) ;
29
27
30
28
// use only token data for chains we support
31
29
const acrossChains = useAcrossChains ( ) ;
@@ -37,7 +35,7 @@ export function Bridge() {
37
35
) ;
38
36
39
37
// FROM TOKEN
40
- const { inputTokens } = useInputTokens ( originChainId ) ;
38
+ const { tokens : inputTokens } = useSwapTokens ( originChainId ) ;
41
39
42
40
const [ fromToken , setFromToken ] = useState < TokenInfo | undefined > (
43
41
inputTokens ?. [ 0 ] ,
@@ -55,74 +53,49 @@ export function Bridge() {
55
53
number | undefined
56
54
> ( chains . find ( ( chain ) => chain . id !== originChainId ) ?. id ) ;
57
55
58
- const { availableRoutes } = useAvailableRoutes ( {
59
- originChainId,
60
- destinationChainId,
61
- originToken : fromToken ?. address ,
62
- } ) ;
63
-
64
- const outputTokensForRoute = availableRoutes ?. map ( ( route ) =>
65
- route . outputToken . toLowerCase ( ) ,
66
- ) ;
67
-
68
- const { outputTokens : outputTokensForChain } =
69
- useOutputTokens ( destinationChainId ) ;
70
-
71
- const [ outputTokens , setOutputTokens ] = useState < TokenInfo [ ] | undefined > ( ) ;
72
-
73
- useEffect ( ( ) => {
74
- const _outputTokens = outputTokensForChain ?. filter ( ( token ) =>
75
- outputTokensForRoute ?. includes ( token . address . toLowerCase ( ) ) ,
76
- ) ;
77
- setOutputTokens ( _outputTokens ) ;
78
- } , [ availableRoutes ] ) ;
56
+ const { tokens : outputTokens } = useSwapTokens ( destinationChainId ) ;
79
57
80
58
const [ toToken , setToToken ] = useState < TokenInfo | undefined > (
81
59
outputTokens ?. [ 0 ] ,
82
60
) ;
83
61
84
- useEffect ( ( ) => {
85
- if ( outputTokens ) {
86
- setToToken (
87
- outputTokens . find ( ( token ) => token . symbol === fromToken ?. symbol ) ??
88
- outputTokens ?. [ 0 ] ,
89
- ) ;
90
- }
91
- } , [ outputTokens ] ) ;
92
-
93
62
const [ inputAmount , setInputAmount ] = useState < string > ( "" ) ;
94
63
const [ debouncedInputAmount ] = useDebounceValue ( inputAmount , 300 ) ;
95
- const route = availableRoutes ?. find ( ( route ) => {
96
- return (
97
- route . outputToken . toLocaleLowerCase ( ) ===
98
- toToken ?. address ?. toLowerCase ( ) &&
99
- route . outputTokenSymbol === toToken . symbol
100
- ) ;
101
- } ) ;
102
64
103
65
const quoteConfig =
104
- route && debouncedInputAmount && fromToken
66
+ debouncedInputAmount &&
67
+ fromToken &&
68
+ toToken &&
69
+ destinationChainId &&
70
+ originChainId &&
71
+ address
105
72
? {
106
- route,
73
+ route : {
74
+ originChainId : originChainId ,
75
+ destinationChainId : destinationChainId ,
76
+ inputToken : fromToken . address ,
77
+ outputToken : toToken . address ,
78
+ } ,
79
+ amount : parseUnits ( debouncedInputAmount , fromToken ?. decimals ) ,
80
+ depositor : address ,
107
81
recipient : address ,
108
- inputAmount : parseUnits ( debouncedInputAmount , fromToken ?. decimals ) ,
109
82
}
110
83
: undefined ;
111
84
112
85
const {
113
86
quote,
114
87
isLoading : quoteLoading ,
115
88
isRefetching,
116
- } = useQuote ( quoteConfig ) ;
89
+ } = useSwapQuote ( quoteConfig ) ;
117
90
118
91
const {
119
- executeQuote ,
92
+ executeSwapQuote ,
120
93
progress,
121
94
error,
122
95
isPending,
123
96
depositReceipt,
124
97
fillReceipt,
125
- } = useExecuteQuote ( quote ) ;
98
+ } = useExecuteSwapQuote ( quote ? { swapQuote : quote } : undefined ) ;
126
99
const inputBalance = fromTokenBalance
127
100
? parseFloat (
128
101
formatUnits ( fromTokenBalance ?. value , fromTokenBalance ?. decimals ) ,
@@ -232,12 +205,12 @@ export function Bridge() {
232
205
{ quote && toToken && (
233
206
< p className = "text-md font-normal text-text" >
234
207
{ parseFloat (
235
- formatUnits ( quote . deposit . outputAmount , toToken . decimals ) ,
208
+ formatUnits ( BigInt ( quote . minOutputAmount ) , toToken . decimals ) ,
236
209
) . toFixed ( 3 ) }
237
210
</ p >
238
211
) }
239
212
< Button
240
- onClick = { ( ) => executeQuote ( ) }
213
+ onClick = { ( ) => executeSwapQuote ( ) }
241
214
disabled = { ! ( quote && toToken ) || isRefetching || isPending }
242
215
className = "mt-2"
243
216
variant = "accent"
0 commit comments