refactor: make the price computation in v2 add liquidity a little safer

This commit is contained in:
Moody Salem 2021-05-18 16:06:54 -05:00
parent 02ecd727eb
commit 8e055df447
No known key found for this signature in database
GPG Key ID: 8CB5CD10385138DB

@ -141,13 +141,9 @@ export function useDerivedMintInfo(
const price = useMemo(() => {
if (noLiquidity) {
const { [Field.CURRENCY_A]: currencyAAmount, [Field.CURRENCY_B]: currencyBAmount } = parsedAmounts
if (currencyAAmount && currencyBAmount) {
return new Price(
currencyAAmount.currency,
currencyBAmount.currency,
currencyAAmount.quotient,
currencyBAmount.quotient
)
if (currencyAAmount?.greaterThan(0) && currencyBAmount?.greaterThan(0)) {
const value = currencyBAmount.divide(currencyAAmount)
return new Price(currencyAAmount.currency, currencyBAmount.currency, value.denominator, value.numerator)
}
return undefined
} else {