From 43b25684859b4e0e4674abeed979bd03c66f6879 Mon Sep 17 00:00:00 2001 From: Jaco Date: Wed, 1 Feb 2023 11:01:17 +0200 Subject: [PATCH] Display para validators (testground staking) (#8913) --- .../src/Validators/Active/Entry.tsx | 4 +--- .../src/Validators/Active/Row/Top.tsx | 4 +--- .../src/Validators/Active/Status.tsx | 23 ++++++++++++------ .../src/Validators/Active/index.tsx | 8 +++---- .../src/Validators/Waiting/index.tsx | 7 +++--- .../page-staking2/src/Validators/index.tsx | 7 ++++-- packages/page-staking2/src/types.ts | 1 + .../page-staking2/src/useValidatorsActive.ts | 24 ++++++++++++++++++- 8 files changed, 53 insertions(+), 25 deletions(-) diff --git a/packages/page-staking2/src/Validators/Active/Entry.tsx b/packages/page-staking2/src/Validators/Active/Entry.tsx index 3423144f74..acb26ff04a 100644 --- a/packages/page-staking2/src/Validators/Active/Entry.tsx +++ b/packages/page-staking2/src/Validators/Active/Entry.tsx @@ -18,7 +18,6 @@ import Top from './Row/Top'; interface Props { className?: string; - isRelay: boolean; points?: number; sessionInfo: SessionInfo; toggleFavorite: (stashId: string) => void; @@ -34,7 +33,7 @@ function EntryExpanded ({ className = '' }: PropsExpanded): React.ReactElement

; } -function Entry ({ className = '', isRelay, points, sessionInfo, toggleFavorite, validator }: Props): React.ReactElement { +function Entry ({ className = '', points, sessionInfo, toggleFavorite, validator }: Props): React.ReactElement { const [isExpanded, toggleExpanded] = useToggle(); const pointsRef = useRef<{ counter: number, points: number }>({ counter: 0, points: 0 }); const exposure = useExposure(validator, sessionInfo); @@ -60,7 +59,6 @@ function Entry ({ className = '', isRelay, points, sessionInfo, toggleFavorite, className={className} heartbeat={heartbeat} isExpanded={isExpanded} - isRelay={isRelay} toggleExpanded={toggleExpanded} toggleFavorite={toggleFavorite} validator={validator} diff --git a/packages/page-staking2/src/Validators/Active/Row/Top.tsx b/packages/page-staking2/src/Validators/Active/Row/Top.tsx index 8a998baf39..c2439d0249 100644 --- a/packages/page-staking2/src/Validators/Active/Row/Top.tsx +++ b/packages/page-staking2/src/Validators/Active/Row/Top.tsx @@ -15,13 +15,12 @@ interface Props { className?: string; heartbeat?: UseHeartbeat; isExpanded: boolean; - isRelay?: boolean; toggleExpanded: () => void; toggleFavorite: (stashId: string) => void; validator: Validator; } -function Top ({ children, className = '', heartbeat, isExpanded, isRelay, toggleExpanded, toggleFavorite, validator }: Props): React.ReactElement { +function Top ({ children, className = '', heartbeat, isExpanded, toggleExpanded, toggleFavorite, validator }: Props): React.ReactElement { return ( diff --git a/packages/page-staking2/src/Validators/Active/Status.tsx b/packages/page-staking2/src/Validators/Active/Status.tsx index 39966c1121..4c830ad5e8 100644 --- a/packages/page-staking2/src/Validators/Active/Status.tsx +++ b/packages/page-staking2/src/Validators/Active/Status.tsx @@ -5,20 +5,20 @@ import type { Validator } from '../../types'; import type { UseHeartbeat } from '../types'; import React, { useMemo } from 'react'; +import styled from 'styled-components'; import { Badge } from '@polkadot/react-components'; import { useAccounts } from '@polkadot/react-hooks'; interface Props { + className?: string; heartbeat?: UseHeartbeat; isChilled?: boolean; - isPara?: boolean; - isRelay?: boolean; nominators?: string[]; validator: Validator; } -function Status ({ heartbeat: { authoredBlocks, isOnline } = {}, isChilled, isPara, isRelay, nominators, validator: { isElected } }: Props): React.ReactElement { +function Status ({ className, heartbeat: { authoredBlocks, isOnline } = {}, isChilled, nominators, validator: { isElected, isPara } }: Props): React.ReactElement { const { allAccounts } = useAccounts(); const isNominating = useMemo( @@ -34,7 +34,7 @@ function Status ({ heartbeat: { authoredBlocks, isOnline } = {}, isChilled, isPa ); return ( -

+ {isNominating ? ( {authoredBlocks} + } /> ) : ( @@ -85,8 +87,15 @@ function Status ({ heartbeat: { authoredBlocks, isOnline } = {}, isChilled, isPa ) : emptyBadge } -
+ ); } +const StyledDiv = styled.div` + .authoredBlocks { + vertical-align: top; + font-size: var(--font-percent-tiny); + } +`; + export default React.memo(Status); diff --git a/packages/page-staking2/src/Validators/Active/index.tsx b/packages/page-staking2/src/Validators/Active/index.tsx index 575a05dd12..45d59cdbf0 100644 --- a/packages/page-staking2/src/Validators/Active/index.tsx +++ b/packages/page-staking2/src/Validators/Active/index.tsx @@ -6,7 +6,6 @@ import type { UsePoints } from '../types'; import React, { useRef } from 'react'; -import Legend from '@polkadot/app-staking/Legend'; import { Table } from '@polkadot/react-components'; import { useNextTick } from '@polkadot/react-hooks'; @@ -15,14 +14,14 @@ import Entry from './Entry'; interface Props { className?: string; - isRelay: boolean; + legend: React.ReactNode; points?: UsePoints; sessionInfo: SessionInfo; toggleFavorite: (stashId: string) => void; validatorsActive?: Validator[]; } -function Active ({ className = '', isRelay, points, sessionInfo, toggleFavorite, validatorsActive }: Props): React.ReactElement { +function Active ({ className = '', legend, points, sessionInfo, toggleFavorite, validatorsActive }: Props): React.ReactElement { const { t } = useTranslation(); const isNextTick = useNextTick(); @@ -38,11 +37,10 @@ function Active ({ className = '', isRelay, points, sessionInfo, toggleFavorite, emptySpinner={t('Retrieving session validators')} header={header.current} isSplit - legend={} + legend={legend} > {isNextTick && validatorsActive?.map((v) => ( void; validatorsActive?: Validator[]; } -function Waiting ({ className = '', favorites, isRelay, sessionInfo, toggleFavorite, validatorsActive }: Props): React.ReactElement { +function Waiting ({ className = '', favorites, legend, sessionInfo, toggleFavorite, validatorsActive }: Props): React.ReactElement { const { t } = useTranslation(); const isNextTick = useNextTick(); const validatorsWaiting = useValidatorsWaiting(favorites, sessionInfo, validatorsActive); @@ -39,7 +38,7 @@ function Waiting ({ className = '', favorites, isRelay, sessionInfo, toggleFavor emptySpinner={t('Retrieving waiting validators')} header={header.current} isSplit - legend={} + legend={legend} > {isNextTick && validatorsWaiting?.map((v) => ( ; + return ( @@ -45,7 +48,7 @@ function Validators ({ className = '', favorites, isRelay, sessionInfo, toggleFa {intentIndex === 0 ? ( + indices.map((n) => n.toNumber()) +}; + function useValidatorsActiveImpl (favorites: string[], sessionInfo: SessionInfo): Validator[] | undefined { const { api } = useApi(); const sessionValidators = useCall(api.query.session.validators, undefined, OPT_VALIDATORS); - const tagged = useTaggedValidators(favorites, sessionInfo, sessionValidators); + const activeIndices = useCall((api.query.parasShared || api.query.shared)?.activeValidatorIndices, undefined, OPT_INDICES); + + const validatorsWithPara = useMemo( + () => activeIndices && sessionValidators + ? sessionValidators.map((v, index) => + activeIndices.includes(index) + ? objectSpread({ isPara: true }, v) + : v + ) + : sessionValidators, + [activeIndices, sessionValidators] + ); + + const tagged = useTaggedValidators(favorites, sessionInfo, validatorsWithPara); return useCacheValue('useValidatorsActive', tagged); }