diff --git a/src/app/components/Validators/index.tsx b/src/app/components/Validators/index.tsx index 2564516e9f..da01167c9f 100644 --- a/src/app/components/Validators/index.tsx +++ b/src/app/components/Validators/index.tsx @@ -12,8 +12,12 @@ import { ValidatorCumulativeVoting } from './ValidatorCumulativeVoting' import { ValidatorLink } from './ValidatorLink' import { useRequiredScopeParam } from '../../hooks/useScopeParam' +export type RankedValidator = Validator & { + rank: number +} + type ValidatorsProps = { - validators?: Validator[] + validators?: RankedValidator[] isLoading: boolean limit: number pagination: false | TablePaginationProps @@ -49,7 +53,7 @@ export const Validators: FC = ({ { align: TableCellAlign.Center, // TODO: replace index when rank is implemented in the API - content:
{offset + index + 1}
, + content:
{validator.rank !== undefined ? validator.rank + 1 : offset + index + 1}
, key: 'rank', }, { diff --git a/src/app/pages/ValidatorsPage/hooks.ts b/src/app/pages/ValidatorsPage/hooks.ts index 372c0c05cc..4277b1a7c2 100644 --- a/src/app/pages/ValidatorsPage/hooks.ts +++ b/src/app/pages/ValidatorsPage/hooks.ts @@ -5,6 +5,7 @@ import { NUMBER_OF_ITEMS_ON_SEPARATE_PAGE } from '../../config' import { Network } from '../../../types/network' import { useTypedSearchParam } from '../../hooks/useTypedSearchParam' import { TFunction } from 'i18next' +import { RankedValidator } from '../../components/Validators' import { hasTextMatch } from '../../components/HighlightedText/text-matching' export const useValidatorNameSearch = () => useTypedSearchParam('name', '', { deleteParams: ['page'] }) @@ -31,11 +32,14 @@ const useWantedValidatorFilter = (): ValidatorFilter => { } export const useLoadedValidators = (network: Network, tableView: TableLayout) => { - const pagination = useClientSidePagination({ + const pagination = useClientSidePagination({ paramName: 'page', serverPageSize: 1000, clientPageSize: NUMBER_OF_ITEMS_ON_SEPARATE_PAGE, - transform: (data, r) => [data, [r.total_count, r.is_total_count_clipped]], + transform: (data, r) => [ + data.map((v, index): RankedValidator => ({ ...v, rank: index })), // add rank as an extra field + [r.total_count, r.is_total_count_clipped], // Extract the real number of validators + ], filter: useWantedValidatorFilter(), }) const { offset, limit } = pagination.paramsForServer