From 2e68dc3cc064a333bf698b85520d06039176ea89 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 22 Mar 2021 10:44:49 +0100 Subject: [PATCH] Additional calcInflation check (#4900) --- packages/react-hooks/src/useInflation.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/react-hooks/src/useInflation.ts b/packages/react-hooks/src/useInflation.ts index a200bcc1ad..5611c8c437 100644 --- a/packages/react-hooks/src/useInflation.ts +++ b/packages/react-hooks/src/useInflation.ts @@ -17,7 +17,9 @@ const EMPTY: Inflation = { inflation: 0, stakedReturn: 0 }; export function calcInflation (api: ApiPromise, totalStaked: BN, totalIssuance: BN): Inflation { const { falloff, idealStake, maxInflation, minInflation } = getInflationParams(api); - const stakedFraction = totalStaked.mul(BN_MILLION).div(totalIssuance).toNumber() / BN_MILLION.toNumber(); + const stakedFraction = totalStaked.isZero() || totalIssuance.isZero() + ? 0 + : totalStaked.mul(BN_MILLION).div(totalIssuance).toNumber() / BN_MILLION.toNumber(); const idealInterest = maxInflation / idealStake; const inflation = 100 * (minInflation + ( stakedFraction <= idealStake