Skip to content

Commit

Permalink
Display next action countdown (#4849)
Browse files Browse the repository at this point in the history
* Display next action countdown

* Show parathreads
  • Loading branch information
jacogr authored Mar 14, 2021
1 parent 97d2e65 commit 15c08c6
Show file tree
Hide file tree
Showing 33 changed files with 378 additions and 48 deletions.
2 changes: 1 addition & 1 deletion packages/page-bounties/src/DueBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function DueBlocks ({ dueBlocks, endBlock, label }: Props): React.ReactElement<P
<>
{dueBlocks.gtn(0) && (
<>
<BlockToTime blocks={dueBlocks}>
<BlockToTime value={dueBlocks}>
&nbsp;({label})
</BlockToTime>
#{formatNumber(endBlock)}
Expand Down
2 changes: 1 addition & 1 deletion packages/page-contracts/src/Contracts/Contract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function Contract ({ className, contract, index, links, onCall }: Props): React.
evictAt
? (
<>
<BlockToTime blocks={evictAt.sub(bestNumber)} />
<BlockToTime value={evictAt.sub(bestNumber)} />
#{formatNumber(evictAt)}
</>
)
Expand Down
2 changes: 1 addition & 1 deletion packages/page-council/src/Motions/Motion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function Motion ({ className = '', isMember, members, motion: { hash, proposal,
<td className='number together'>
{remainingBlocks && end && (
<>
<BlockToTime blocks={remainingBlocks} />
<BlockToTime value={remainingBlocks} />
#{formatNumber(end)}
</>
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/page-democracy/src/Execute/DispatchEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function DispatchEntry ({ value: { at, image, imageHash, index } }: Props): Reac
<td className='number together'>
{bestNumber && (
<>
<BlockToTime blocks={at.sub(bestNumber)} />
<BlockToTime value={at.sub(bestNumber)} />
#{formatNumber(at)}
</>
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/page-democracy/src/Execute/Scheduled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Scheduled ({ className = '', value: { blockNumber, call, maybeId, maybe
<td className='number together'>
{bestNumber && (
<>
<BlockToTime blocks={blockNumber.sub(bestNumber)} />
<BlockToTime value={blockNumber.sub(bestNumber)} />
#{formatNumber(blockNumber)}
</>
)}
Expand Down
4 changes: 2 additions & 2 deletions packages/page-democracy/src/Overview/Referendum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ function Referendum ({ className = '', value: { allAye, allNay, image, imageHash
proposal={image?.proposal}
/>
<td className='number together media--1200'>
<BlockToTime blocks={remainBlock} />
<BlockToTime value={remainBlock} />
{t<string>('{{blocks}} blocks', { replace: { blocks: formatNumber(remainBlock) } })}
</td>
<td className='number together media--1400'>
<BlockToTime blocks={enactBlock.sub(bestNumber)} />
<BlockToTime value={enactBlock.sub(bestNumber)} />
#{formatNumber(enactBlock)}
</td>
<td className='number together media--1400'>
Expand Down
2 changes: 1 addition & 1 deletion packages/page-explorer/src/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Summary (): React.ReactElement {
className='media--800'
label={t<string>('target')}
>
<BlockToTime blocks={BN_ONE} />
<BlockToTime value={BN_ONE} />
</CardSummary>
{api.query.balances && (
<CardSummary
Expand Down
2 changes: 1 addition & 1 deletion packages/page-parachains/src/Crowdloan/Fund.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Fund ({ bestNumber, className, isOngoing, value: { info: { cap, deposit
<td className='address'><AddressMini value={depositor} /></td>
<td className='number together'>
{blocksLeft && (
<BlockToTime blocks={blocksLeft} />
<BlockToTime value={blocksLeft} />
)}
#{formatNumber(end)}
</td>
Expand Down
27 changes: 27 additions & 0 deletions packages/page-parachains/src/Overview/Lifecycle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { ParaLifecycle } from '@polkadot/types/interfaces';
import type { QueuedAction } from './types';

import React from 'react';

import { SessionToTime } from '@polkadot/react-query';

interface Props {
lifecycle: ParaLifecycle | null;
nextAction?: QueuedAction;
}

function Lifecycle ({ lifecycle, nextAction }: Props): React.ReactElement<Props> | null {
return lifecycle && (
<>
{lifecycle.toString()}
{nextAction && (
<SessionToTime value={nextAction.sessionIndex} />
)}
</>
);
}

export default React.memo(Lifecycle);
12 changes: 9 additions & 3 deletions packages/page-parachains/src/Overview/Parachain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import type { Option, Vec } from '@polkadot/types';
import type { AccountId, BlockNumber, HeadData, Header, ParaId, ParaLifecycle } from '@polkadot/types/interfaces';
import type { Codec } from '@polkadot/types/types';
import type { QueuedAction } from './types';

import BN from 'bn.js';
import React, { useCallback, useMemo } from 'react';
Expand All @@ -15,6 +16,7 @@ import { formatNumber } from '@polkadot/util';

import { useTranslation } from '../translate';
import { sliceHex } from '../util';
import Lifecycle from './Lifecycle';

interface Props {
bestNumber?: BN;
Expand All @@ -23,6 +25,7 @@ interface Props {
isScheduled?: boolean;
lastBacked?: [string, string, BN];
lastInclusion?: [string, string, BN];
nextAction?: QueuedAction;
validators?: AccountId[];
}

Expand Down Expand Up @@ -68,7 +71,7 @@ const optionsMulti = {
})
};

function Parachain ({ bestNumber, className = '', id, isScheduled, lastBacked, lastInclusion, validators }: Props): React.ReactElement<Props> {
function Parachain ({ bestNumber, className = '', id, isScheduled, lastBacked, lastInclusion, nextAction, validators }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api } = useApi();
const { api: paraApi } = useParaApi(id);
Expand Down Expand Up @@ -125,7 +128,10 @@ function Parachain ({ bestNumber, className = '', id, isScheduled, lastBacked, l
</td>
<td className='start together hash'>{paraInfo.headHex}</td>
<td className='start media--1100'>
{paraInfo.lifecycle && paraInfo.lifecycle.toString()}
<Lifecycle
lifecycle={paraInfo.lifecycle}
nextAction={nextAction}
/>
</td>
<td className='all' />
<td className='number'>{blockDelay && <BlockToTime blocks={blockDelay} />}</td>
Expand All @@ -144,7 +150,7 @@ function Parachain ({ bestNumber, className = '', id, isScheduled, lastBacked, l
<td className='number media--1300'>
{paraInfo.updateAt && bestNumber && (
<>
<BlockToTime blocks={bestNumber.sub(paraInfo.updateAt)} />
<BlockToTime value={bestNumber.sub(paraInfo.updateAt)} />
#{formatNumber(paraInfo.updateAt)}
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import type { SignedBlockExtended } from '@polkadot/api-derive/type';
import type { AccountId, CandidateReceipt, Event, ParaId, ParaValidatorIndex } from '@polkadot/types/interfaces';
import type { ScheduledProposals } from '../types';
import type { QueuedAction } from './types';

import BN from 'bn.js';
import React, { useEffect, useMemo, useRef, useState } from 'react';
Expand All @@ -15,6 +16,7 @@ import { useTranslation } from '../translate';
import Parachain from './Parachain';

interface Props {
actionsQueue: QueuedAction[];
ids?: ParaId[];
scheduled?: ScheduledProposals[];
}
Expand Down Expand Up @@ -42,7 +44,7 @@ function includeEntry (map: EventMap, event: Event, blockHash: string, blockNumb
}
}

function ParachainList ({ ids, scheduled }: Props): React.ReactElement<Props> {
function Parachains ({ actionsQueue, ids, scheduled }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api } = useApi();
const bestNumber = useBestNumber();
Expand Down Expand Up @@ -131,11 +133,14 @@ function ParachainList ({ ids, scheduled }: Props): React.ReactElement<Props> {
key={id.toString()}
lastBacked={lastBacked[id.toString()]}
lastInclusion={lastIncluded[id.toString()]}
nextAction={actionsQueue.find(({ paraIds }) =>
paraIds.some((p) => p.eq(id))
)}
validators={validatorMap[index]}
/>
))}
</Table>
);
}

export default React.memo(ParachainList);
export default React.memo(Parachains);
94 changes: 94 additions & 0 deletions packages/page-parachains/src/Overview/Parathread.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { Option, Vec } from '@polkadot/types';
import type { AccountId, BalanceOf, HeadData, ParaId, ParaLifecycle } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { LeaseInfo, QueuedAction } from './types';

import BN from 'bn.js';
import React from 'react';

import { ParaLink } from '@polkadot/react-components';
import { useApi, useCallMulti } from '@polkadot/react-hooks';
import { formatNumber } from '@polkadot/util';

import { sliceHex } from '../util';
import Lifecycle from './Lifecycle';

interface Props {
className?: string;
currentPeriod: BN | null;
id: ParaId;
nextAction?: QueuedAction;
}

type QueryResult = [Option<HeadData>, Option<ParaLifecycle>, Vec<Option<ITuple<[AccountId, BalanceOf]>>>];

interface QueryState {
headHex: string | null;
leases: LeaseInfo[];
lifecycle: ParaLifecycle | null;
}

const optionsMulti = {
defaultValue: {
headHex: null,
leases: [],
lifecycle: null
},
transform: ([headData, optLifecycle, leases]: QueryResult): QueryState => ({
headHex: headData.isSome
? sliceHex(headData.unwrap())
: null,
leases: leases
? leases
.map((optLease, period): LeaseInfo | null => {
if (optLease.isNone) {
return null;
}

const [accountId, balance] = optLease.unwrap();

return {
accountId,
balance,
period
};
})
.filter((item): item is LeaseInfo => !!item)
: [],
lifecycle: optLifecycle.unwrapOr(null)
})
};

function Parachain ({ className = '', currentPeriod, id, nextAction }: Props): React.ReactElement<Props> {
const { api } = useApi();
const paraInfo = useCallMulti<QueryState>([
[api.query.paras.heads, id],
[api.query.paras.paraLifecycles, id],
[api.query.slots?.leases, id]
], optionsMulti);

return (
<tr className={className}>
<td className='number'><h1>{formatNumber(id)}</h1></td>
<td className='badge together'><ParaLink id={id} /></td>
<td className='start together hash'>{paraInfo.headHex}</td>
<td className='start media--1100'>
<Lifecycle
lifecycle={paraInfo.lifecycle}
nextAction={nextAction}
/>
</td>
<td className='all' />
<td className='start together'>
{currentPeriod &&
paraInfo.leases.map(({ period }) => formatNumber(currentPeriod.addn(period))).join(', ')
}
</td>
</tr>
);
}

export default React.memo(Parachain);
51 changes: 51 additions & 0 deletions packages/page-parachains/src/Overview/Parathreads.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type BN from 'bn.js';
import type { ParaId } from '@polkadot/types/interfaces';
import type { QueuedAction } from './types';

import React, { useRef } from 'react';

import { Table } from '@polkadot/react-components';

import { useTranslation } from '../translate';
import Parathread from './Parathread';

interface Props {
actionsQueue: QueuedAction[];
currentPeriod: BN | null;
ids?: ParaId[];
}

function Parathreads ({ actionsQueue, currentPeriod, ids }: Props): React.ReactElement<Props> {
const { t } = useTranslation();

const headerRef = useRef([
[t('waiting'), 'start', 2],
[t('genesis'), 'start'],
[t('lifecycle'), 'start'],
[],
[t('leases'), 'start']
]);

return (
<Table
empty={ids && t<string>('There are no waiting parathreads')}
header={headerRef.current}
>
{ids?.map((id): React.ReactNode => (
<Parathread
currentPeriod={currentPeriod}
id={id}
key={id.toString()}
nextAction={actionsQueue.find(({ paraIds }) =>
paraIds.some((p) => p.eq(id))
)}
/>
))}
</Table>
);
}

export default React.memo(Parathreads);
Loading

0 comments on commit 15c08c6

Please sign in to comment.