Nominations current elected (#1816)
* Nominations for currentElected * Drop nominatioons (for now) * Display forks (i.e. multi authors)
This commit is contained in:
parent
888afac71f
commit
3948690528
@ -26,7 +26,7 @@ interface Props extends I18nProps {
|
||||
currentElected: string[];
|
||||
defaultName: string;
|
||||
filter: ValidatorFilter;
|
||||
lastAuthor?: string;
|
||||
lastAuthors?: string[];
|
||||
points?: Points;
|
||||
recentlyOnline?: DerivedHeartbeats;
|
||||
stakingInfo?: DerivedStaking;
|
||||
@ -53,7 +53,7 @@ interface OnlineState {
|
||||
|
||||
const WITH_VALIDATOR_PREFS = { validatorPayment: true };
|
||||
|
||||
function Address ({ address, authorsMap, className, currentElected, defaultName, filter, lastAuthor, points, recentlyOnline, stakingInfo, t, withNominations }: Props): React.ReactElement<Props> | null {
|
||||
function Address ({ address, authorsMap, className, currentElected, defaultName, filter, lastAuthors, points, recentlyOnline, stakingInfo, t, withNominations }: Props): React.ReactElement<Props> | null {
|
||||
const { isSubstrateV2 } = useContext(ApiContext);
|
||||
const [extraInfo, setExtraInfo] = useState<[React.ReactNode, React.ReactNode][] | undefined>();
|
||||
const [{ hasOfflineWarnings, onlineStatus }, setOnlineStatus] = useState<OnlineState>({
|
||||
@ -83,7 +83,7 @@ function Address ({ address, authorsMap, className, currentElected, defaultName,
|
||||
useEffect((): void => {
|
||||
if (stakingInfo) {
|
||||
const { controllerId, nextSessionId, stakers, stashId } = stakingInfo;
|
||||
const nominators = stakers
|
||||
const nominators = withNominations && stakers
|
||||
? stakers.others.map(({ who, value }): [AccountId, Balance] => [who, value.unwrap()])
|
||||
: [];
|
||||
const myAccounts = keyring.getAccounts().map(({ address }): string => address);
|
||||
@ -148,7 +148,7 @@ function Address ({ address, authorsMap, className, currentElected, defaultName,
|
||||
}
|
||||
|
||||
const lastBlockNumber = authorsMap[stashId];
|
||||
const isAuthor = lastAuthor === stashId;
|
||||
const isAuthor = lastAuthors && lastAuthors.includes(stashId);
|
||||
// isDisabled={!!points && points.isEmpty}
|
||||
|
||||
return (
|
||||
|
||||
@ -18,12 +18,12 @@ interface Props extends I18nProps {
|
||||
currentElected: string[];
|
||||
currentValidators: string[];
|
||||
eraPoints?: EraPoints;
|
||||
lastAuthor?: string;
|
||||
lastAuthors?: string[];
|
||||
next: string[];
|
||||
recentlyOnline?: DerivedHeartbeats;
|
||||
}
|
||||
|
||||
function renderColumn (addresses: string[], defaultName: string, withExpanded: boolean, filter: string, without: string[], { authorsMap, currentElected, eraPoints, lastAuthor, recentlyOnline }: Props): React.ReactNode {
|
||||
function renderColumn (addresses: string[], defaultName: string, withNominations: boolean, withPoints: boolean, filter: string, without: string[], { authorsMap, currentElected, eraPoints, lastAuthors, recentlyOnline }: Props): React.ReactNode {
|
||||
return addresses.filter((address): boolean => !without.includes(address)).map((address, index): React.ReactNode => (
|
||||
<Address
|
||||
address={address}
|
||||
@ -31,15 +31,15 @@ function renderColumn (addresses: string[], defaultName: string, withExpanded: b
|
||||
currentElected={currentElected}
|
||||
defaultName={defaultName}
|
||||
filter={filter}
|
||||
lastAuthor={lastAuthor}
|
||||
lastAuthors={lastAuthors}
|
||||
key={address}
|
||||
points={
|
||||
withExpanded && eraPoints
|
||||
withPoints && eraPoints
|
||||
? eraPoints.individual[index]
|
||||
: undefined
|
||||
}
|
||||
recentlyOnline={recentlyOnline}
|
||||
withNominations={withExpanded}
|
||||
withNominations={withNominations}
|
||||
/>
|
||||
));
|
||||
}
|
||||
@ -71,14 +71,14 @@ function CurrentList (props: Props): React.ReactElement<Props> {
|
||||
emptyText={t('No addresses found')}
|
||||
headerText={t('validators')}
|
||||
>
|
||||
{renderColumn(currentValidators, t('validator'), true, filter, [], props)}
|
||||
{renderColumn(currentValidators, t('validator'), true, true, filter, [], props)}
|
||||
</Column>
|
||||
<Column
|
||||
emptyText={t('No addresses found')}
|
||||
headerText={t('next up')}
|
||||
>
|
||||
{renderColumn(currentElected, t('intention'), false, filter, currentValidators, props)}
|
||||
{renderColumn(next, t('intention'), false, filter, currentElected || [], props)}
|
||||
{renderColumn(currentElected, t('intention'), false, false, filter, currentValidators, props)}
|
||||
{renderColumn(next, t('intention'), false, false, filter, currentElected || [], props)}
|
||||
</Column>
|
||||
</Columar>
|
||||
</div>
|
||||
|
||||
@ -18,13 +18,13 @@ interface Props extends I18nProps {
|
||||
allControllers: string[];
|
||||
className?: string;
|
||||
currentValidators: string[];
|
||||
lastAuthor?: string;
|
||||
lastAuthors?: string[];
|
||||
lastBlock: string;
|
||||
staking_validatorCount?: BN;
|
||||
next: string[];
|
||||
}
|
||||
|
||||
function Summary ({ className, currentValidators, lastAuthor, lastBlock, next, style, staking_validatorCount, t }: Props): React.ReactElement<Props> {
|
||||
function Summary ({ className, currentValidators, lastAuthors, lastBlock, next, style, staking_validatorCount, t }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<SummaryBox
|
||||
className={className}
|
||||
@ -39,14 +39,18 @@ function Summary ({ className, currentValidators, lastAuthor, lastBlock, next, s
|
||||
</CardSummary>
|
||||
</section>
|
||||
<section>
|
||||
<CardSummary label={t('last block')}>
|
||||
{lastAuthor && (
|
||||
<CardSummary
|
||||
className='validator--Summary-authors'
|
||||
label={t('last block')}
|
||||
>
|
||||
{lastAuthors && lastAuthors.map((author): React.ReactNode => (
|
||||
<IdentityIcon
|
||||
className='validator--Account-block-icon'
|
||||
key={author}
|
||||
size={24}
|
||||
value={lastAuthor}
|
||||
value={author}
|
||||
/>
|
||||
)}
|
||||
))}
|
||||
{lastBlock}
|
||||
</CardSummary>
|
||||
</section>
|
||||
@ -64,6 +68,12 @@ export default withMulti(
|
||||
margin-top: -0.25rem;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.validator--Summary-authors {
|
||||
.validator--Account-block-icon+.validator--Account-block-icon {
|
||||
margin-left: -1.5rem;
|
||||
}
|
||||
}
|
||||
`,
|
||||
translate,
|
||||
withCalls<Props>('query.staking.validatorCount')
|
||||
|
||||
@ -20,7 +20,7 @@ interface Props extends BareProps, ComponentProps {
|
||||
|
||||
export default function Overview ({ allControllers, allStashes, currentElected, currentValidators, eraPoints, recentlyOnline }: Props): React.ReactElement<Props> {
|
||||
const { isSubstrateV2 } = useContext(ApiContext);
|
||||
const { byAuthor, lastBlockAuthor, lastBlockNumber } = useContext(BlockAuthorsContext);
|
||||
const { byAuthor, lastBlockAuthors, lastBlockNumber } = useContext(BlockAuthorsContext);
|
||||
const [next, setNext] = useState<string[]>([]);
|
||||
|
||||
useEffect((): void => {
|
||||
@ -40,7 +40,7 @@ export default function Overview ({ allControllers, allStashes, currentElected,
|
||||
currentElected={currentElected}
|
||||
currentValidators={currentValidators}
|
||||
lastBlock={lastBlockNumber}
|
||||
lastAuthor={lastBlockAuthor}
|
||||
lastAuthors={lastBlockAuthors}
|
||||
next={next}
|
||||
/>
|
||||
<CurrentList
|
||||
@ -48,7 +48,7 @@ export default function Overview ({ allControllers, allStashes, currentElected,
|
||||
currentElected={currentElected}
|
||||
currentValidators={currentValidators}
|
||||
eraPoints={eraPoints}
|
||||
lastAuthor={lastBlockAuthor}
|
||||
lastAuthors={lastBlockAuthors}
|
||||
next={next}
|
||||
recentlyOnline={recentlyOnline}
|
||||
/>
|
||||
|
||||
@ -9,7 +9,7 @@ import { formatNumber } from '@polkadot/util';
|
||||
|
||||
interface Authors {
|
||||
byAuthor: Record<string, string>;
|
||||
lastBlockAuthor?: string;
|
||||
lastBlockAuthors?: string[];
|
||||
lastBlockNumber?: string;
|
||||
lastHeader?: HeaderExtended;
|
||||
lastHeaders: HeaderExtended[];
|
||||
@ -33,15 +33,24 @@ function BlockAuthors ({ children }: Props): React.ReactElement<Props> {
|
||||
// atm I'm rather typing this than doing it the way it is supposed to be
|
||||
api.isReady.then((): void => {
|
||||
let lastHeaders: HeaderExtended[] = [];
|
||||
let lastBlockAuthors: string[] = [];
|
||||
let lastBlockNumber = '';
|
||||
|
||||
api.derive.chain.subscribeNewHeads((lastHeader): void => {
|
||||
if (lastHeader && lastHeader.number) {
|
||||
const blockNumber = lastHeader.number.unwrap();
|
||||
const lastBlockAuthor = lastHeader.author ? lastHeader.author.toString() : undefined;
|
||||
const lastBlockNumber = formatNumber(blockNumber);
|
||||
const thisBlockAuthor = lastHeader.author ? lastHeader.author.toString() : undefined;
|
||||
const thisBlockNumber = formatNumber(blockNumber);
|
||||
|
||||
if (lastBlockAuthor) {
|
||||
byAuthor[lastBlockAuthor] = lastBlockNumber;
|
||||
if (thisBlockAuthor) {
|
||||
byAuthor[thisBlockAuthor] = thisBlockNumber;
|
||||
|
||||
if (thisBlockNumber !== lastBlockNumber) {
|
||||
lastBlockNumber = thisBlockNumber;
|
||||
lastBlockAuthors = [thisBlockAuthor];
|
||||
} else {
|
||||
lastBlockAuthors.push(thisBlockAuthor);
|
||||
}
|
||||
}
|
||||
|
||||
lastHeaders = lastHeaders
|
||||
@ -53,7 +62,7 @@ function BlockAuthors ({ children }: Props): React.ReactElement<Props> {
|
||||
}, [lastHeader])
|
||||
.sort((a, b): number => b.number.unwrap().cmp(a.number.unwrap()));
|
||||
|
||||
setState({ byAuthor, lastBlockAuthor, lastBlockNumber, lastHeader, lastHeaders });
|
||||
setState({ byAuthor, lastBlockAuthors: lastBlockAuthors.slice(), lastBlockNumber, lastHeader, lastHeaders });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user