Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relay Chain - Coretime Overview UI Tab #11016

Merged
merged 25 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
18e46a9
exposing coretime wss endpoint to use on relay chain, adjusted hooks …
piggydoughnut Oct 7, 2024
94a4329
adjusting hook calls to new parameters
piggydoughnut Oct 7, 2024
ec64d75
added Tag for coretime types, renamed occupancyType to coretimeType
piggydoughnut Oct 7, 2024
2500205
added cycle progress and cycle end date to summary, fixed the estimat…
piggydoughnut Oct 8, 2024
1913d17
coretime page draft, added hook for gathering all the coretime inform…
piggydoughnut Oct 8, 2024
de1f7f9
Merge branch 'master' into dm-coretime-ui-relay
piggydoughnut Oct 8, 2024
92b5216
lint
piggydoughnut Oct 9, 2024
88e762d
Merge branch 'master' into dm-coretime-ui-relay
piggydoughnut Oct 16, 2024
7eec0b7
bumped version
piggydoughnut Oct 16, 2024
19ee4e0
updated coretime chain summary
piggydoughnut Oct 16, 2024
7bb556f
updated summary, added timeslice for the first sale start,
piggydoughnut Oct 16, 2024
17fa09b
hook updates to make sure the coretime data is displayed even if work…
piggydoughnut Oct 16, 2024
56bbcfa
removed unused files
piggydoughnut Oct 16, 2024
da7be71
lint
piggydoughnut Oct 16, 2024
a5de399
tsc
piggydoughnut Oct 17, 2024
ad8053b
merging parachainIds with renewalIds
piggydoughnut Oct 17, 2024
d807d4e
if there is no record in potential renewals, then the chain has renew…
piggydoughnut Oct 17, 2024
316243a
added config for page-coretime
piggydoughnut Oct 17, 2024
fc8c983
removed hardcoded regionLength value
piggydoughnut Oct 18, 2024
90f06a5
improved function to find out type
piggydoughnut Oct 18, 2024
b15407c
lint
piggydoughnut Oct 18, 2024
a425c9f
tsc
piggydoughnut Oct 18, 2024
f0139db
Merge branch 'master' of github.com:polkadot-js/apps into dm-coretime…
TarikGul Oct 22, 2024
4df1c0a
Fix versioning
TarikGul Oct 22, 2024
bb764fd
fix comments
TarikGul Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merging parachainIds with renewalIds
  • Loading branch information
piggydoughnut committed Oct 17, 2024
commit ad8053bb048946e1e53f3150c30dd2be1edf64ee
5 changes: 2 additions & 3 deletions packages/page-broker/src/Overview/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface Props {
workloadInfos?: CoreWorkload[]
}

function Summary({ coreCount, workloadInfos }: Props): React.ReactElement {
function Summary ({ coreCount, workloadInfos }: Props): React.ReactElement {
const { t } = useTranslation();
const { api, apiEndpoint, isApiReady } = useApi();
const uiHighlight = apiEndpoint?.ui.color || defaultHighlight;
Expand Down Expand Up @@ -79,7 +79,7 @@ function Summary({ coreCount, workloadInfos }: Props): React.ReactElement {
progress={{
isBlurred: false,
total: new BN(config?.regionLength || 0),
value: config?.regionLength && currentRegionEnd && status && new BN(config?.regionLength - (currentRegionEnd - status?.lastTimeslice)) || BN_ZERO,
value: (config?.regionLength && currentRegionEnd && status && new BN(config?.regionLength - (currentRegionEnd - status?.lastTimeslice))) || BN_ZERO,
withTime: false
}}
/>
Expand Down Expand Up @@ -114,7 +114,6 @@ function Summary({ coreCount, workloadInfos }: Props): React.ReactElement {
<div style={{ fontSize: '14px' }}>{estimateTime(currentRegionEnd, status?.lastTimeslice * 80)}</div>
</div>
</CardSummary>

<CardSummary
className='media--1200'
label={t('cycle ts')}
Expand Down
12 changes: 6 additions & 6 deletions packages/page-coretime/src/Overview/Summary.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2024 @polkadot/app-coretime authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { ApiPromise } from '@polkadot/api';

Check failure on line 4 in packages/page-coretime/src/Overview/Summary.tsx

View workflow job for this annotation

GitHub Actions / pr (lint)

incorrect header

Check failure on line 4 in packages/page-coretime/src/Overview/Summary.tsx

View workflow job for this annotation

GitHub Actions / pr (lint)

Run autofix to sort these imports!
import type { BrokerStatus, CoreDescription, PalletBrokerConfigRecord, PalletBrokerSaleInfoRecord, RegionInfo } from '@polkadot/react-hooks/types';

import React, { useMemo } from 'react';
Expand All @@ -11,27 +11,27 @@
import { BN } from '@polkadot/util';

import { useTranslation } from '../translate.js';
import { CoreTimeConsts, estimateTime } from '../utils.js';
import { FirstCycleStart, estimateTime } from '../utils.js';

interface Props {
api: ApiPromise,
api: ApiPromise | null,
coreDscriptors?: CoreDescription[];
saleInfo: PalletBrokerSaleInfoRecord
config: PalletBrokerConfigRecord,
region: RegionInfo,
region: RegionInfo[],
status: BrokerStatus,
parachainCount: number
}

function Summary ({ api, config, parachainCount, saleInfo, status }: Props): React.ReactElement<Props> {
function Summary({ api, config, parachainCount, saleInfo, status }: Props): React.ReactElement<Props> {

Check failure on line 26 in packages/page-coretime/src/Overview/Summary.tsx

View workflow job for this annotation

GitHub Actions / pr (lint)

Missing space before function parentheses
const { t } = useTranslation();
const currentRegionEnd = saleInfo.regionEnd - config.regionLength;
const currentRegionStart = saleInfo.regionEnd - config.regionLength * 2;
const chainName = useCall<string>(api?.rpc.system.chain)?.toString().toLowerCase();

const cycleNumber = useMemo(() =>
chainName && currentRegionEnd && Math.floor((currentRegionEnd - CoreTimeConsts.FirstCycleStart[chainName]) / config.regionLength)
, [currentRegionEnd, chainName, config]);
chainName && currentRegionEnd && Math.floor((currentRegionEnd - FirstCycleStart[chainName]) / config.regionLength)
, [currentRegionEnd, chainName, config]);

Check failure on line 34 in packages/page-coretime/src/Overview/Summary.tsx

View workflow job for this annotation

GitHub Actions / pr (lint)

Expected indentation of 2 spaces but found 4

return (
<SummaryBox>
Expand Down
23 changes: 8 additions & 15 deletions packages/page-coretime/src/ParachainsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2024 @polkadot/app-coretime authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { FlagColor } from '@polkadot/react-components/types';

Check failure on line 4 in packages/page-coretime/src/ParachainsTable.tsx

View workflow job for this annotation

GitHub Actions / pr (lint)

incorrect header
import type { CoretimeInformation } from '@polkadot/react-hooks/types';

import React, { useRef } from 'react';
Expand All @@ -20,7 +20,6 @@
}

interface Props {
ids: number[]
coretimeInfo: CoretimeInformation
}

Expand All @@ -30,21 +29,17 @@
[CoreTimeTypes['Bulk Coretime']]: 'pink'
};

function ParachainsTable ({ coretimeInfo, ids }: Props): React.ReactElement<Props> {
function ParachainsTable ({ coretimeInfo }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
[t('parachains'), 'start'],
[t('name'), 'start'],
// ['', 'media--1400'],
[t('core number'), 'start'],
[t('type'), 'start'],
[t('last block'), 'start'],
[t('end'), 'start'],
[t('renewal'), 'start'],
[t('renewal price'), 'start']
// [t('chain'), 'no-pad-left'],
// [t('in/out'), 'media--1700', 2],
// [t('leases'), 'media--1100']
]);

return (
Expand All @@ -53,20 +48,18 @@
header={headerRef.current}
isSplit={false}
>
{ids && coretimeInfo && ids.map((id: number) => {
const chain = coretimeInfo.chainInfo[id];
{coretimeInfo?.taskIds?.map((taskId: number) => {
const chain = coretimeInfo.chainInfo[taskId];
const type = chain?.lease ? CoreTimeTypes.Lease : chain?.reservation ? CoreTimeTypes.Reservation : CoreTimeTypes['Bulk Coretime'];
const targetTimeslice = chain?.lease?.until || coretimeInfo.salesInfo.regionEnd;
const showEsimates = !!targetTimeslice && type !== CoreTimeTypes.Reservation;
// const renewBefore =

return (
<tr key={id}>
<td>{id}</td>
<tr key={taskId}>
<td>{taskId}</td>
<td>
<ParaLink
id={new BN(id)}
key={id}
id={new BN(taskId)}
/>
</td>
<td>{chain?.workload?.core}</td>
Expand All @@ -78,8 +71,8 @@
</td>
<td>{showEsimates && formatNumber(targetTimeslice * 80).toString()}</td>
<td>{showEsimates && estimateTime(targetTimeslice, coretimeInfo.status.lastCommittedTimeslice * 80)}</td>
<td>{chain.renewal ? 'renewed' : ''}</td>
<td>{chain.renewal ? formatBalance(chain.renewal?.price.toString()) : ''}</td>
<td>{chain?.renewal ? 'renewed' : ''}</td>
<td>{chain?.renewal ? formatBalance(chain.renewal?.price.toString()) : ''}</td>
</tr>
);
}
Expand Down
21 changes: 5 additions & 16 deletions packages/page-coretime/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Copyright 2017-2024 @polkadot/app-coretime authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { TabItem } from '@polkadot/react-components/types';

Check failure on line 4 in packages/page-coretime/src/index.tsx

View workflow job for this annotation

GitHub Actions / pr (lint)

incorrect header
import type { ParaId } from '@polkadot/types/interfaces';

import React, { useEffect, useRef, useState } from 'react';
import React, { useRef } from 'react';

import { Tabs } from '@polkadot/react-components';
import { useApi, useCall, useCoretimeInformation } from '@polkadot/react-hooks';
import { useApi, useCoretimeInformation } from '@polkadot/react-hooks';

import Summary from './Overview/Summary.js';
import ParachainsTable from './ParachainsTable.js';
Expand All @@ -32,37 +31,27 @@
const { t } = useTranslation();
const { api, isApiReady } = useApi();
const itemsRef = useRef(createItemsRef(t));
const [parachainIds, setParachainIds] = useState<number[]>([]);
const coretimeInfo = useCoretimeInformation(api, isApiReady);

const paraIds = useCall<ParaId[]>(api.query.paras.parachains);

useEffect(() => {
if (paraIds) {
setParachainIds(paraIds.map((a) => a.toNumber()));
}
}, [paraIds]);

return (
<main className={className}>
<Tabs
basePath={basePath}
items={itemsRef.current}
/>
{coretimeInfo?.salesInfo && (
{coretimeInfo && (
<Summary
api={isApiReady ? api : null}
config={coretimeInfo?.config}
parachainCount={paraIds?.length || 0}
parachainCount={coretimeInfo.taskIds?.length || 0}
region={coretimeInfo?.region}
saleInfo={coretimeInfo?.salesInfo}
status={coretimeInfo?.status}
/>
)}
{!!parachainIds &&
{!!coretimeInfo &&
<ParachainsTable
coretimeInfo={coretimeInfo}
ids={parachainIds}
/>
}

Expand Down
9 changes: 5 additions & 4 deletions packages/page-coretime/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// Copyright 2017-2024 @polkadot/app-coretime authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { BN } from '@polkadot/util';

Check failure on line 4 in packages/page-coretime/src/utils.ts

View workflow job for this annotation

GitHub Actions / pr (lint)

incorrect header

export const CoreTimeConsts = {
BlockTime: 6000,
BlocksPerTimeslice: 80,
DefaultRegion: 5040,

Check failure on line 9 in packages/page-coretime/src/utils.ts

View workflow job for this annotation

GitHub Actions / pr (lint)

Unexpected trailing comma
FirstCycleStart: {
kusama: 285768,
polkadot: 282525
}
};

export const FirstCycleStart: Record<string, number> ={
kusama: 285768,
polkadot: 282525
}

function formatDate (date: Date) {
const day = date.getDate();
const month = date.toLocaleString('default', { month: 'short' });
Expand Down
7 changes: 4 additions & 3 deletions packages/react-hooks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { SubmittableExtrinsic } from '@polkadot/api/types';
import type { DeriveAccountFlags, DeriveAccountRegistration } from '@polkadot/api-derive/types';
import type { DisplayedJudgement } from '@polkadot/react-components/types';
import type { Option, u32, u128, Vec } from '@polkadot/types';
import type { AccountId, BlockNumber, Call, Hash, ParaId, SessionIndex, ValidatorPrefs } from '@polkadot/types/interfaces';
import type { AccountId, BlockNumber, Call, Hash, SessionIndex, ValidatorPrefs } from '@polkadot/types/interfaces';
import type { PalletPreimageRequestStatus, PalletStakingRewardDestination, PalletStakingStakingLedger, PolkadotRuntimeParachainsAssignerCoretimeCoreDescriptor, SpStakingExposurePage, SpStakingPagedExposureMetadata } from '@polkadot/types/lookup';
import type { ICompact, IExtrinsic, INumber } from '@polkadot/types/types';
import type { KeyringJson$Meta } from '@polkadot/ui-keyring/types';
Expand Down Expand Up @@ -323,8 +323,8 @@ export interface PalletBrokerConfigRecord {
}

export interface ChainInformation {
id: ParaId,
workload: CoreWorkload[] | undefined,
id: number,
workload: CoreWorkload | undefined,
renewal: PotentialRenewal | undefined,
worklplan: CoreWorkplan[] | undefined,
lease: LegacyLease | undefined,
Expand All @@ -336,6 +336,7 @@ export interface CoretimeInformation {
status: BrokerStatus,
region: RegionInfo[],
config: PalletBrokerConfigRecord
taskIds: number[]
}

export interface BrokerStatus {
Expand Down
12 changes: 7 additions & 5 deletions packages/react-hooks/src/useBrokerPotentialRenewals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type { ApiPromise } from '@polkadot/api';
import type { Option, StorageKey, u32 } from '@polkadot/types';
import type { PalletBrokerPotentialRenewalId, PalletBrokerPotentialRenewalRecord } from '@polkadot/types/lookup';
import type { PotentialRenewal } from './types.js';
import { BN_ZERO, } from '@polkadot/util';

import { useEffect, useState } from 'react';

import { createNamedHook, useCall, useMapKeys } from '@polkadot/react-hooks';
import { BN_ZERO } from '@polkadot/util';

import { processHexMask } from './utils/dataProcessing.js';

Expand All @@ -19,8 +19,9 @@ function extractInfo (info: Option<PalletBrokerPotentialRenewalRecord>, item: Pa
let task = '';

if (!unwrapped) {
return
return;
}

const completion = unwrapped?.completion;

if (completion?.isComplete) {
Expand All @@ -45,7 +46,6 @@ function extractInfo (info: Option<PalletBrokerPotentialRenewalRecord>, item: Pa
task,
when: item?.when.toNumber()
};

}

const OPT_KEY = {
Expand All @@ -61,9 +61,11 @@ function useBrokerPotentialRenewalsImpl (api: ApiPromise, ready: boolean): Poten

useEffect((): void => {
if (!potentialRenewals) {
return
return;
}
const renewals = potentialRenewals[0][0].map((info, index) => extractInfo(potentialRenewals[1][index], info))

const renewals = potentialRenewals[0][0].map((info, index) => extractInfo(potentialRenewals[1][index], info));

setState(renewals.filter((renewal): renewal is PotentialRenewal => !!renewal));
}, [potentialRenewals]);

Expand Down
41 changes: 30 additions & 11 deletions packages/react-hooks/src/useCoretimeInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function useCoretimeInformationImpl (api: ApiPromise, ready: boolean): CoretimeI
const { apiCoretime, isApiReady } = useApi();

const [workloadData, setWorkloadData] = useState<CoreWorkload[]>([]);
const [taskIds, setTaskIds] = useState<number[]>([]);

/** coretime API calls */
const status = useBrokerStatus(apiCoretime, isApiReady);
Expand All @@ -30,10 +31,24 @@ function useCoretimeInformationImpl (api: ApiPromise, ready: boolean): CoretimeI
/** Other APIs */
const paraIds = useCall<ParaId[]>(api.query.paras.parachains);
const coreInfos = useCoreDescriptor(api, ready);

const potentialRenewalsCurrentRegion = useMemo(() => potentialRenewals?.filter((renewal: PotentialRenewal) => renewal.when === salesInfo?.regionEnd), [potentialRenewals, salesInfo]);
// when - The point in time that the renewable workload on core ends and a fresh renewal may begin.
const potentialRenewalsCurrentRegion = useMemo(() => config && salesInfo && potentialRenewals?.filter((renewal: PotentialRenewal) => renewal.when.toString() === salesInfo?.regionBegin.toString()), [potentialRenewals, salesInfo, config]);
const [state, setState] = useState<CoretimeInformation | undefined>();

useEffect(() => {
if (paraIds?.length && potentialRenewals?.length && !taskIds.length) {
const simpleIds = paraIds.map((p) => p.toNumber());
const renewalIds = potentialRenewals?.map((r) => Number(r.task));
const numbers = [...new Set(simpleIds.concat(renewalIds))];

if (numbers?.length > simpleIds.length) {
setTaskIds(numbers.sort((a, b) => a - b));
} else {
setTaskIds(simpleIds);
}
}
}, [potentialRenewals, paraIds, taskIds]);

useEffect(() => {
if (workloads?.length) {
setWorkloadData(workloads);
Expand Down Expand Up @@ -64,18 +79,21 @@ function useCoretimeInformationImpl (api: ApiPromise, ready: boolean): CoretimeI

const chainInfo: Record<string, ChainInformation> = {};

paraIds?.forEach((id: ParaId) => {
const lease = leases?.find((lease) => lease.task === id.toString());
const reservation = reservations?.find((reservation) => reservation.task === id.toString());
const workload = workloadData?.find((one) => one.info.task === id.toString());
taskIds?.forEach((id) => {
const taskId = id.toString();
const lease = leases?.find((lease) => lease.task === taskId);
const reservation = reservations?.find((reservation) => reservation.task === taskId);
const workload = workloadData?.find((one) => one.info.task === taskId);
const renewal = potentialRenewalsCurrentRegion?.find((renewal) => renewal.task.toString() === taskId);
const worklplan = workplans?.filter((workplan) => workplan.core === workload?.core && workplan.info.task.toString() === taskId);

chainInfo[id.toString()] = {
id: id.toNumber() as unknown as ParaId,
id,
lease,
renewal: potentialRenewalsCurrentRegion?.find((renewal) => renewal.task.toString() === id.toString()),
renewal,
reservation,
workload: workloadData,
worklplan: workplans?.filter((workplan) => workplan.core === workload?.core && workplan.info.task.toString() === id.toString())
workload,
worklplan
};
});

Expand All @@ -86,9 +104,10 @@ function useCoretimeInformationImpl (api: ApiPromise, ready: boolean): CoretimeI
region,
salesInfo,
status,
taskIds
});
}
}, [paraIds, workloadData, potentialRenewalsCurrentRegion, salesInfo, leases, reservations, region, status, config, workplans]);
}, [taskIds, workloadData, potentialRenewalsCurrentRegion, salesInfo, leases, reservations, region, status, config, workplans]);

return state;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-hooks/src/utils/dataProcessing.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright 2017-2024 @polkadot/react-hooks authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { PalletBrokerScheduleItem, PalletBrokerCoreMask } from '@polkadot/types/lookup';
import type { PalletBrokerScheduleItem } from '@polkadot/types/lookup';

import { BN } from '@polkadot/util';

export function hexToBin (hex: string): string {
return parseInt(hex, 16).toString(2);
}

export function processHexMask (mask: PalletBrokerScheduleItem['mask'] | PalletBrokerCoreMask | undefined): string[] {
export function processHexMask (mask: PalletBrokerScheduleItem['mask'] | undefined): string[] {
if (!mask) {
return [];
}
Expand Down
Loading