Display para validators (testground staking) (#8913)
This commit is contained in:
parent
ddf044f479
commit
43b2568485
@ -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<P
|
||||
return <td className={className} />;
|
||||
}
|
||||
|
||||
function Entry ({ className = '', isRelay, points, sessionInfo, toggleFavorite, validator }: Props): React.ReactElement<Props> {
|
||||
function Entry ({ className = '', points, sessionInfo, toggleFavorite, validator }: Props): React.ReactElement<Props> {
|
||||
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}
|
||||
|
||||
@ -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<Props> {
|
||||
function Top ({ children, className = '', heartbeat, isExpanded, toggleExpanded, toggleFavorite, validator }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<tr className={`${className} isExpanded isFirst packedBottom`}>
|
||||
<Table.Column.Favorite
|
||||
@ -35,7 +34,6 @@ function Top ({ children, className = '', heartbeat, isExpanded, isRelay, toggle
|
||||
>
|
||||
<Status
|
||||
heartbeat={heartbeat}
|
||||
isRelay={isRelay}
|
||||
validator={validator}
|
||||
/>
|
||||
</td>
|
||||
|
||||
@ -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<Props> {
|
||||
function Status ({ className, heartbeat: { authoredBlocks, isOnline } = {}, isChilled, nominators, validator: { isElected, isPara } }: Props): React.ReactElement<Props> {
|
||||
const { allAccounts } = useAccounts();
|
||||
|
||||
const isNominating = useMemo(
|
||||
@ -34,7 +34,7 @@ function Status ({ heartbeat: { authoredBlocks, isOnline } = {}, isChilled, isPa
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<StyledDiv className={className}>
|
||||
{isNominating
|
||||
? (
|
||||
<Badge
|
||||
@ -44,7 +44,7 @@ function Status ({ heartbeat: { authoredBlocks, isOnline } = {}, isChilled, isPa
|
||||
)
|
||||
: emptyBadge
|
||||
}
|
||||
{isRelay && isPara
|
||||
{isPara
|
||||
? (
|
||||
<Badge
|
||||
color='purple'
|
||||
@ -74,7 +74,9 @@ function Status ({ heartbeat: { authoredBlocks, isOnline } = {}, isChilled, isPa
|
||||
? (
|
||||
<Badge
|
||||
color='green'
|
||||
info={authoredBlocks}
|
||||
info={
|
||||
<span className='authoredBlocks'>{authoredBlocks}</span>
|
||||
}
|
||||
/>
|
||||
)
|
||||
: (
|
||||
@ -85,8 +87,15 @@ function Status ({ heartbeat: { authoredBlocks, isOnline } = {}, isChilled, isPa
|
||||
)
|
||||
: emptyBadge
|
||||
}
|
||||
</div>
|
||||
</StyledDiv>
|
||||
);
|
||||
}
|
||||
|
||||
const StyledDiv = styled.div`
|
||||
.authoredBlocks {
|
||||
vertical-align: top;
|
||||
font-size: var(--font-percent-tiny);
|
||||
}
|
||||
`;
|
||||
|
||||
export default React.memo(Status);
|
||||
|
||||
@ -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<Props> {
|
||||
function Active ({ className = '', legend, points, sessionInfo, toggleFavorite, validatorsActive }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const isNextTick = useNextTick();
|
||||
|
||||
@ -38,11 +37,10 @@ function Active ({ className = '', isRelay, points, sessionInfo, toggleFavorite,
|
||||
emptySpinner={t<string>('Retrieving session validators')}
|
||||
header={header.current}
|
||||
isSplit
|
||||
legend={<Legend isRelay={isRelay} />}
|
||||
legend={legend}
|
||||
>
|
||||
{isNextTick && validatorsActive?.map((v) => (
|
||||
<Entry
|
||||
isRelay={isRelay}
|
||||
key={v.key}
|
||||
points={points?.[v.stashId]}
|
||||
sessionInfo={sessionInfo}
|
||||
|
||||
@ -5,7 +5,6 @@ import type { SessionInfo, Validator } 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';
|
||||
|
||||
@ -16,13 +15,13 @@ import Entry from './Entry';
|
||||
interface Props {
|
||||
className?: string;
|
||||
favorites: string[];
|
||||
isRelay: boolean;
|
||||
legend: React.ReactNode;
|
||||
sessionInfo: SessionInfo;
|
||||
toggleFavorite: (stashId: string) => void;
|
||||
validatorsActive?: Validator[];
|
||||
}
|
||||
|
||||
function Waiting ({ className = '', favorites, isRelay, sessionInfo, toggleFavorite, validatorsActive }: Props): React.ReactElement<Props> {
|
||||
function Waiting ({ className = '', favorites, legend, sessionInfo, toggleFavorite, validatorsActive }: Props): React.ReactElement<Props> {
|
||||
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<string>('Retrieving waiting validators')}
|
||||
header={header.current}
|
||||
isSplit
|
||||
legend={<Legend isRelay={isRelay} />}
|
||||
legend={legend}
|
||||
>
|
||||
{isNextTick && validatorsWaiting?.map((v) => (
|
||||
<Entry
|
||||
|
||||
@ -6,6 +6,7 @@ import type { SessionInfo } from '../types';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import Legend from '@polkadot/app-staking/Legend';
|
||||
import { Button, ToggleGroup } from '@polkadot/react-components';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
@ -33,6 +34,8 @@ function Validators ({ className = '', favorites, isRelay, sessionInfo, toggleFa
|
||||
{ text: t('Waiting'), value: 'waiting' }
|
||||
]);
|
||||
|
||||
const legend = <Legend isRelay={isRelay} />;
|
||||
|
||||
return (
|
||||
<StyledDiv className={className}>
|
||||
<Button.Group>
|
||||
@ -45,7 +48,7 @@ function Validators ({ className = '', favorites, isRelay, sessionInfo, toggleFa
|
||||
{intentIndex === 0
|
||||
? (
|
||||
<Active
|
||||
isRelay={isRelay}
|
||||
legend={legend}
|
||||
points={points}
|
||||
sessionInfo={sessionInfo}
|
||||
toggleFavorite={toggleFavorite}
|
||||
@ -55,7 +58,7 @@ function Validators ({ className = '', favorites, isRelay, sessionInfo, toggleFa
|
||||
: (
|
||||
<Waiting
|
||||
favorites={favorites}
|
||||
isRelay={isRelay}
|
||||
legend={legend}
|
||||
sessionInfo={sessionInfo}
|
||||
toggleFavorite={toggleFavorite}
|
||||
validatorsActive={validatorsActive}
|
||||
|
||||
@ -13,6 +13,7 @@ export interface Validator {
|
||||
isElected: boolean;
|
||||
isFavorite: boolean;
|
||||
isOwned: boolean;
|
||||
isPara?: boolean;
|
||||
key: string;
|
||||
stashId: string;
|
||||
stashIndex: number;
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
// Copyright 2017-2023 @polkadot/app-staking authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { u32 } from '@polkadot/types';
|
||||
import type { AccountId32 } from '@polkadot/types/interfaces';
|
||||
import type { SessionInfo, Validator } from './types';
|
||||
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks';
|
||||
import { objectSpread } from '@polkadot/util';
|
||||
|
||||
import { useCacheValue } from './useCache';
|
||||
import useTaggedValidators from './useTaggedValidators';
|
||||
@ -25,10 +29,28 @@ const OPT_VALIDATORS = {
|
||||
})
|
||||
};
|
||||
|
||||
const OPT_INDICES = {
|
||||
transform: (indices: u32[]): number[] =>
|
||||
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<Validator>({ isPara: true }, v)
|
||||
: v
|
||||
)
|
||||
: sessionValidators,
|
||||
[activeIndices, sessionValidators]
|
||||
);
|
||||
|
||||
const tagged = useTaggedValidators(favorites, sessionInfo, validatorsWithPara);
|
||||
|
||||
return useCacheValue('useValidatorsActive', tagged);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user