Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A0-2592: Add filter showing only active suspensions #76

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions packages/page-staking/src/Suspensions/CurrentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

import React, { useRef, useState } from 'react';

import { Table } from '@polkadot/react-components';
import { Table, Toggle } from '@polkadot/react-components';

import Filtering from '../Filtering.js';
import useCurrentSessionInfo from '../Performance/useCurrentSessionInfo.js';
import { useTranslation } from '../translate.js';
import Address from './Address/index.js';
import { SuspensionEvent } from './index.js';
Expand All @@ -17,6 +18,8 @@ interface Props {
function CurrentList ({ suspensions }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const [nameFilter, setNameFilter] = useState<string>('');
const [activeOnly, setActiveOnly] = useState(true);
const [, currentEra] = useCurrentSessionInfo();

const headerRef = useRef<[string, string, number?][]>(
[
Expand All @@ -43,10 +46,18 @@ function CurrentList ({ suspensions }: Props): React.ReactElement<Props> {
'5H9h84SrX4gdXTxGyB6wtEfTye5Kb7vMcwARNLCZxMa1CruS', '5HdUiPkneLL2dQHvFkp47cfw63uPWSL8gFPzduLw6YXx3cBU'
];

const filteredSuspensions = suspensions?.filter(
jalooc marked this conversation as resolved.
Show resolved Hide resolved
({ address, suspensionLiftsInEra }) =>
!excludedReservedValidators.find((value) => value === address) &&
(!activeOnly || currentEra === undefined || suspensionLiftsInEra >= currentEra)
);

return (
<Table
empty={
suspensions !== undefined && suspensions.length === 0 && t<string>('No suspensions events found in the past 84 eras')
filteredSuspensions !== undefined &&
filteredSuspensions.length === 0 &&
t<string>('No suspension events matching the filters found in the past 84 eras')
}
emptySpinner={
<>
Expand All @@ -59,22 +70,26 @@ function CurrentList ({ suspensions }: Props): React.ReactElement<Props> {
nameFilter={nameFilter}
setNameFilter={setNameFilter}
/>
<Toggle
className='staking--buttonToggle'
label={t<string>('Active only')}
onChange={setActiveOnly}
value={activeOnly}
/>
</div>
}
header={headerRef.current}
>
{suspensions?.filter(({ address }) =>
!excludedReservedValidators.find((value) => value === address))
.map(({ address, era, suspensionLiftsInEra, suspensionReason }): React.ReactNode => (
<Address
address={address}
era={era}
filterName={nameFilter}
key={`address-${address}-era-${era}`}
suspensionLiftsInEra={suspensionLiftsInEra}
suspensionReason={suspensionReason}
/>
))}
{filteredSuspensions?.map(({ address, era, suspensionLiftsInEra, suspensionReason }): React.ReactNode => (
<Address
address={address}
era={era}
filterName={nameFilter}
key={`address-${address}-era-${era}`}
suspensionLiftsInEra={suspensionLiftsInEra}
suspensionReason={suspensionReason}
/>
))}
</Table>
);
}
Expand Down