Handle insufficient reserves/input errors without crashing
This commit is contained in:
parent
f1ccd7a166
commit
ee92df1554
@ -21,7 +21,12 @@ export function useTradeExactIn(amountIn?: TokenAmount, tokenOut?: Token): Trade
|
||||
const allPairs = [pairBetween, aToETH, bToETH].filter(p => !!p)
|
||||
|
||||
if (amountIn && allPairs.length > 0 && tokenOut) {
|
||||
return Trade.bestTradeExactIn(allPairs, amountIn, tokenOut)[0] ?? null
|
||||
try {
|
||||
// TODO(moodysalem): remove when the insufficient reserves/input errors do not throw exceptions
|
||||
return Trade.bestTradeExactIn(allPairs, amountIn, tokenOut)[0] ?? null
|
||||
} catch (error) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
return null
|
||||
}, [aToETH, bToETH, pairBetween, amountIn, tokenOut])
|
||||
@ -44,7 +49,12 @@ export function useTradeExactOut(tokenIn?: Token, amountOut?: TokenAmount): Trad
|
||||
const allPairs = [pairBetween, aToETH, bToETH].filter(p => !!p)
|
||||
|
||||
if (amountOut && allPairs.length > 0 && tokenIn) {
|
||||
return Trade.bestTradeExactOut(allPairs, tokenIn, amountOut)[0] ?? null
|
||||
try {
|
||||
// TODO(moodysalem): remove when the insufficient reserves/input errors do not throw exceptions
|
||||
return Trade.bestTradeExactOut(allPairs, tokenIn, amountOut)[0] ?? null
|
||||
} catch (error) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
return null
|
||||
}, [pairBetween, aToETH, bToETH, amountOut, tokenIn])
|
||||
|
Loading…
Reference in New Issue
Block a user