From 1b3f049015c09abfd8e6bc181c7fd49d4b29ed52 Mon Sep 17 00:00:00 2001 From: Jaco Date: Tue, 31 Jan 2023 13:23:28 +0200 Subject: [PATCH] Adjust next-gen waiting display (#8900) * Adjust next-gen waiting display * isElected status * Re-use Active Status * Relay Badge adjustment --- .../{Validator => Active}/Status.tsx | 23 +++--- .../{Validator => Active}/index.tsx | 0 .../{Validator => Active}/useExposure.ts | 0 .../{Validator => Active}/useHeartbeat.ts | 0 .../src/Validators/ListActive.tsx | 8 +-- .../src/Validators/ListWaiting.tsx | 10 ++- .../src/Validators/Waiting/index.tsx | 72 +++++++++++++++++++ 7 files changed, 91 insertions(+), 22 deletions(-) rename packages/page-staking2/src/Validators/{Validator => Active}/Status.tsx (80%) rename packages/page-staking2/src/Validators/{Validator => Active}/index.tsx (100%) rename packages/page-staking2/src/Validators/{Validator => Active}/useExposure.ts (100%) rename packages/page-staking2/src/Validators/{Validator => Active}/useHeartbeat.ts (100%) create mode 100644 packages/page-staking2/src/Validators/Waiting/index.tsx diff --git a/packages/page-staking2/src/Validators/Validator/Status.tsx b/packages/page-staking2/src/Validators/Active/Status.tsx similarity index 80% rename from packages/page-staking2/src/Validators/Validator/Status.tsx rename to packages/page-staking2/src/Validators/Active/Status.tsx index ac06184acc..39966c1121 100644 --- a/packages/page-staking2/src/Validators/Validator/Status.tsx +++ b/packages/page-staking2/src/Validators/Active/Status.tsx @@ -10,7 +10,7 @@ import { Badge } from '@polkadot/react-components'; import { useAccounts } from '@polkadot/react-hooks'; interface Props { - heartbeat: UseHeartbeat; + heartbeat?: UseHeartbeat; isChilled?: boolean; isPara?: boolean; isRelay?: boolean; @@ -18,7 +18,7 @@ interface Props { validator: Validator; } -function Status ({ heartbeat: { authoredBlocks, isOnline }, isChilled, isPara, isRelay, nominators, validator: { isElected } }: Props): React.ReactElement { +function Status ({ heartbeat: { authoredBlocks, isOnline } = {}, isChilled, isPara, isRelay, nominators, validator: { isElected } }: Props): React.ReactElement { const { allAccounts } = useAccounts(); const isNominating = useMemo( @@ -44,16 +44,15 @@ function Status ({ heartbeat: { authoredBlocks, isOnline }, isChilled, isPara, i ) : emptyBadge } - {isRelay && ( - isPara - ? ( - - ) - : emptyBadge - )} + {isRelay && isPara + ? ( + + ) + : emptyBadge + } {isChilled ? ( ([ + const header = useRef<[string?, string?, number?][]>([ // favorite, badges, details, expand [t('validators'), 'start', 4] ]); @@ -36,12 +36,12 @@ function ListActive ({ className = '', isRelay, points, sessionInfo, toggleFavor className={className} empty={isNextTick && validatorsActive && t('No session validators found')} emptySpinner={t('Retrieving session validators')} - header={headerActive.current} + header={header.current} isSplit legend={} > {isNextTick && validatorsActive?.map((v) => ( - ([ + const header = useRef<[string?, string?, number?][]>([ // favorite, badges, details, expand [t('waiting'), 'start', 4] ]); @@ -37,15 +37,13 @@ function ListActive ({ className = '', favorites, isRelay, sessionInfo, toggleFa className={className} empty={isNextTick && validatorsWaiting && t('No waiting validators found')} emptySpinner={t('Retrieving waiting validators')} - header={headerWaiting.current} + header={header.current} isSplit legend={} > {isNextTick && validatorsWaiting?.map((v) => ( - diff --git a/packages/page-staking2/src/Validators/Waiting/index.tsx b/packages/page-staking2/src/Validators/Waiting/index.tsx new file mode 100644 index 0000000000..b1cc336cde --- /dev/null +++ b/packages/page-staking2/src/Validators/Waiting/index.tsx @@ -0,0 +1,72 @@ +// Copyright 2017-2023 @polkadot/app-staking authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { Validator } from '../../types'; + +import React from 'react'; + +import { AddressSmall, Table } from '@polkadot/react-components'; +import { useToggle } from '@polkadot/react-hooks'; + +import Status from '../Active/Status'; + +interface Props { + className?: string; + toggleFavorite: (stashId: string) => void; + validator: Validator; +} + +interface PropsExpanded { + className?: string; + validator: Validator; +} + +function ValidatorExpanded ({ className = '' }: PropsExpanded): React.ReactElement { + return ( + + + + + + + ); +} + +function Validator ({ className = '', toggleFavorite, validator }: Props): React.ReactElement { + const [isExpanded, toggleExpanded] = useToggle(); + + return ( + <> + + + + + + + + + + + + + + + + {isExpanded && ( + + )} + + ); +} + +export default React.memo(Validator);