diff --git a/packages/page-bounties/src/DueBlocks.tsx b/packages/page-bounties/src/DueBlocks.tsx index a46162a9f7..c6ab6ad902 100644 --- a/packages/page-bounties/src/DueBlocks.tsx +++ b/packages/page-bounties/src/DueBlocks.tsx @@ -18,7 +18,7 @@ function DueBlocks ({ dueBlocks, endBlock, label }: Props): React.ReactElement

{dueBlocks.gtn(0) && ( <> - +  ({label}) #{formatNumber(endBlock)} diff --git a/packages/page-contracts/src/Contracts/Contract.tsx b/packages/page-contracts/src/Contracts/Contract.tsx index 886536faff..b7afe01294 100644 --- a/packages/page-contracts/src/Contracts/Contract.tsx +++ b/packages/page-contracts/src/Contracts/Contract.tsx @@ -126,7 +126,7 @@ function Contract ({ className, contract, index, links, onCall }: Props): React. evictAt ? ( <> - + #{formatNumber(evictAt)} ) diff --git a/packages/page-council/src/Motions/Motion.tsx b/packages/page-council/src/Motions/Motion.tsx index 94485cc54a..fe9bc53060 100644 --- a/packages/page-council/src/Motions/Motion.tsx +++ b/packages/page-council/src/Motions/Motion.tsx @@ -81,7 +81,7 @@ function Motion ({ className = '', isMember, members, motion: { hash, proposal, {remainingBlocks && end && ( <> - + #{formatNumber(end)} )} diff --git a/packages/page-democracy/src/Execute/DispatchEntry.tsx b/packages/page-democracy/src/Execute/DispatchEntry.tsx index 0e19a01884..b3976beda0 100644 --- a/packages/page-democracy/src/Execute/DispatchEntry.tsx +++ b/packages/page-democracy/src/Execute/DispatchEntry.tsx @@ -30,7 +30,7 @@ function DispatchEntry ({ value: { at, image, imageHash, index } }: Props): Reac {bestNumber && ( <> - + #{formatNumber(at)} )} diff --git a/packages/page-democracy/src/Execute/Scheduled.tsx b/packages/page-democracy/src/Execute/Scheduled.tsx index e5a773c89c..15e17b98da 100644 --- a/packages/page-democracy/src/Execute/Scheduled.tsx +++ b/packages/page-democracy/src/Execute/Scheduled.tsx @@ -33,7 +33,7 @@ function Scheduled ({ className = '', value: { blockNumber, call, maybeId, maybe {bestNumber && ( <> - + #{formatNumber(blockNumber)} )} diff --git a/packages/page-democracy/src/Overview/Referendum.tsx b/packages/page-democracy/src/Overview/Referendum.tsx index e4b66e9f72..c2942303b2 100644 --- a/packages/page-democracy/src/Overview/Referendum.tsx +++ b/packages/page-democracy/src/Overview/Referendum.tsx @@ -92,11 +92,11 @@ function Referendum ({ className = '', value: { allAye, allNay, image, imageHash proposal={image?.proposal} /> - + {t('{{blocks}} blocks', { replace: { blocks: formatNumber(remainBlock) } })} - + #{formatNumber(enactBlock)} diff --git a/packages/page-explorer/src/Summary.tsx b/packages/page-explorer/src/Summary.tsx index 3387dc9137..8096c52075 100644 --- a/packages/page-explorer/src/Summary.tsx +++ b/packages/page-explorer/src/Summary.tsx @@ -25,7 +25,7 @@ function Summary (): React.ReactElement { className='media--800' label={t('target')} > - + {api.query.balances && ( {blocksLeft && ( - + )} #{formatNumber(end)} diff --git a/packages/page-parachains/src/Overview/Lifecycle.tsx b/packages/page-parachains/src/Overview/Lifecycle.tsx new file mode 100644 index 0000000000..50710f3121 --- /dev/null +++ b/packages/page-parachains/src/Overview/Lifecycle.tsx @@ -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 | null { + return lifecycle && ( + <> + {lifecycle.toString()} + {nextAction && ( + + )} + + ); +} + +export default React.memo(Lifecycle); diff --git a/packages/page-parachains/src/Overview/Parachain.tsx b/packages/page-parachains/src/Overview/Parachain.tsx index aa35268429..c66a62e349 100644 --- a/packages/page-parachains/src/Overview/Parachain.tsx +++ b/packages/page-parachains/src/Overview/Parachain.tsx @@ -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'; @@ -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; @@ -23,6 +25,7 @@ interface Props { isScheduled?: boolean; lastBacked?: [string, string, BN]; lastInclusion?: [string, string, BN]; + nextAction?: QueuedAction; validators?: AccountId[]; } @@ -68,7 +71,7 @@ const optionsMulti = { }) }; -function Parachain ({ bestNumber, className = '', id, isScheduled, lastBacked, lastInclusion, validators }: Props): React.ReactElement { +function Parachain ({ bestNumber, className = '', id, isScheduled, lastBacked, lastInclusion, nextAction, validators }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const { api: paraApi } = useParaApi(id); @@ -125,7 +128,10 @@ function Parachain ({ bestNumber, className = '', id, isScheduled, lastBacked, l {paraInfo.headHex} - {paraInfo.lifecycle && paraInfo.lifecycle.toString()} + {blockDelay && } @@ -144,7 +150,7 @@ function Parachain ({ bestNumber, className = '', id, isScheduled, lastBacked, l {paraInfo.updateAt && bestNumber && ( <> - + #{formatNumber(paraInfo.updateAt)} )} diff --git a/packages/page-parachains/src/Overview/ParachainList.tsx b/packages/page-parachains/src/Overview/Parachains.tsx similarity index 93% rename from packages/page-parachains/src/Overview/ParachainList.tsx rename to packages/page-parachains/src/Overview/Parachains.tsx index 9362dc9ad7..961f788152 100644 --- a/packages/page-parachains/src/Overview/ParachainList.tsx +++ b/packages/page-parachains/src/Overview/Parachains.tsx @@ -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'; @@ -15,6 +16,7 @@ import { useTranslation } from '../translate'; import Parachain from './Parachain'; interface Props { + actionsQueue: QueuedAction[]; ids?: ParaId[]; scheduled?: ScheduledProposals[]; } @@ -42,7 +44,7 @@ function includeEntry (map: EventMap, event: Event, blockHash: string, blockNumb } } -function ParachainList ({ ids, scheduled }: Props): React.ReactElement { +function Parachains ({ actionsQueue, ids, scheduled }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const bestNumber = useBestNumber(); @@ -131,6 +133,9 @@ function ParachainList ({ ids, scheduled }: Props): React.ReactElement { key={id.toString()} lastBacked={lastBacked[id.toString()]} lastInclusion={lastIncluded[id.toString()]} + nextAction={actionsQueue.find(({ paraIds }) => + paraIds.some((p) => p.eq(id)) + )} validators={validatorMap[index]} /> ))} @@ -138,4 +143,4 @@ function ParachainList ({ ids, scheduled }: Props): React.ReactElement { ); } -export default React.memo(ParachainList); +export default React.memo(Parachains); diff --git a/packages/page-parachains/src/Overview/Parathread.tsx b/packages/page-parachains/src/Overview/Parathread.tsx new file mode 100644 index 0000000000..eee19d46e9 --- /dev/null +++ b/packages/page-parachains/src/Overview/Parathread.tsx @@ -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, 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 new file mode 100644 index 0000000000..76a5b4e954 --- /dev/null +++ b/packages/page-parachains/src/Overview/Parathreads.tsx @@ -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 { + 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 4beda7a5f5..c3bddc4fd2 100644 --- a/packages/page-parachains/src/Overview/Upcoming.tsx +++ b/packages/page-parachains/src/Overview/Upcoming.tsx @@ -5,6 +5,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 { ITuple } from '@polkadot/types/types'; +import type { LeaseInfo, QueuedAction } from './types'; import React from 'react'; @@ -14,16 +15,12 @@ import { formatNumber } from '@polkadot/util'; import { useTranslation } from '../translate'; import { sliceHex } from '../util'; +import Lifecycle from './Lifecycle'; interface Props { currentPeriod: BN | null; id: ParaId; -} - -interface LeaseInfo { - accountId: AccountId; - balance: BalanceOf; - period: number; + nextAction?: QueuedAction; } interface MultiState { @@ -61,7 +58,7 @@ const optMulti = { }) }; -function Upcoming ({ currentPeriod, id }: Props): React.ReactElement { +function Upcoming ({ currentPeriod, id, nextAction }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const { leases, lifecycle, upcomingGenesis } = useCallMulti([ @@ -71,7 +68,7 @@ function Upcoming ({ currentPeriod, id }: Props): React.ReactElement { ], optMulti); return ( - +

{formatNumber(id)}

@@ -80,7 +77,10 @@ function Upcoming ({ currentPeriod, id }: Props): React.ReactElement { )} - {lifecycle && lifecycle.toString()} + diff --git a/packages/page-parachains/src/Overview/UpcomingList.tsx b/packages/page-parachains/src/Overview/Upcomings.tsx similarity index 75% rename from packages/page-parachains/src/Overview/UpcomingList.tsx rename to packages/page-parachains/src/Overview/Upcomings.tsx index f84607001e..a8234cd5e0 100644 --- a/packages/page-parachains/src/Overview/UpcomingList.tsx +++ b/packages/page-parachains/src/Overview/Upcomings.tsx @@ -3,6 +3,7 @@ import type BN from 'bn.js'; import type { ParaId } from '@polkadot/types/interfaces'; +import type { QueuedAction } from './types'; import React, { useRef } from 'react'; @@ -12,11 +13,12 @@ import { useTranslation } from '../translate'; import Upcoming from './Upcoming'; interface Props { + actionsQueue: QueuedAction[]; currentPeriod: BN | null; ids?: ParaId[]; } -function UpcomingList ({ currentPeriod, ids }: Props): React.ReactElement { +function Upcomings ({ actionsQueue, currentPeriod, ids }: Props): React.ReactElement { const { t } = useTranslation(); const headerRef = useRef([ @@ -38,10 +40,13 @@ function UpcomingList ({ currentPeriod, ids }: Props): React.ReactElement currentPeriod={currentPeriod} id={id} key={id.toString()} + nextAction={actionsQueue.find(({ paraIds }) => + paraIds.some((p) => p.eq(id)) + )} /> ))} ); } -export default React.memo(UpcomingList); +export default React.memo(Upcomings); diff --git a/packages/page-parachains/src/Overview/index.tsx b/packages/page-parachains/src/Overview/index.tsx index 2d9cfe707c..f32bf22f4f 100644 --- a/packages/page-parachains/src/Overview/index.tsx +++ b/packages/page-parachains/src/Overview/index.tsx @@ -9,10 +9,13 @@ import React, { useEffect, useState } from 'react'; import { useApi, useCall, useEventTrigger, useIsMountedRef } from '@polkadot/react-hooks'; import Actions from './Actions'; -import Parachains from './ParachainList'; +import Parachains from './Parachains'; +import Parathreads from './Parathreads'; import Summary from './Summary'; -import Upcoming from './UpcomingList'; +import Upcomings from './Upcomings'; +import useActionsQueue from './useActionsQueue'; import useLeasePeriod from './useLeasePeriod'; +import useParathreads from './useParathreads'; interface Props { className?: string; @@ -23,22 +26,24 @@ 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 sessionTrigger = useEventTrigger([api.events.session.NewSession, api.events.registrar?.Registered]); + const threadIds = useParathreads(); + const trigger = useEventTrigger([api.events.session.NewSession, api.events.registrar?.Registered]); const [upcomingIds, setUpcomingIds] = useState([]); useEffect((): void => { - sessionTrigger && + trigger && api.query.paras?.upcomingParasGenesis ?.keys<[ParaId]>() .then((keys): void => { mountedRef.current && setUpcomingIds( - keys.map(({ args: [paraId] }) => paraId) + keys.map(({ args: [paraId] }) => paraId) ); }) .catch(console.error); - }, [api, mountedRef, sessionTrigger]); + }, [api, mountedRef, trigger]); return (
@@ -52,10 +57,17 @@ function Overview ({ className, proposals }: Props): React.ReactElement { {api.query.paras && ( <> - + diff --git a/packages/page-parachains/src/Overview/types.ts b/packages/page-parachains/src/Overview/types.ts index 64b1b7fd58..b44376ea5d 100644 --- a/packages/page-parachains/src/Overview/types.ts +++ b/packages/page-parachains/src/Overview/types.ts @@ -2,9 +2,21 @@ // SPDX-License-Identifier: Apache-2.0 import type BN from 'bn.js'; +import type { AccountId, BalanceOf, ParaId } from '@polkadot/types/interfaces'; + +export interface LeaseInfo { + accountId: AccountId; + balance: BalanceOf; + period: number; +} export interface LeasePeriod { currentPeriod: BN; length: BN; remainder: BN; } + +export interface QueuedAction { + paraIds: ParaId[]; + sessionIndex: BN; +} diff --git a/packages/page-parachains/src/Overview/useActionsQueue.ts b/packages/page-parachains/src/Overview/useActionsQueue.ts new file mode 100644 index 0000000000..131196f4f6 --- /dev/null +++ b/packages/page-parachains/src/Overview/useActionsQueue.ts @@ -0,0 +1,33 @@ +// Copyright 2017-2021 @polkadot/app-parachains authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { ParaId, SessionIndex } from '@polkadot/types/interfaces'; +import type { QueuedAction } from './types'; + +import { useMemo } from 'react'; + +import { useApi, useCall, useCallMulti } from '@polkadot/react-hooks'; +import { BN_FIVE, BN_FOUR, BN_ONE, BN_THREE, BN_TWO } from '@polkadot/util'; + +const INC = [BN_ONE, BN_TWO, BN_THREE, BN_FOUR, BN_FIVE]; + +export default function useActionsQueue (): QueuedAction[] { + const { api } = useApi(); + const currentIndex = useCall(api.query.session.currentIndex); + const nextActions = useCallMulti( + currentIndex + ? INC.map((inc) => [api.query.paras.actionsQueue, currentIndex.add(inc)]) + : [] + ); + + return useMemo( + (): QueuedAction[] => + currentIndex && nextActions + ? nextActions.filter((paraIds) => paraIds.length).map((paraIds, index) => ({ + paraIds, + sessionIndex: currentIndex.add(INC[index]) + })) + : [], + [currentIndex, nextActions] + ); +} diff --git a/packages/page-parachains/src/Overview/useParathreads.ts b/packages/page-parachains/src/Overview/useParathreads.ts new file mode 100644 index 0000000000..3b74e34746 --- /dev/null +++ b/packages/page-parachains/src/Overview/useParathreads.ts @@ -0,0 +1,36 @@ +// Copyright 2017-2021 @polkadot/app-parachains authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { Option } from '@polkadot/types'; +import type { ParaId, ParaLifecycle } from '@polkadot/types/interfaces'; + +import { useEffect, useState } from 'react'; + +import { useApi, useEventTrigger } from '@polkadot/react-hooks'; + +export default function useParathreads (): ParaId[] | undefined { + const { api } = useApi(); + const trigger = useEventTrigger([api.events.session.NewSession]); + const [result, setResult] = useState(); + + useEffect((): void => { + trigger && + api.query.paras.paraLifecycles + .entries, [ParaId]>() + .then((entries) => setResult(() => + entries + .map(([{ args: [paraId] }, optValue]): ParaId | null => { + const value = optValue.unwrap(); + + return (value && (value.isParathread || value.isUpgradingToParachain || value.isOutgoingParathread)) + ? paraId + : null; + }) + .filter((paraId): paraId is ParaId => !!paraId) + .sort((a, b) => a.cmp(b)) + )) + .catch(console.error); + }, [api, trigger]); + + return result; +} diff --git a/packages/page-poll/src/index.tsx b/packages/page-poll/src/index.tsx index 9ac789f87d..d73ee02102 100644 --- a/packages/page-poll/src/index.tsx +++ b/packages/page-poll/src/index.tsx @@ -114,7 +114,7 @@ function PollApp ({ basePath, className }: Props): React.ReactElement { )}
{canVote - ? + ? : t('Completed') }
#{formatNumber(api.consts.poll.end as BlockNumber)}
diff --git a/packages/page-staking/src/Actions/Account/Unbond.tsx b/packages/page-staking/src/Actions/Account/Unbond.tsx index af132a5e33..701669aa0f 100644 --- a/packages/page-staking/src/Actions/Account/Unbond.tsx +++ b/packages/page-staking/src/Actions/Account/Unbond.tsx @@ -73,7 +73,7 @@ function Unbond ({ className = '', controllerId, onClose, stakingLedger, stashId help={t('The bonding duration for any staked funds. After this period needs to be withdrawn.')} label={t('on-chain bonding duration')} > - + )} diff --git a/packages/page-staking/src/Actions/partials/Bond.tsx b/packages/page-staking/src/Actions/partials/Bond.tsx index a040aee561..2ba8aa8193 100644 --- a/packages/page-staking/src/Actions/partials/Bond.tsx +++ b/packages/page-staking/src/Actions/partials/Bond.tsx @@ -152,7 +152,7 @@ function Bond ({ className = '', isNominating, minNomination, onChange }: Props) help={t('The bonding duration for any staked funds. Needs to be unlocked and withdrawn to become available.')} label={t('on-chain bonding duration')} > - + )} diff --git a/packages/page-staking/src/Payouts/Stash.tsx b/packages/page-staking/src/Payouts/Stash.tsx index 4a0ef02504..0eec93f75e 100644 --- a/packages/page-staking/src/Payouts/Stash.tsx +++ b/packages/page-staking/src/Payouts/Stash.tsx @@ -86,7 +86,7 @@ function Stash ({ className = '', isDisabled, payout: { available, rewards, stas {eraStr} - {eraBlocks && } + {eraBlocks && } {eraStr} - {eraBlocks && } + {eraBlocks && } {remainingBlocks && end && ( <> - + #{formatNumber(end)} )} diff --git a/packages/page-treasury/src/Tips/Tip.tsx b/packages/page-treasury/src/Tips/Tip.tsx index 673ef8dd45..456c95f720 100644 --- a/packages/page-treasury/src/Tips/Tip.tsx +++ b/packages/page-treasury/src/Tips/Tip.tsx @@ -142,7 +142,7 @@ function Tip ({ bestNumber, className = '', defaultId, hash, isMember, members, {closesAt ? (bestNumber && closesAt.gt(bestNumber)) && (
- + #{formatNumber(closesAt)}
) diff --git a/packages/react-components/src/AddressInfo.tsx b/packages/react-components/src/AddressInfo.tsx index 4f0bf236de..30aff9f6c5 100644 --- a/packages/react-components/src/AddressInfo.tsx +++ b/packages/react-components/src/AddressInfo.tsx @@ -263,7 +263,7 @@ function createBalanceItems (formatIndex: number, lookup: Record {bestNumber.lt((balancesAll as DeriveBalancesAll).vestingEndBlock) && ( <>
- +
{t('until block')} {formatNumber((balancesAll as DeriveBalancesAll).vestingEndBlock)}
diff --git a/packages/react-components/src/CardSummary.tsx b/packages/react-components/src/CardSummary.tsx index 245d2a7330..24533d4cf0 100644 --- a/packages/react-components/src/CardSummary.tsx +++ b/packages/react-components/src/CardSummary.tsx @@ -66,7 +66,7 @@ function CardSummary ({ children, className = '', help, label, progress }: Props progress && !progress.hideValue && ( <> {isTimed && !children && ( - + )}
{!left || isUndefined(progress.total) @@ -79,8 +79,8 @@ function CardSummary ({ children, className = '', help, label, progress }: Props }` : ( ) } diff --git a/packages/react-components/src/DemocracyLocks.tsx b/packages/react-components/src/DemocracyLocks.tsx index 2e6c5fa4cc..323753d230 100644 --- a/packages/react-components/src/DemocracyLocks.tsx +++ b/packages/react-components/src/DemocracyLocks.tsx @@ -59,8 +59,8 @@ function groupLocks (t: TFunction, bestNumber: BN, locks: DeriveDemocracyLock[] {isCountdown ? ( ('{{blocks}} blocks', { replace: { blocks: formatNumber(blocks) } })}, `} + value={blocks} /> ) : isFinished diff --git a/packages/react-components/src/StakingUnbonding.tsx b/packages/react-components/src/StakingUnbonding.tsx index c4edd944d0..34a30bedc7 100644 --- a/packages/react-components/src/StakingUnbonding.tsx +++ b/packages/react-components/src/StakingUnbonding.tsx @@ -75,8 +75,8 @@ function StakingUnbonding ({ className = '', stakingInfo }: Props): React.ReactE {api.consts.babe?.epochDuration ? ( ('{{blocks}} blocks', { replace: { blocks: formatNumber(blocks) } })}, `} + value={blocks} /> ) : t('{{eras}} eras remaining', { replace: { eras: formatNumber(eras) } }) diff --git a/packages/react-query/src/BlockToTime.tsx b/packages/react-query/src/BlockToTime.tsx index c23f1fa8b5..ea9cca0b09 100644 --- a/packages/react-query/src/BlockToTime.tsx +++ b/packages/react-query/src/BlockToTime.tsx @@ -11,17 +11,17 @@ import { useBlockTime } from '@polkadot/react-hooks'; interface Props { api?: ApiPromise; - blocks?: BN; children?: React.ReactNode; className?: string; isInline?: boolean; label?: React.ReactNode; + value?: BN; } -function BlockToTime ({ api, blocks, children, className = '', isInline, label }: Props): React.ReactElement | null { - const [, text] = useBlockTime(blocks, api); +function BlockToTime ({ api, children, className = '', isInline, label, value }: Props): React.ReactElement | null { + const [, text] = useBlockTime(value, api); - if (!blocks || blocks.isZero()) { + if (!value || value.isZero()) { return null; } diff --git a/packages/react-query/src/SessionToTime.tsx b/packages/react-query/src/SessionToTime.tsx new file mode 100644 index 0000000000..1b9890e8e0 --- /dev/null +++ b/packages/react-query/src/SessionToTime.tsx @@ -0,0 +1,48 @@ +// Copyright 2017-2021 @polkadot/react-query authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { DeriveSessionProgress } from '@polkadot/api-derive/types'; + +import BN from 'bn.js'; +import React, { useMemo } from 'react'; + +import { useApi, useCall } from '@polkadot/react-hooks'; +import { BN_ZERO } from '@polkadot/util'; + +import BlockToTime from './BlockToTime'; + +interface Props { + children?: React.ReactNode; + className?: string; + isInline?: boolean; + label?: React.ReactNode; + value?: BN; +} + +function SessionToTime ({ children, className, isInline, label, value }: Props): React.ReactElement | null { + const { api } = useApi(); + const sessionInfo = useCall(api.derive.session.progress); + + const blocks = useMemo( + () => sessionInfo && value && sessionInfo.currentIndex.lt(value) + ? value + .sub(sessionInfo.currentIndex) + .imul(sessionInfo.sessionLength) + .isub(sessionInfo.sessionProgress) + : BN_ZERO, + [sessionInfo, value] + ); + + return ( + + {children} + + ); +} + +export default React.memo(SessionToTime); diff --git a/packages/react-query/src/index.ts b/packages/react-query/src/index.ts index 8d4c624c82..b6e1e082bf 100644 --- a/packages/react-query/src/index.ts +++ b/packages/react-query/src/index.ts @@ -18,5 +18,6 @@ export { default as LockedVote } from './LockedVote'; export { default as NodeName } from './NodeName'; export { default as NodeVersion } from './NodeVersion'; export { default as Nonce } from './Nonce'; +export { default as SessionToTime } from './SessionToTime'; export { default as TimeNow } from './TimeNow'; export { default as TotalIssuance } from './TotalIssuance';