diff --git a/packages/page-parachains/src/Overview/Parathread.tsx b/packages/page-parachains/src/Overview/Parathread.tsx deleted file mode 100644 index eee19d46e9..0000000000 --- a/packages/page-parachains/src/Overview/Parathread.tsx +++ /dev/null @@ -1,94 +0,0 @@ -// 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, Option, Vec>>]; - -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 { - const { api } = useApi(); - const paraInfo = useCallMulti([ - [api.query.paras.heads, id], - [api.query.paras.paraLifecycles, id], - [api.query.slots?.leases, id] - ], optionsMulti); - - return ( - -

{formatNumber(id)}

- - {paraInfo.headHex} - - - - - - {currentPeriod && - paraInfo.leases.map(({ period }) => formatNumber(currentPeriod.addn(period))).join(', ') - } - - - ); -} - -export default React.memo(Parachain); diff --git a/packages/page-parachains/src/Overview/Parathreads.tsx b/packages/page-parachains/src/Overview/Parathreads.tsx deleted file mode 100644 index 76a5b4e954..0000000000 --- a/packages/page-parachains/src/Overview/Parathreads.tsx +++ /dev/null @@ -1,51 +0,0 @@ -// 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 { - const { t } = useTranslation(); - - const headerRef = useRef([ - [t('waiting'), 'start', 2], - [t('genesis'), 'start'], - [t('lifecycle'), 'start'], - [], - [t('leases'), 'start'] - ]); - - return ( - ('There are no waiting parathreads')} - header={headerRef.current} - > - {ids?.map((id): React.ReactNode => ( - - paraIds.some((p) => p.eq(id)) - )} - /> - ))} -
- ); -} - -export default React.memo(Parathreads); diff --git a/packages/page-parachains/src/Overview/Upcoming.tsx b/packages/page-parachains/src/Overview/Upcoming.tsx index c3bddc4fd2..4cee9bb778 100644 --- a/packages/page-parachains/src/Overview/Upcoming.tsx +++ b/packages/page-parachains/src/Overview/Upcoming.tsx @@ -3,7 +3,7 @@ import type BN from 'bn.js'; import type { Option, Vec } from '@polkadot/types'; -import type { AccountId, BalanceOf, ParaGenesisArgs, ParaId, ParaLifecycle } from '@polkadot/types/interfaces'; +import type { AccountId, BalanceOf, HeadData, ParaGenesisArgs, ParaId, ParaLifecycle } from '@polkadot/types/interfaces'; import type { ITuple } from '@polkadot/types/types'; import type { LeaseInfo, QueuedAction } from './types'; @@ -13,7 +13,6 @@ import { ParaLink } from '@polkadot/react-components'; import { useApi, useCallMulti } from '@polkadot/react-hooks'; import { formatNumber } from '@polkadot/util'; -import { useTranslation } from '../translate'; import { sliceHex } from '../util'; import Lifecycle from './Lifecycle'; @@ -24,18 +23,23 @@ interface Props { } interface MultiState { + headHex: string | null; leases: LeaseInfo[]; lifecycle: ParaLifecycle | null; - upcomingGenesis: ParaGenesisArgs | null; } const optMulti = { defaultValue: { + headHex: null, leases: [], - lifecycle: null, - upcomingGenesis: null + lifecycle: null }, - transform: ([optGenesis, optLifecycle, leases]: [Option, Option, Vec>>]): MultiState => ({ + transform: ([optHead, optGenesis, optLifecycle, leases]: [Option, Option, Option, Vec>>]): MultiState => ({ + headHex: optHead.isSome + ? sliceHex(optHead.unwrap()) + : optGenesis.isSome + ? sliceHex(optGenesis.unwrap().genesisHead) + : null, leases: leases ? leases .map((optLease, period): LeaseInfo | null => { @@ -53,15 +57,14 @@ const optMulti = { }) .filter((item): item is LeaseInfo => !!item) : [], - lifecycle: optLifecycle.unwrapOr(null), - upcomingGenesis: optGenesis.unwrapOr(null) + lifecycle: optLifecycle.unwrapOr(null) }) }; function Upcoming ({ currentPeriod, id, nextAction }: Props): React.ReactElement { - const { t } = useTranslation(); const { api } = useApi(); - const { leases, lifecycle, upcomingGenesis } = useCallMulti([ + const { headHex, leases, lifecycle } = useCallMulti([ + [api.query.paras.heads, id], [api.query.paras.upcomingParasGenesis, id], [api.query.paras.paraLifecycles, id], [api.query.slots?.leases, id] @@ -71,11 +74,7 @@ function Upcoming ({ currentPeriod, id, nextAction }: Props): React.ReactElement

{formatNumber(id)}

- - {upcomingGenesis && ( - sliceHex(upcomingGenesis.genesisHead) - )} - + {headHex} formatNumber(currentPeriod.addn(period))).join(', ') } - - {upcomingGenesis && ( - upcomingGenesis.parachain.isTrue ? t('Yes') : t('No') - )} - ); } diff --git a/packages/page-parachains/src/Overview/Upcomings.tsx b/packages/page-parachains/src/Overview/Upcomings.tsx index a8234cd5e0..7c25e9cc45 100644 --- a/packages/page-parachains/src/Overview/Upcomings.tsx +++ b/packages/page-parachains/src/Overview/Upcomings.tsx @@ -23,11 +23,10 @@ function Upcomings ({ actionsQueue, currentPeriod, ids }: Props): React.ReactEle const headerRef = useRef([ [t('upcoming'), 'start', 2], - [t('genesis'), 'start'], + [t('head'), 'start'], [t('lifecycle'), 'start'], [], - [t('leases'), 'start'], - [t('parachain'), 'start'] + [t('leases'), 'start'] ]); return ( diff --git a/packages/page-parachains/src/Overview/index.tsx b/packages/page-parachains/src/Overview/index.tsx index f32bf22f4f..133444aa06 100644 --- a/packages/page-parachains/src/Overview/index.tsx +++ b/packages/page-parachains/src/Overview/index.tsx @@ -4,18 +4,17 @@ import type { ParaId } from '@polkadot/types/interfaces'; import type { Proposals } from '../types'; -import React, { useEffect, useState } from 'react'; +import React from 'react'; -import { useApi, useCall, useEventTrigger, useIsMountedRef } from '@polkadot/react-hooks'; +import { useApi, useCall } from '@polkadot/react-hooks'; import Actions from './Actions'; import Parachains from './Parachains'; -import Parathreads from './Parathreads'; import Summary from './Summary'; import Upcomings from './Upcomings'; import useActionsQueue from './useActionsQueue'; import useLeasePeriod from './useLeasePeriod'; -import useParathreads from './useParathreads'; +import useUpcomingIds from './useUpcomingIds'; interface Props { className?: string; @@ -25,25 +24,9 @@ interface Props { function Overview ({ className, proposals }: Props): React.ReactElement { const { api } = useApi(); const paraIds = useCall(api.query.paras?.parachains); - const mountedRef = useIsMountedRef(); const actionsQueue = useActionsQueue(); const leasePeriod = useLeasePeriod(); - const threadIds = useParathreads(); - const trigger = useEventTrigger([api.events.session.NewSession, api.events.registrar?.Registered]); - const [upcomingIds, setUpcomingIds] = useState([]); - - useEffect((): void => { - trigger && - api.query.paras?.upcomingParasGenesis - ?.keys<[ParaId]>() - .then((keys): void => { - mountedRef.current && - setUpcomingIds( - keys.map(({ args: [paraId] }) => paraId) - ); - }) - .catch(console.error); - }, [api, mountedRef, trigger]); + const upcomingIds = useUpcomingIds(); return (
@@ -61,11 +44,6 @@ function Overview ({ className, proposals }: Props): React.ReactElement { ids={paraIds} scheduled={proposals?.scheduled} /> - (); useEffect((): void => { @@ -22,7 +22,12 @@ export default function useParathreads (): ParaId[] | undefined { .map(([{ args: [paraId] }, optValue]): ParaId | null => { const value = optValue.unwrap(); - return (value && (value.isParathread || value.isUpgradingToParachain || value.isOutgoingParathread)) + return value && ( + value.isParathread || + value.isUpgradingToParachain || + value.isOutgoingParathread || + value.isOnboarding + ) ? paraId : null; })