/* eslint-disable @typescript-eslint/camelcase */ // Copyright 2017-2019 @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 { DerivedSessionInfo } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; import React from 'react'; import { CardSummary } from '@polkadot/ui-app'; import { withCalls } from '@polkadot/ui-api'; import translate from './translate'; import { formatNumber } from '@polkadot/util'; interface Props extends I18nProps { session_info?: DerivedSessionInfo; withEra?: boolean; withSession?: boolean; } class SummarySession extends React.PureComponent { public render (): React.ReactNode { return ( <> {this.renderSession()} {this.renderEra()} ); } private renderEra (): React.ReactNode { const { session_info, t, withEra = true } = this.props; if (!withEra || !session_info) { return null; } console.error(JSON.stringify(session_info)); const label = session_info.isEpoch ? t('era slots') : t('era'); return session_info.sessionLength.gtn(0) ? ( ) : ( {formatNumber(session_info.currentEra)} ); } private renderSession (): React.ReactNode { const { session_info, t, withSession = true } = this.props; if (!withSession || !session_info) { return null; } const label = session_info.isEpoch ? t('epoch slots') : t('session'); return session_info.sessionLength.gtn(0) ? ( ) : ( {formatNumber(session_info.currentIndex)} ); } } export default translate( withCalls( 'derive.session.info' )(SummarySession) );