// Copyright 2017-2026 @pezkuwi/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Option } from '@pezkuwi/types'; import type { Balance } from '@pezkuwi/types/interfaces'; import type { BN } from '@pezkuwi/util'; import React, { useMemo } from 'react'; import { CardSummary, styled, SummaryBox } from '@pezkuwi/react-components'; import { useApi, useCall } from '@pezkuwi/react-hooks'; import { FormatBalance } from '@pezkuwi/react-query'; import { BN_THREE, BN_TWO, BN_ZERO } from '@pezkuwi/util'; import { useTranslation } from '../translate.js'; interface Props { avgStaked?: BN; className?: string; lastEra?: BN; lowStaked?: BN; minNominated?: BN; minNominatorBond?: BN; numNominators?: number; numValidators?: number; stakedReturn: number; totalIssuance?: BN; totalStaked?: BN; } interface ProgressInfo { hideValue: true; isBlurred: boolean; total: BN; value: BN; } const OPT_REWARD = { transform: (optBalance: Option) => optBalance.unwrapOrDefault() }; function getProgressInfo (value?: BN, total?: BN): ProgressInfo { return { hideValue: true, isBlurred: !(value && total), total: (value && total) ? total : BN_THREE, value: (value && total) ? value : BN_TWO }; } function Summary ({ avgStaked, className, lastEra, lowStaked, minNominated, minNominatorBond, stakedReturn, totalIssuance, totalStaked }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const lastReward = useCall(lastEra && api.query.staking.erasValidatorReward, [lastEra], OPT_REWARD); const progressStake = useMemo( () => getProgressInfo(totalStaked, totalIssuance), [totalIssuance, totalStaked] ); const progressAvg = useMemo( () => getProgressInfo(lowStaked, avgStaked), [avgStaked, lowStaked] ); const percent = %; return (
{totalIssuance && (stakedReturn > 0) ? Number.isFinite(stakedReturn) ? <>{stakedReturn.toFixed(1)}{percent} : '-.-%' : 0.0{percent} }
 / 
{minNominated?.gt(BN_ZERO) && ( {minNominatorBond && ( <>  /  )} )}
); } const StyledSummaryBox = styled(SummaryBox)` .percent { font-size: var(--font-percent-tiny); } `; export default React.memo(Summary);