From 6a4fa0c9bf48aac37ffbe9293f097789ed77ec75 Mon Sep 17 00:00:00 2001 From: Justin Domingue Date: Tue, 18 May 2021 12:50:28 -0700 Subject: [PATCH] fix: division by 0 error when both reserves are 0 (#1632) * set pair to invalid if both reserves are 0 * consider reserve0/1=0 as no liquidity --- src/state/mint/hooks.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/state/mint/hooks.ts b/src/state/mint/hooks.ts index 6ed4e8478d..3f6d81898c 100644 --- a/src/state/mint/hooks.ts +++ b/src/state/mint/hooks.ts @@ -83,7 +83,14 @@ export function useDerivedMintInfo( const totalSupply = useTotalSupply(pair?.liquidityToken) const noLiquidity: boolean = - pairState === PairState.NOT_EXISTS || Boolean(totalSupply && JSBI.equal(totalSupply.quotient, ZERO)) + pairState === PairState.NOT_EXISTS || + Boolean(totalSupply && JSBI.equal(totalSupply.quotient, ZERO)) || + Boolean( + pairState === PairState.EXISTS && + pair && + JSBI.equal(pair.reserve0.quotient, ZERO) && + JSBI.equal(pair.reserve1.quotient, ZERO) + ) // balances const balances = useCurrencyBalances(account ?? undefined, [