@@ -2,7 +2,7 @@ import { Currency, CurrencyAmount, TradeType } from '@uniswap/sdk-core'
2
2
import { Field } from 'components/swap/constants'
3
3
import { CHAIN_IDS_TO_NAMES , useSupportedChainId } from 'constants/chains'
4
4
import { NATIVE_CHAIN_ID } from 'constants/tokens'
5
- import { useCurrency } from 'hooks/Tokens'
5
+ import { useCurrency , useCurrencyInfo } from 'hooks/Tokens'
6
6
import { useAccount } from 'hooks/useAccount'
7
7
import useAutoSlippageTolerance from 'hooks/useAutoSlippageTolerance'
8
8
import { useDebouncedTrade } from 'hooks/useDebouncedTrade'
@@ -141,6 +141,12 @@ export function useDerivedSwapInfo(state: SwapState): SwapInfo {
141
141
const nativeCurrency = useNativeCurrency ( chainId )
142
142
const balance = useCurrencyBalance ( account . address , nativeCurrency )
143
143
144
+ // Note: if the currency was selected from recent searches
145
+ // we don't have decimals (decimals are 0) need to fetch
146
+ // full currency info with useCurrencyInfo otherwise quotes will break
147
+ const inputCurrencyInfo = useCurrencyInfo ( inputCurrency )
148
+ const outputCurrencyInfo = useCurrencyInfo ( outputCurrency )
149
+
144
150
const { independentField, typedValue } = state
145
151
146
152
const { inputTax, outputTax } = useSwapTaxes (
@@ -156,8 +162,12 @@ export function useDerivedSwapInfo(state: SwapState): SwapInfo {
156
162
157
163
const isExactIn : boolean = independentField === Field . INPUT
158
164
const parsedAmount = useMemo (
159
- ( ) => tryParseCurrencyAmount ( typedValue , ( isExactIn ? inputCurrency : outputCurrency ) ?? undefined ) ,
160
- [ inputCurrency , isExactIn , outputCurrency , typedValue ] ,
165
+ ( ) =>
166
+ tryParseCurrencyAmount (
167
+ typedValue ,
168
+ ( isExactIn ? inputCurrencyInfo ?. currency : outputCurrencyInfo ?. currency ) ?? undefined ,
169
+ ) ,
170
+ [ inputCurrencyInfo , isExactIn , outputCurrencyInfo , typedValue ] ,
161
171
)
162
172
163
173
const trade : {
@@ -167,7 +177,7 @@ export function useDerivedSwapInfo(state: SwapState): SwapInfo {
167
177
} = useDebouncedTrade (
168
178
isExactIn ? TradeType . EXACT_INPUT : TradeType . EXACT_OUTPUT ,
169
179
parsedAmount ,
170
- ( isExactIn ? outputCurrency : inputCurrency ) ?? undefined ,
180
+ ( isExactIn ? outputCurrencyInfo ?. currency : inputCurrencyInfo ?. currency ) ?? undefined ,
171
181
state . routerPreferenceOverride as RouterPreference . API | undefined ,
172
182
account . address ,
173
183
)
0 commit comments