// Copyright 2017-2020 @polkadot/app-explorer authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. import { DeriveSessionProgress } from '@polkadot/api-derive/types'; import { Forcing } from '@polkadot/types/interfaces'; import React from 'react'; import { CardSummary } from '@polkadot/react-components'; import { useApi, useCall } from '@polkadot/react-hooks'; import { formatNumber } from '@polkadot/util'; import { useTranslation } from './translate'; interface Props { withEra?: boolean; withSession?: boolean; } function SummarySession ({ withEra = true, withSession = true }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const sessionInfo = useCall(api.query.staking && api.derive.session?.progress); const forcing = useCall(api.query.staking?.forceEra); const eraLabel = t('era'); const sessionLabel = sessionInfo?.isEpoch ? t('epoch') : t('session'); return ( <> {sessionInfo && ( <> {withSession && ( sessionInfo.sessionLength.gtn(1) ? ( ) : ( #{formatNumber(sessionInfo.currentIndex)} ) )} {forcing && !forcing.isForceNone && withEra && ( sessionInfo.sessionLength.gtn(1) ? ( ) : ( #{formatNumber(sessionInfo.activeEra)} ) )} )} ); } export default React.memo(SummarySession);