Skip to content

Commit

Permalink
fix: handle insufficient input amount error in v2 add liquidity (Unis…
Browse files Browse the repository at this point in the history
…wap#1652)

* handle insufficient input amount error in mint/hooks

* use error.isInsufficientInputAmountError

* fixed typo
  • Loading branch information
Justin Domingue authored May 19, 2021
1 parent 4691159 commit 307a995
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/state/mint/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 307a995

Please sign in to comment.