-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathSummary.tsx
66 lines (56 loc) · 1.98 KB
/
Summary.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2017-2021 @polkadot/app-democracy authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DeriveElectionsInfo } from '@polkadot/api-derive/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import type { ComponentProps } from './types';
import React from 'react';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { formatNumber } from '@polkadot/util';
import { useTranslation } from '../translate';
interface Props extends ComponentProps {
bestNumber?: BlockNumber;
className?: string;
electionsInfo?: DeriveElectionsInfo;
}
function Summary ({ bestNumber, className = '', electionsInfo }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
if (!electionsInfo) {
return null;
}
const { candidateCount, desiredRunnersUp, desiredSeats, members, runnersUp, termDuration, voteCount } = electionsInfo;
return (
<SummaryBox className={className}>
<section>
<CardSummary label={t<string>('seats')}>
{formatNumber(members.length)} / {formatNumber(desiredSeats)}
</CardSummary>
<CardSummary label={t<string>('runners up')}>
{formatNumber(runnersUp.length)} / {formatNumber(desiredRunnersUp)}
</CardSummary>
<CardSummary label={t<string>('candidates')}>
{formatNumber(candidateCount)}
</CardSummary>
</section>
{voteCount && (
<section>
<CardSummary label={t<string>('voting round')}>
#{formatNumber(voteCount)}
</CardSummary>
</section>
)}
{bestNumber && termDuration?.gtn(0) && (
<section>
<CardSummary
label={t<string>('term progress')}
progress={{
total: termDuration,
value: bestNumber.mod(termDuration),
withTime: true
}}
/>
</section>
)}
</SummaryBox>
);
}
export default React.memo(Summary);