ghost-portal/packages/page-explorer/src/SummarySession.tsx
Jaco Greeff c60ba8708a
Bumps w/ eslint (#2802)
* Bumps w/ eslint

* Additional

* Additional

* Additional

* Additional

* Remove style props

* Additional

* Additional

* Additional

* Additional (< 100)

* eslint passes, tsc next

* tsc fixes

* Update deps

* Update i18n
2020-05-24 19:41:14 +02:00

79 lines
2.3 KiB
TypeScript

// 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 React, { useMemo } 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<Props> {
const { t } = useTranslation();
const { api } = useApi();
const sessionInfo = useCall<DeriveSessionProgress>(api.derive.session?.progress, []);
const eraLabel = useMemo(() =>
t<string>('era')
, [t]);
const sessionLabel = useMemo(() =>
sessionInfo?.isEpoch
? t<string>('epoch')
: t<string>('session')
, [sessionInfo?.isEpoch, t]);
return (
<>
{sessionInfo && (
<>
{withSession && (
sessionInfo.sessionLength.gtn(1)
? (
<CardSummary
label={sessionLabel}
progress={{
total: sessionInfo.sessionLength,
value: sessionInfo.sessionProgress,
withTime: true
}}
/>
)
: (
<CardSummary label={sessionLabel}>
#{formatNumber(sessionInfo.currentIndex)}
</CardSummary>
)
)}
{withEra && (
sessionInfo.sessionLength.gtn(1)
? (
<CardSummary
label={eraLabel}
progress={{
total: sessionInfo.eraLength,
value: sessionInfo.eraProgress,
withTime: true
}}
/>
)
: (
<CardSummary label={eraLabel}>
#{formatNumber(sessionInfo.activeEra)}
</CardSummary>
)
)}
</>
)}
</>
);
}
export default React.memo(SummarySession);