diff --git a/packages/page-parachains/src/Crowdloan/Fund.tsx b/packages/page-parachains/src/Crowdloan/Fund.tsx index 6b507f03a0..0e3137eeba 100644 --- a/packages/page-parachains/src/Crowdloan/Fund.tsx +++ b/packages/page-parachains/src/Crowdloan/Fund.tsx @@ -48,7 +48,7 @@ function Fund ({ bestNumber, className, isOngoing, leasePeriod, value: { childKe const { api } = useApi(); const { allAccounts, isAccount } = useAccounts(); const [{ myAccounts, uniqueKeys }, setContributors] = useState(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] diff --git a/packages/page-parachains/src/Overview/Parachain.tsx b/packages/page-parachains/src/Overview/Parachain.tsx index e5f6c39b13..6de5e66b24 100644 --- a/packages/page-parachains/src/Overview/Parachain.tsx +++ b/packages/page-parachains/src/Overview/Parachain.tsx @@ -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, Option, Option, Vec, Vec, Vec, Vec, Option, Option, Option]; +type QueryResult = [Option, Option, Option, Vec, Vec, Vec, Vec, Option, Option, Option, Option>[]]; 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 { +function Parachain ({ bestNumber, channelDst, channelSrc, className = '', id, lastBacked, lastInclusion, lastTimeout, leasePeriod, nextAction, sessionValidators, validators }: Props): React.ReactElement { 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([]); @@ -159,7 +168,7 @@ function Parachain ({ bestNumber, channelDst, channelSrc, className = '', id, la

{formatNumber(id)}

- + {validators && validators.length !== 0 && ( {formatNumber(paraInfo.qHrmpE)} ({formatNumber(channelCounts[1])}) + + + ); } diff --git a/packages/page-parachains/src/Overview/Parachains.tsx b/packages/page-parachains/src/Overview/Parachains.tsx index f89e395823..01ec24ebe1 100644 --- a/packages/page-parachains/src/Overview/Parachains.tsx +++ b/packages/page-parachains/src/Overview/Parachains.tsx @@ -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 { +function Parachains ({ actionsQueue, ids, leasePeriod, scheduled }: Props): React.ReactElement { 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]} diff --git a/packages/page-parachains/src/Overview/Periods.tsx b/packages/page-parachains/src/Overview/Periods.tsx new file mode 100644 index 0000000000..dc13493780 --- /dev/null +++ b/packages/page-parachains/src/Overview/Periods.tsx @@ -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 { + 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 ( +
+
{mapped}
+ {periods && ( + + )} +
+ ); +} + +export default React.memo(Periods); diff --git a/packages/page-parachains/src/Overview/Upcoming.tsx b/packages/page-parachains/src/Overview/Upcoming.tsx index 2adb6ea445..0097ed06e8 100644 --- a/packages/page-parachains/src/Overview/Upcoming.tsx +++ b/packages/page-parachains/src/Overview/Upcoming.tsx @@ -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

leasePeriod?.currentPeriod && leases && + leases.map(({ period }) => period), + [leasePeriod?.currentPeriod, leases] + ); + return (

{formatNumber(id)}

@@ -92,16 +98,14 @@ function Upcoming ({ id, leasePeriod, nextAction }: Props): React.ReactElement

- {leasePeriod && leases && ( + {leasePeriod && leases && periods && ( leases.length ? ( - <> -

{leases.map(({ period }) => formatNumber(leasePeriod.currentPeriod.addn(period))).join(', ')}
- - + ) : t('None') )} diff --git a/packages/page-parachains/src/Overview/index.tsx b/packages/page-parachains/src/Overview/index.tsx index ce4fbe2c32..981da820a8 100644 --- a/packages/page-parachains/src/Overview/index.tsx +++ b/packages/page-parachains/src/Overview/index.tsx @@ -41,6 +41,7 @@ function Overview ({ className, leasePeriod, proposals }: Props): React.ReactEle