@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react'
22import { ChaingeAggregateQuote , fetchAggregateQuote } from '@/hooks/chainge/fetchAggregateQuote'
33import { formatNumberWithDecimal } from '@/utils/formatting'
44import { ChaingeToken } from '@/hooks/chainge/useChaingeTokens'
5+ import { parseUnits } from 'ethers'
56
67// TODO refetch every 15 seconds
78const useAggregateQuote = (
@@ -18,11 +19,6 @@ const useAggregateQuote = (
1819 const controller = new AbortController ( )
1920 const { signal } = controller
2021
21- const formatPayAmountToBigInt = ( amount : number , decimals : number ) : bigint => {
22- const scaledAmount = Math . round ( amount * Math . pow ( 10 , decimals ) )
23- return BigInt ( scaledAmount )
24- }
25-
2622 const fetchQuote = async ( ) => {
2723 if ( ! payAmount || ! ( Number ( payAmount ) > 0 ) ) {
2824 setReceiveAmount ( '' )
@@ -34,7 +30,7 @@ const useAggregateQuote = (
3430 await new Promise ( ( resolve ) => setTimeout ( resolve , 200 ) )
3531 setError ( null )
3632 try {
37- const adjustedPayAmount = formatPayAmountToBigInt ( parseFloat ( payAmount ) , payToken . decimals )
33+ const adjustedPayAmount = parseUnits ( payAmount , payToken . decimals ) . toString ( )
3834 const quote = await fetchAggregateQuote ( payToken , receiveToken , adjustedPayAmount , { signal } )
3935 setAggregateQuote ( quote )
4036 if ( quote ) {
0 commit comments