Avoind NaN for returns (#4899)
This commit is contained in:
parent
c23745f352
commit
bfd6e387d5
@ -13,6 +13,8 @@ import { BN_MILLION } from '@polkadot/util';
|
||||
import { useApi } from './useApi';
|
||||
import { useCall } from './useCall';
|
||||
|
||||
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();
|
||||
@ -25,14 +27,16 @@ export function calcInflation (api: ApiPromise, totalStaked: BN, totalIssuance:
|
||||
|
||||
return {
|
||||
inflation,
|
||||
stakedReturn: inflation / stakedFraction
|
||||
stakedReturn: stakedFraction
|
||||
? (inflation / stakedFraction)
|
||||
: 0
|
||||
};
|
||||
}
|
||||
|
||||
export function useInflation (totalStaked?: BN): Inflation {
|
||||
const { api } = useApi();
|
||||
const totalIssuance = useCall<BN>(api.query.balances.totalIssuance);
|
||||
const [state, setState] = useState<Inflation>({ inflation: 0, stakedReturn: 0 });
|
||||
const [state, setState] = useState<Inflation>(EMPTY);
|
||||
|
||||
useEffect((): void => {
|
||||
totalIssuance && totalStaked && setState(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user