@@ -134,18 +134,17 @@ export function useSwapActionHandlers(): {
134
134
// from the current swap inputs, compute the best trade and return it.
135
135
export function useDerivedSwapInfo ( state : SwapState ) : SwapInfo {
136
136
const account = useAccount ( )
137
- const {
138
- chainId,
139
- currencyState : { inputCurrency, outputCurrency } ,
140
- } = useSwapAndLimitContext ( )
137
+ const { chainId, currencyState } = useSwapAndLimitContext ( )
141
138
const nativeCurrency = useNativeCurrency ( chainId )
142
139
const balance = useCurrencyBalance ( account . address , nativeCurrency )
143
140
144
141
// Note: if the currency was selected from recent searches
145
142
// we don't have decimals (decimals are 0) need to fetch
146
143
// full currency info with useCurrencyInfo otherwise quotes will break
147
- const inputCurrencyInfo = useCurrencyInfo ( inputCurrency )
148
- const outputCurrencyInfo = useCurrencyInfo ( outputCurrency )
144
+ const inputCurrencyInfo = useCurrencyInfo ( currencyState . inputCurrency )
145
+ const outputCurrencyInfo = useCurrencyInfo ( currencyState . outputCurrency )
146
+ const inputCurrency = inputCurrencyInfo ?. currency
147
+ const outputCurrency = outputCurrencyInfo ?. currency
149
148
150
149
const { independentField, typedValue } = state
151
150
@@ -162,12 +161,8 @@ export function useDerivedSwapInfo(state: SwapState): SwapInfo {
162
161
163
162
const isExactIn : boolean = independentField === Field . INPUT
164
163
const parsedAmount = useMemo (
165
- ( ) =>
166
- tryParseCurrencyAmount (
167
- typedValue ,
168
- ( isExactIn ? inputCurrencyInfo ?. currency : outputCurrencyInfo ?. currency ) ?? undefined ,
169
- ) ,
170
- [ inputCurrencyInfo , isExactIn , outputCurrencyInfo , typedValue ] ,
164
+ ( ) => tryParseCurrencyAmount ( typedValue , ( isExactIn ? inputCurrency : outputCurrency ) ?? undefined ) ,
165
+ [ inputCurrency , isExactIn , outputCurrency , typedValue ] ,
171
166
)
172
167
173
168
const trade : {
@@ -177,7 +172,7 @@ export function useDerivedSwapInfo(state: SwapState): SwapInfo {
177
172
} = useDebouncedTrade (
178
173
isExactIn ? TradeType . EXACT_INPUT : TradeType . EXACT_OUTPUT ,
179
174
parsedAmount ,
180
- ( isExactIn ? outputCurrencyInfo ?. currency : inputCurrencyInfo ?. currency ) ?? undefined ,
175
+ ( isExactIn ? outputCurrency : inputCurrency ) ?? undefined ,
181
176
state . routerPreferenceOverride as RouterPreference . API | undefined ,
182
177
account . address ,
183
178
)
0 commit comments