@@ -4,28 +4,26 @@ import { ChainSelect } from "@/components/ChainSelect";
44import { Divider } from "@/components/Divider" ;
55import { TokenSelect } from "@/components/TokenSelect" ;
66import { 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" ;
128import { getExplorerLink , isNativeToken } from "@/lib/utils" ;
139import { TokenInfo } from "@across-protocol/app-sdk" ;
14- import { useEffect , useState } from "react" ;
10+ import { useState } from "react" ;
1511import { formatUnits , parseUnits } from "viem" ;
1612import { useAccount , useBalance , useChains } from "wagmi" ;
1713import { useDebounceValue } from "usehooks-ts" ;
18- import { useExecuteQuote } from "@/lib/hooks/useExecuteQuote " ;
14+ import { useExecuteSwapQuote } from "@/lib/hooks/useExecuteSwapQuote " ;
1915import { Progress } from "./Progress" ;
2016import { TokenInput } from "@/components/TokenInput" ;
2117import { ExternalLink } from "@/components/ExternalLink" ;
2218import { useAcrossChains } from "@/lib/hooks/useAcrossChains" ;
19+ import { useSwapTokens } from "@/lib/hooks/useSwapTokens" ;
20+ import { useSwapChains } from "@/lib/hooks/useSwapChains" ;
2321
2422export function Bridge ( ) {
2523 const { address } = useAccount ( ) ;
2624 const chains = useChains ( ) ;
2725 // CHAINS
28- const { supportedChains } = useSupportedAcrossChains ( { } ) ;
26+ const { swapChains : supportedChains } = useSwapChains ( { } ) ;
2927
3028 // use only token data for chains we support
3129 const acrossChains = useAcrossChains ( ) ;
@@ -37,7 +35,7 @@ export function Bridge() {
3735 ) ;
3836
3937 // FROM TOKEN
40- const { inputTokens } = useInputTokens ( originChainId ) ;
38+ const { tokens : inputTokens } = useSwapTokens ( originChainId ) ;
4139
4240 const [ fromToken , setFromToken ] = useState < TokenInfo | undefined > (
4341 inputTokens ?. [ 0 ] ,
@@ -55,74 +53,49 @@ export function Bridge() {
5553 number | undefined
5654 > ( chains . find ( ( chain ) => chain . id !== originChainId ) ?. id ) ;
5755
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 ) ;
7957
8058 const [ toToken , setToToken ] = useState < TokenInfo | undefined > (
8159 outputTokens ?. [ 0 ] ,
8260 ) ;
8361
84- useEffect ( ( ) => {
85- if ( outputTokens ) {
86- setToToken (
87- outputTokens . find ( ( token ) => token . symbol === fromToken ?. symbol ) ??
88- outputTokens ?. [ 0 ] ,
89- ) ;
90- }
91- } , [ outputTokens ] ) ;
92-
9362 const [ inputAmount , setInputAmount ] = useState < string > ( "" ) ;
9463 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- } ) ;
10264
10365 const quoteConfig =
104- route && debouncedInputAmount && fromToken
66+ debouncedInputAmount &&
67+ fromToken &&
68+ toToken &&
69+ destinationChainId &&
70+ originChainId &&
71+ address
10572 ? {
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 ,
10781 recipient : address ,
108- inputAmount : parseUnits ( debouncedInputAmount , fromToken ?. decimals ) ,
10982 }
11083 : undefined ;
11184
11285 const {
11386 quote,
11487 isLoading : quoteLoading ,
11588 isRefetching,
116- } = useQuote ( quoteConfig ) ;
89+ } = useSwapQuote ( quoteConfig ) ;
11790
11891 const {
119- executeQuote ,
92+ executeSwapQuote ,
12093 progress,
12194 error,
12295 isPending,
12396 depositReceipt,
12497 fillReceipt,
125- } = useExecuteQuote ( quote ) ;
98+ } = useExecuteSwapQuote ( quote ? { swapQuote : quote } : undefined ) ;
12699 const inputBalance = fromTokenBalance
127100 ? parseFloat (
128101 formatUnits ( fromTokenBalance ?. value , fromTokenBalance ?. decimals ) ,
@@ -232,12 +205,12 @@ export function Bridge() {
232205 { quote && toToken && (
233206 < p className = "text-md font-normal text-text" >
234207 { parseFloat (
235- formatUnits ( quote . deposit . outputAmount , toToken . decimals ) ,
208+ formatUnits ( BigInt ( quote . minOutputAmount ) , toToken . decimals ) ,
236209 ) . toFixed ( 3 ) }
237210 </ p >
238211 ) }
239212 < Button
240- onClick = { ( ) => executeQuote ( ) }
213+ onClick = { ( ) => executeSwapQuote ( ) }
241214 disabled = { ! ( quote && toToken ) || isRefetching || isPending }
242215 className = "mt-2"
243216 variant = "accent"
0 commit comments