-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display next action countdown (#4849)
* Display next action countdown * Show parathreads
- Loading branch information
Showing
33 changed files
with
378 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.