ghost-portal/packages/app-explorer/src/SummarySession.tsx
Jaco Greeff f80e22a883
Updates for lazy payouts (#2292)
* Updates for lazy payouts

* Add chain overrides

* Align currentEra & indexes

* Empty nominator updates

* currentElected -> nextElected

* Bump deps

* Bump api
2020-02-24 21:00:39 +01:00

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