diff --git a/packages/page-staking/src/Overview/Summary.tsx b/packages/page-staking/src/Overview/Summary.tsx index a7443d1548..46746a9f2b 100644 --- a/packages/page-staking/src/Overview/Summary.tsx +++ b/packages/page-staking/src/Overview/Summary.tsx @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import type { DeriveStakingOverview } from '@polkadot/api-derive/types'; +import type { Inflation } from '@polkadot/react-hooks/types'; import React, { useContext } from 'react'; import styled from 'styled-components'; @@ -13,13 +14,14 @@ import { useTranslation } from '../translate'; interface Props { className?: string; + inflation: Inflation; isVisible: boolean; next?: string[]; nominators?: string[]; stakingOverview?: DeriveStakingOverview; } -function Summary ({ className = '', isVisible, next, nominators, stakingOverview }: Props): React.ReactElement { +function Summary ({ className = '', inflation, isVisible, next, nominators, stakingOverview }: Props): React.ReactElement { const { t } = useTranslation(); const { lastBlockAuthors, lastBlockNumber } = useContext(BlockAuthorsContext); @@ -47,6 +49,14 @@ function Summary ({ className = '', isVisible, next, nominators, stakingOverview {nominators.length} )} + {(inflation.inflation > 0) && ( + ('inflation')} + > + {inflation.inflation.toFixed(1)}% + + )}
{ +function Summary ({ avgStaked, inflation, lastReward, lowStaked, numNominators, numValidators, totalStaked }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const totalIssuance = useCall(api.query.balances?.totalIssuance); @@ -73,6 +75,14 @@ function Summary ({ avgStaked, lastReward, lowStaked, numNominators, numValidato )} + {(inflation.stakedReturn > 0) && ( + ('returns')} + > + {inflation.stakedReturn.toFixed(1)}% + + )}
{avgStaked && lowStaked && ( { +function Targets ({ className = '', inflation, isInElection, ownStashes, targets: { avgStaked, calcWith, lastReward, lowStaked, nominators, setCalcWith, totalStaked, validators }, toggleFavorite }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const allSlashes = useAvailableSlashes(); @@ -226,6 +227,7 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { avgStak
(api.derive.staking.overview); const isInElection = useCall(api.query.staking?.eraElectionStatus, undefined, transformElection); @@ -115,6 +115,7 @@ function StakingApp ({ basePath, className = '' }: Props): React.ReactElement void; } +export interface Inflation { + inflation: number; + stakedReturn: number; +} + export interface Slash { accountId: AccountId; amount: Balance; diff --git a/packages/react-hooks/src/useInflation.ts b/packages/react-hooks/src/useInflation.ts index 7096ab07b6..82c4538331 100644 --- a/packages/react-hooks/src/useInflation.ts +++ b/packages/react-hooks/src/useInflation.ts @@ -1,6 +1,8 @@ // Copyright 2017-2020 @polkadot/react-hooks authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { Inflation } from './types'; + import BN from 'bn.js'; import { useEffect, useState } from 'react'; import { KUSAMA_GENESIS, POLKADOT_GENESIS } from '@polkadot/apps-config'; @@ -15,11 +17,6 @@ interface Config { minInflation: number; } -interface State { - inflation: number; - stakedReturn: number; -} - const DEFAULT_CONFIG: Config = { falloff: 0.05, idealStake: 0.5, @@ -32,7 +29,7 @@ const KNOWN_CONFIG: Record = { [POLKADOT_GENESIS]: { ...DEFAULT_CONFIG, idealStake: 0.75 } }; -function getInflation ({ falloff, idealStake, maxInflation, minInflation }: Config = DEFAULT_CONFIG, totalStaked: BN, totalIssuance: BN): State { +function getInflation ({ falloff, idealStake, maxInflation, minInflation }: Config = DEFAULT_CONFIG, totalStaked: BN, totalIssuance: BN): Inflation { const stakedFraction = totalStaked.muln(1_000_000).div(totalIssuance).toNumber() / 1_000_000; const idealInterest = maxInflation / idealStake; const inflation = 100 * (minInflation + ( @@ -47,10 +44,10 @@ function getInflation ({ falloff, idealStake, maxInflation, minInflation }: Conf }; } -export function useInflation (totalStaked?: BN): State { +export function useInflation (totalStaked?: BN): Inflation { const { api } = useApi(); const totalIssuance = useCall(api.query.balances.totalIssuance); - const [state, setState] = useState({ inflation: 0, stakedReturn: 0 }); + const [state, setState] = useState({ inflation: 0, stakedReturn: 0 }); useEffect((): void => { totalIssuance && totalStaked && setState(