mirror of
https://github.com/pezkuwichain/pezkuwi-sdk-ui.git
synced 2026-04-24 06:28:01 +00:00
d949863789
Comprehensive web interface for interacting with Pezkuwi blockchain. Features: - Blockchain explorer - Wallet management - Staking interface - Governance participation - Developer tools Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
109 lines
3.5 KiB
TypeScript
109 lines
3.5 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/app-explorer authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { DeriveSessionProgress } from '@pezkuwi/api-derive/types';
|
|
import type { Forcing } from '@pezkuwi/types/interfaces';
|
|
|
|
import React from 'react';
|
|
|
|
import { CardSummary } from '@pezkuwi/react-components';
|
|
import { useApi, useCall } from '@pezkuwi/react-hooks';
|
|
import { Elapsed } from '@pezkuwi/react-query';
|
|
import { BN_THREE, BN_TWO, formatNumber } from '@pezkuwi/util';
|
|
|
|
import { useTranslation } from './translate.js';
|
|
|
|
interface Props {
|
|
className?: string;
|
|
withEra?: boolean;
|
|
withSession?: boolean;
|
|
}
|
|
|
|
function SummarySession ({ className, withEra = true, withSession = true }: Props): React.ReactElement<Props> {
|
|
const { t } = useTranslation();
|
|
const { api } = useApi();
|
|
const sessionInfo = useCall<DeriveSessionProgress>(api.derive.session?.progress);
|
|
const forcing = useCall<Forcing>(api.query.staking?.forceEra);
|
|
|
|
const eraLabel = t('era');
|
|
const sessionLabel = api.query.babe
|
|
? t('epoch')
|
|
: t('session');
|
|
const activeEraStart = sessionInfo?.activeEraStart.unwrapOr(null);
|
|
|
|
return (
|
|
<>
|
|
{api.derive.session && (
|
|
<>
|
|
{withSession && (
|
|
api.query.babe
|
|
? (
|
|
<CardSummary
|
|
className={className}
|
|
label={sessionLabel}
|
|
progress={{
|
|
isBlurred: !sessionInfo,
|
|
total: sessionInfo?.sessionLength || BN_THREE,
|
|
value: sessionInfo?.sessionProgress || BN_TWO,
|
|
withTime: true
|
|
}}
|
|
/>
|
|
)
|
|
: (
|
|
<CardSummary label={sessionLabel}>
|
|
#{sessionInfo
|
|
? formatNumber(sessionInfo.currentIndex)
|
|
: <span className='--tmp'>123</span>}
|
|
{withEra && activeEraStart && <div className='isSecondary'> </div>}
|
|
</CardSummary>
|
|
)
|
|
)}
|
|
{withEra && (
|
|
api.query.babe
|
|
? (
|
|
<CardSummary
|
|
className={className}
|
|
label={eraLabel}
|
|
progress={{
|
|
isBlurred: !(sessionInfo && forcing),
|
|
total: sessionInfo && forcing
|
|
? forcing.isForceAlways
|
|
? sessionInfo.sessionLength
|
|
: sessionInfo.eraLength
|
|
: BN_THREE,
|
|
value: sessionInfo && forcing
|
|
? forcing.isForceAlways
|
|
? sessionInfo.sessionProgress
|
|
: sessionInfo.eraProgress
|
|
: BN_TWO,
|
|
withTime: true
|
|
}}
|
|
/>
|
|
)
|
|
: (
|
|
<CardSummary
|
|
className={className}
|
|
label={eraLabel}
|
|
>
|
|
#{sessionInfo
|
|
? formatNumber(sessionInfo.activeEra)
|
|
: <span className='--tmp'>123</span>}
|
|
{activeEraStart && (
|
|
<Elapsed
|
|
className={`${sessionInfo ? '' : '--tmp'} isSecondary`}
|
|
value={activeEraStart}
|
|
>
|
|
{t('elapsed')}
|
|
</Elapsed>
|
|
)}
|
|
</CardSummary>
|
|
)
|
|
)}
|
|
</>
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default React.memo(SummarySession);
|