Show scheduled icon on parachains (#4431)

* Show scheduled icon on parachains

* Add column
This commit is contained in:
Jaco Greeff 2021-01-16 11:48:47 +01:00 committed by GitHub
parent f56e42543d
commit 7be76a9835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 7 deletions

View File

@ -8,6 +8,7 @@ import type { Codec } from '@polkadot/types/types';
import BN from 'bn.js';
import React, { useMemo } from 'react';
import { Badge } from '@polkadot/react-components';
import { useApi, useCall, useCallMulti, useParaApi } from '@polkadot/react-hooks';
import { BlockToTime, FormatBalance } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';
@ -18,6 +19,7 @@ interface Props {
bestNumber?: BN;
className?: string;
id: ParaId;
isScheduled?: boolean;
lastInclusion?: [string, string];
}
@ -60,7 +62,7 @@ const transformMulti = {
})
};
function Parachain ({ bestNumber, className = '', id, lastInclusion }: Props): React.ReactElement<Props> {
function Parachain ({ bestNumber, className = '', id, isScheduled, lastInclusion }: Props): React.ReactElement<Props> {
const { api } = useApi();
const { api: paraApi, endpoints } = useParaApi(id);
const paraBest = useCall<BlockNumber>(paraApi?.derive.chain.bestNumber);
@ -95,7 +97,13 @@ function Parachain ({ bestNumber, className = '', id, lastInclusion }: Props): R
return (
<tr className={className}>
<td className='number'><h1>{formatNumber(id)}</h1></td>
<td className='together'>{chainLink}</td>
<td className='badge'>{isScheduled && (
<Badge
color='green'
icon='clock'
/>
)}</td>
<td className='badge together'>{chainLink}</td>
<td className='all start together hash'>{paraInfo.headHex}</td>
<td className='number'>{blockDelay && <BlockToTime blocks={blockDelay} />}</td>
<td className='number'>

View File

@ -3,9 +3,10 @@
import type { SignedBlockExtended } from '@polkadot/api-derive/type';
import type { CandidateReceipt, ParaId } from '@polkadot/types/interfaces';
import type { ScheduledProposals } from '../types';
import BN from 'bn.js';
import React, { useEffect, useRef, useState } from 'react';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { Table } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
@ -15,15 +16,25 @@ import Parachain from './Parachain';
interface Props {
ids?: ParaId[];
scheduled?: ScheduledProposals[];
}
function ParachainList ({ ids }: Props): React.ReactElement<Props> {
function ParachainList ({ ids, scheduled }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api } = useApi();
const bestNumber = useCall<BN>(api.derive.chain.bestNumber);
const lastBlock = useCall<SignedBlockExtended>(api.derive.chain.subscribeNewBlocks);
const [lastIncluded, setLastIncluded] = useState<Record<string, [string, string]>>({});
const scheduledIds = useMemo(
() => scheduled
? scheduled.reduce((all: Record<string, boolean>, { scheduledIds }: ScheduledProposals): Record<string, boolean> => {
return scheduledIds.reduce((all: Record<string, boolean>, id) => ({ ...all, [id.toString()]: true }), all);
}, {})
: {},
[scheduled]
);
useEffect((): void => {
lastBlock && setLastIncluded((prev) => {
const updated: Record<string, [string, string]> = {};
@ -55,7 +66,7 @@ function ParachainList ({ ids }: Props): React.ReactElement<Props> {
}, [api, lastBlock]);
const headerRef = useRef([
[t('parachains'), 'start', 2],
[t('parachains'), 'start', 3],
[t('heads'), 'start'],
[t('relay parent'), undefined, 2],
[t('chain best'), 'media--900'],
@ -73,6 +84,7 @@ function ParachainList ({ ids }: Props): React.ReactElement<Props> {
<Parachain
bestNumber={bestNumber}
id={id}
isScheduled={scheduledIds[id.toString()]}
key={id.toString()}
lastInclusion={lastIncluded[id.toString()]}
/>

View File

@ -33,7 +33,10 @@ function Overview ({ className, proposals }: Props): React.ReactElement<Props> {
<Actions />
{api.query.paras && (
<>
<Parachains ids={paraIds} />
<Parachains
ids={paraIds}
scheduled={proposals?.scheduled}
/>
<Upcoming ids={upcomingIds} />
</>
)}

View File

@ -116,7 +116,7 @@ function Proposal ({ approvedIds, id, scheduled }: Props): React.ReactElement<Pr
)
}
<td className='button'>
{!proposal.isApproved && (
{!(proposal.isApproved || proposal.isScheduled) && (
<>
<TxButton
accountId={sudoKey}