Display formatted leases (#4993)
This commit is contained in:
parent
24b4578e33
commit
51d75a7663
@ -48,7 +48,7 @@ function Fund ({ bestNumber, className, isOngoing, leasePeriod, value: { childKe
|
||||
const { api } = useApi();
|
||||
const { allAccounts, isAccount } = useAccounts();
|
||||
const [{ myAccounts, uniqueKeys }, setContributors] = useState<Contributions>(NO_CONTRIB);
|
||||
const trigger = useEventTrigger([api.events.crowdloan.Contributed, api.events.crowdloan.Withdrew], useCallback(
|
||||
const trigger = useEventTrigger([api.events.crowdloan?.Contributed, api.events.crowdloan?.Withdrew], useCallback(
|
||||
({ event: { data: [, fundIndex] } }: EventRecord) =>
|
||||
(fundIndex as ParaId).eq(paraId),
|
||||
[paraId]
|
||||
|
||||
@ -2,8 +2,9 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Option, Vec } from '@polkadot/types';
|
||||
import type { AccountId, BlockNumber, CandidatePendingAvailability, HeadData, Header, HrmpChannel, HrmpChannelId, ParaId, ParaInfo, ParaLifecycle } from '@polkadot/types/interfaces';
|
||||
import type { Codec } from '@polkadot/types/types';
|
||||
import type { AccountId, BalanceOf, BlockNumber, CandidatePendingAvailability, HeadData, Header, HrmpChannel, HrmpChannelId, ParaId, ParaInfo, ParaLifecycle } from '@polkadot/types/interfaces';
|
||||
import type { Codec, ITuple } from '@polkadot/types/types';
|
||||
import type { LeasePeriod } from '../types';
|
||||
import type { EventMapInfo, QueuedAction, ValidatorInfo } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -17,6 +18,7 @@ import { BN_ZERO, formatNumber } from '@polkadot/util';
|
||||
import { useTranslation } from '../translate';
|
||||
import { sliceHex } from '../util';
|
||||
import Lifecycle from './Lifecycle';
|
||||
import Periods from './Periods';
|
||||
|
||||
interface Props {
|
||||
bestNumber?: BN;
|
||||
@ -28,15 +30,17 @@ interface Props {
|
||||
lastBacked?: EventMapInfo;
|
||||
lastInclusion?: EventMapInfo;
|
||||
lastTimeout?: EventMapInfo;
|
||||
leasePeriod?: LeasePeriod;
|
||||
nextAction?: QueuedAction;
|
||||
sessionValidators?: AccountId[] | null;
|
||||
validators?: ValidatorInfo[];
|
||||
}
|
||||
|
||||
type QueryResult = [Option<HeadData>, Option<BlockNumber>, Option<ParaLifecycle>, Vec<Codec>, Vec<Codec>, Vec<Codec>, Vec<Codec>, Option<BlockNumber>, Option<CandidatePendingAvailability>, Option<ParaInfo>];
|
||||
type QueryResult = [Option<HeadData>, Option<BlockNumber>, Option<ParaLifecycle>, Vec<Codec>, Vec<Codec>, Vec<Codec>, Vec<Codec>, Option<BlockNumber>, Option<CandidatePendingAvailability>, Option<ParaInfo>, Option<ITuple<[AccountId, BalanceOf]>>[]];
|
||||
|
||||
interface QueryState {
|
||||
headHex: string | null;
|
||||
leases: number[];
|
||||
lifecycle: ParaLifecycle | null;
|
||||
paraInfo: ParaInfo | null;
|
||||
pendingAvail: CandidatePendingAvailability | null;
|
||||
@ -55,6 +59,7 @@ const transformHeader = {
|
||||
const optionsMulti = {
|
||||
defaultValue: {
|
||||
headHex: null,
|
||||
leases: [],
|
||||
lifecycle: null,
|
||||
paraInfo: null,
|
||||
pendingAvail: null,
|
||||
@ -65,10 +70,13 @@ const optionsMulti = {
|
||||
updateAt: null,
|
||||
watermark: null
|
||||
},
|
||||
transform: ([headData, optUp, optLifecycle, dmp, ump, hrmpE, hrmpI, optWm, optPending, optInfo]: QueryResult): QueryState => ({
|
||||
transform: ([headData, optUp, optLifecycle, dmp, ump, hrmpE, hrmpI, optWm, optPending, optInfo, leases]: QueryResult): QueryState => ({
|
||||
headHex: headData.isSome
|
||||
? sliceHex(headData.unwrap())
|
||||
: null,
|
||||
leases: leases
|
||||
.map((opt, index) => opt.isSome ? index : -1)
|
||||
.filter((period) => period !== -1),
|
||||
lifecycle: optLifecycle.unwrapOr(null),
|
||||
paraInfo: optInfo.unwrapOr(null),
|
||||
pendingAvail: optPending.unwrapOr(null),
|
||||
@ -90,7 +98,7 @@ function renderAddresses (list?: AccountId[]): JSX.Element[] | undefined {
|
||||
));
|
||||
}
|
||||
|
||||
function Parachain ({ bestNumber, channelDst, channelSrc, className = '', id, lastBacked, lastInclusion, lastTimeout, nextAction, sessionValidators, validators }: Props): React.ReactElement<Props> {
|
||||
function Parachain ({ bestNumber, channelDst, channelSrc, className = '', id, lastBacked, lastInclusion, lastTimeout, leasePeriod, nextAction, sessionValidators, validators }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const { api: paraApi } = useParaApi(id);
|
||||
@ -105,7 +113,8 @@ function Parachain ({ bestNumber, channelDst, channelSrc, className = '', id, la
|
||||
[api.query.hrmp.hrmpIngressChannelsIndex, id],
|
||||
[api.query.hrmp.hrmpWatermarks, id],
|
||||
[api.query.inclusion.pendingAvailability, id],
|
||||
[api.query.registrar.paras, id]
|
||||
[api.query.registrar.paras, id],
|
||||
[api.query.slots.leases, id]
|
||||
], optionsMulti);
|
||||
const [nonBacked, setNonBacked] = useState<AccountId[]>([]);
|
||||
|
||||
@ -159,7 +168,7 @@ function Parachain ({ bestNumber, channelDst, channelSrc, className = '', id, la
|
||||
<tr className={className}>
|
||||
<td className='number'><h1>{formatNumber(id)}</h1></td>
|
||||
<td className='badge'><ParaLink id={id} /></td>
|
||||
<td className='number media--1500'>
|
||||
<td className='number media--1400'>
|
||||
{validators && validators.length !== 0 && (
|
||||
<Expander
|
||||
renderChildren={valRender}
|
||||
@ -217,6 +226,12 @@ function Parachain ({ bestNumber, channelDst, channelSrc, className = '', id, la
|
||||
<td className='number media--1300 no-pad-left'>
|
||||
{formatNumber(paraInfo.qHrmpE)} ({formatNumber(channelCounts[1])})
|
||||
</td>
|
||||
<td className='number together media--1500'>
|
||||
<Periods
|
||||
leasePeriod={leasePeriod}
|
||||
periods={paraInfo.leases}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ import type { ApiPromise } from '@polkadot/api';
|
||||
import type { SignedBlockExtended } from '@polkadot/api-derive/types';
|
||||
import type { AccountId, CandidateReceipt, Event, ParaId, ParaValidatorIndex } from '@polkadot/types/interfaces';
|
||||
import type { IEvent } from '@polkadot/types/types';
|
||||
import type { ScheduledProposals } from '../types';
|
||||
import type { LeasePeriod, ScheduledProposals } from '../types';
|
||||
import type { EventMapInfo, QueuedAction, ValidatorInfo } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -21,6 +21,7 @@ import useHrmp from './useHrmp';
|
||||
interface Props {
|
||||
actionsQueue: QueuedAction[];
|
||||
ids?: ParaId[];
|
||||
leasePeriod?: LeasePeriod;
|
||||
scheduled?: ScheduledProposals[];
|
||||
}
|
||||
|
||||
@ -124,7 +125,7 @@ function extractActions (actionsQueue: QueuedAction[], knownIds?: [ParaId, strin
|
||||
: {};
|
||||
}
|
||||
|
||||
function Parachains ({ actionsQueue, ids, scheduled }: Props): React.ReactElement<Props> {
|
||||
function Parachains ({ actionsQueue, ids, leasePeriod, scheduled }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const bestNumber = useBestNumber();
|
||||
@ -139,7 +140,7 @@ function Parachains ({ actionsQueue, ids, scheduled }: Props): React.ReactElemen
|
||||
|
||||
const headerRef = useRef([
|
||||
[t('parachains'), 'start', 2],
|
||||
['', 'media--1500'],
|
||||
['', 'media--1400'],
|
||||
[t('head'), 'start'],
|
||||
[t('lifecycle'), 'start media--1100'],
|
||||
[],
|
||||
@ -147,7 +148,8 @@ function Parachains ({ actionsQueue, ids, scheduled }: Props): React.ReactElemen
|
||||
[t('backed'), 'no-pad-left'],
|
||||
[t('timeout'), 'no-pad-left'],
|
||||
[t('chain best'), 'media--900 no-pad-left'],
|
||||
[t('in/out (msg)'), 'media--1300', 2]
|
||||
[t('in/out (msg)'), 'media--1300', 2],
|
||||
[t('leases'), 'media--1500']
|
||||
]);
|
||||
|
||||
const scheduledIds = useMemo(
|
||||
@ -192,6 +194,7 @@ function Parachains ({ actionsQueue, ids, scheduled }: Props): React.ReactElemen
|
||||
lastBacked={lastBacked[key]}
|
||||
lastInclusion={lastIncluded[key]}
|
||||
lastTimeout={lastTimeout[key]}
|
||||
leasePeriod={leasePeriod}
|
||||
nextAction={nextActions[key]}
|
||||
sessionValidators={validators}
|
||||
validators={validatorMap[index]}
|
||||
|
||||
57
packages/page-parachains/src/Overview/Periods.tsx
Normal file
57
packages/page-parachains/src/Overview/Periods.tsx
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { LeasePeriod } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
import { BN_ONE, formatNumber } from '@polkadot/util';
|
||||
|
||||
import LeaseBlocks from './LeaseBlocks';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
fromFirst?: boolean;
|
||||
leasePeriod?: LeasePeriod;
|
||||
periods: number[];
|
||||
}
|
||||
|
||||
function Periods ({ className, fromFirst, leasePeriod, periods }: Props): React.ReactElement<Props> {
|
||||
const mapped = useMemo(
|
||||
() => leasePeriod?.currentPeriod && periods &&
|
||||
periods
|
||||
.reduce((all: [BN, BN][], period): [BN, BN][] => {
|
||||
const bnp = leasePeriod.currentPeriod.addn(period);
|
||||
|
||||
if (!all.length || all[all.length - 1][1].add(BN_ONE).lt(bnp)) {
|
||||
all.push([bnp, bnp]);
|
||||
} else {
|
||||
all[all.length - 1][1] = bnp;
|
||||
}
|
||||
|
||||
return all;
|
||||
}, [])
|
||||
.map(([a, b]) => `${formatNumber(a)} - ${formatNumber(b)}`)
|
||||
.join(', '),
|
||||
[leasePeriod?.currentPeriod, periods]
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<div>{mapped}</div>
|
||||
{periods && (
|
||||
<LeaseBlocks
|
||||
leasePeriod={leasePeriod}
|
||||
value={
|
||||
fromFirst
|
||||
? periods[0]
|
||||
: periods[periods.length - 1] + 1
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(Periods);
|
||||
@ -7,7 +7,7 @@ import type { ITuple } from '@polkadot/types/types';
|
||||
import type { LeasePeriod } from '../types';
|
||||
import type { LeaseInfo, QueuedAction } from './types';
|
||||
|
||||
import React from 'react';
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
import { AddressSmall, ParaLink } from '@polkadot/react-components';
|
||||
import { useApi, useCallMulti } from '@polkadot/react-hooks';
|
||||
@ -15,8 +15,8 @@ import { formatNumber } from '@polkadot/util';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
import { sliceHex } from '../util';
|
||||
import LeaseBlocks from './LeaseBlocks';
|
||||
import Lifecycle from './Lifecycle';
|
||||
import Periods from './Periods';
|
||||
|
||||
interface Props {
|
||||
id: ParaId;
|
||||
@ -79,6 +79,12 @@ function Upcoming ({ id, leasePeriod, nextAction }: Props): React.ReactElement<P
|
||||
[api.query.slots?.leases, id]
|
||||
], optMulti);
|
||||
|
||||
const periods = useMemo(
|
||||
() => leasePeriod?.currentPeriod && leases &&
|
||||
leases.map(({ period }) => period),
|
||||
[leasePeriod?.currentPeriod, leases]
|
||||
);
|
||||
|
||||
return (
|
||||
<tr>
|
||||
<td className='number'><h1>{formatNumber(id)}</h1></td>
|
||||
@ -92,16 +98,14 @@ function Upcoming ({ id, leasePeriod, nextAction }: Props): React.ReactElement<P
|
||||
/>
|
||||
</td>
|
||||
<td className='all number together'>
|
||||
{leasePeriod && leases && (
|
||||
{leasePeriod && leases && periods && (
|
||||
leases.length
|
||||
? (
|
||||
<>
|
||||
<div>{leases.map(({ period }) => formatNumber(leasePeriod.currentPeriod.addn(period))).join(', ')}</div>
|
||||
<LeaseBlocks
|
||||
leasePeriod={leasePeriod}
|
||||
value={leases[0]?.period}
|
||||
/>
|
||||
</>
|
||||
<Periods
|
||||
fromFirst
|
||||
leasePeriod={leasePeriod}
|
||||
periods={periods}
|
||||
/>
|
||||
)
|
||||
: t('None')
|
||||
)}
|
||||
|
||||
@ -41,6 +41,7 @@ function Overview ({ className, leasePeriod, proposals }: Props): React.ReactEle
|
||||
<Parachains
|
||||
actionsQueue={actionsQueue}
|
||||
ids={paraIds}
|
||||
leasePeriod={leasePeriod}
|
||||
scheduled={proposals?.scheduled}
|
||||
/>
|
||||
<Upcomings
|
||||
|
||||
Loading…
Reference in New Issue
Block a user