Display activeEraStart with Babe (#4105)
This commit is contained in:
parent
242951585b
commit
6ae747b9e3
@ -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'> </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}
|
||||
>
|
||||
{t('elpased')}
|
||||
</Elapsed>
|
||||
)}
|
||||
</CardSummary>
|
||||
)
|
||||
)}
|
||||
|
||||
@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user