fix: handle insufficient input amount error in v2 add liquidity (#1652)

* handle insufficient input amount error in mint/hooks

* use error.isInsufficientInputAmountError

* fixed typo
This commit is contained in:
Justin Domingue 2021-05-19 13:18:32 -07:00 committed by GitHub
parent 46911593e5
commit 307a995a50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -160,10 +160,16 @@ export function useDerivedMintInfo(
wrappedCurrencyAmount(currencyBAmount, chainId),
]
if (pair && totalSupply && tokenAmountA && tokenAmountB) {
return pair.getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB)
} else {
return undefined
try {
return pair.getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB)
} catch (error) {
if (error.InsufficientInputAmountError) {
return CurrencyAmount.fromRawAmount(pair.liquidityToken, ZERO)
}
return undefined
}
}
return undefined
}, [parsedAmounts, chainId, pair, totalSupply])
const poolTokenPercentage = useMemo(() => {
@ -197,6 +203,10 @@ export function useDerivedMintInfo(
error = 'Insufficient ' + currencies[Field.CURRENCY_B]?.symbol + ' balance'
}
if (!liquidityMinted?.greaterThan(ZERO)) {
error = `Insufficient input amount`
}
return {
dependentField,
currencies,