Display activeEraStart with Babe (#4105)

This commit is contained in:
Jaco Greeff 2020-11-29 22:50:12 +01:00 committed by GitHub
parent 242951585b
commit 6ae747b9e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import type { Forcing } from '@polkadot/types/interfaces';
import React from 'react';
import { CardSummary } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
import { Elapsed } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';
import { useTranslation } from './translate';
@ -26,6 +27,7 @@ function SummarySession ({ withEra = true, withSession = true }: Props): React.R
const sessionLabel = sessionInfo?.isEpoch
? t<string>('epoch')
: t<string>('session');
const activeEraStart = sessionInfo?.activeEraStart.unwrapOr(null);
return (
<>
@ -46,6 +48,7 @@ function SummarySession ({ withEra = true, withSession = true }: Props): React.R
: (
<CardSummary label={sessionLabel}>
#{formatNumber(sessionInfo.currentIndex)}
{withEra && activeEraStart && <div className='isSecondary'>&nbsp;</div>}
</CardSummary>
)
)}
@ -64,6 +67,14 @@ function SummarySession ({ withEra = true, withSession = true }: Props): React.R
: (
<CardSummary label={eraLabel}>
#{formatNumber(sessionInfo.activeEra)}
{activeEraStart && (
<Elapsed
className='isSecondary'
value={activeEraStart}
>
&nbsp;{t('elpased')}
</Elapsed>
)}
</CardSummary>
)
)}

View File

@ -8,6 +8,7 @@ import { bnToBn } from '@polkadot/util';
type Ticker = (now: number) => void;
interface Props {
children?: React.ReactNode;
className?: string;
value?: BN | Date | number;
}
@ -55,7 +56,7 @@ function getDisplayValue (now = 0, value: BN | Date | number = 0): string {
tick();
function Elapsed ({ className = '', value }: Props): React.ReactElement<Props> {
function Elapsed ({ children, className = '', value }: Props): React.ReactElement<Props> {
const [now, setNow] = useState(lastNow);
useEffect((): () => void => {
@ -69,8 +70,8 @@ function Elapsed ({ className = '', value }: Props): React.ReactElement<Props> {
}, []);
return (
<div className={['ui--Elapsed', className].join(' ')}>
{getDisplayValue(now, value)}
<div className={`ui--Elapsed ${className}`}>
{getDisplayValue(now, value)}{children}
</div>
);
}