Commit 307a995a authored by Justin Domingue's avatar Justin Domingue Committed by GitHub

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

* handle insufficient input amount error in mint/hooks

* use error.isInsufficientInputAmountError

* fixed typo
parent 46911593
...@@ -160,10 +160,16 @@ export function useDerivedMintInfo( ...@@ -160,10 +160,16 @@ export function useDerivedMintInfo(
wrappedCurrencyAmount(currencyBAmount, chainId), wrappedCurrencyAmount(currencyBAmount, chainId),
] ]
if (pair && totalSupply && tokenAmountA && tokenAmountB) { if (pair && totalSupply && tokenAmountA && tokenAmountB) {
return pair.getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB) try {
} else { return pair.getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB)
return undefined } catch (error) {
if (error.InsufficientInputAmountError) {
return CurrencyAmount.fromRawAmount(pair.liquidityToken, ZERO)
}
return undefined
}
} }
return undefined
}, [parsedAmounts, chainId, pair, totalSupply]) }, [parsedAmounts, chainId, pair, totalSupply])
const poolTokenPercentage = useMemo(() => { const poolTokenPercentage = useMemo(() => {
...@@ -197,6 +203,10 @@ export function useDerivedMintInfo( ...@@ -197,6 +203,10 @@ export function useDerivedMintInfo(
error = 'Insufficient ' + currencies[Field.CURRENCY_B]?.symbol + ' balance' error = 'Insufficient ' + currencies[Field.CURRENCY_B]?.symbol + ' balance'
} }
if (!liquidityMinted?.greaterThan(ZERO)) {
error = `Insufficient input amount`
}
return { return {
dependentField, dependentField,
currencies, currencies,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment