Skip to content

Commit 4df5c9a

Browse files
Relay Chain - Coretime Overview UI Tab (#11016)
* exposing coretime wss endpoint to use on relay chain, adjusted hooks to accept api endpoint as a parameter * adjusting hook calls to new parameters * added Tag for coretime types, renamed occupancyType to coretimeType * added cycle progress and cycle end date to summary, fixed the estimation dates * coretime page draft, added hook for gathering all the coretime information in order to show it on relay chain * lint * bumped version * updated coretime chain summary * updated summary, added timeslice for the first sale start, * hook updates to make sure the coretime data is displayed even if workloads are empty, fallback on coreAssignments * removed unused files * lint * tsc * merging parachainIds with renewalIds * if there is no record in potential renewals, then the chain has renewed already * added config for page-coretime * removed hardcoded regionLength value * improved function to find out type * lint * tsc * Fix versioning * fix comments --------- Co-authored-by: tarikgul <[email protected]>
1 parent 9134c0e commit 4df5c9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+967
-219
lines changed

packages/apps-config/src/endpoints/testingRelayPaseo.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ export const testParasPaseoCommon: EndpointOption[] = [
351351
}
352352
},
353353
{
354-
info: 'BridgeHub',
354+
info: 'PaseoBridgeHub',
355355
isPeopleForIdentity: true,
356356
paraId: 1002,
357357
providers: {
@@ -367,7 +367,7 @@ export const testParasPaseoCommon: EndpointOption[] = [
367367
}
368368
},
369369
{
370-
info: 'Coretime',
370+
info: 'PaseoCoretime',
371371
isPeopleForIdentity: true,
372372
paraId: 1005,
373373
providers: {

packages/apps-routing/src/coretime.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2017-2024 @polkadot/apps-routing authors & contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import type { Route, TFunction } from './types.js';
5+
6+
import Component from '@polkadot/app-coretime';
7+
8+
export default function create (t: TFunction): Route {
9+
return {
10+
Component,
11+
display: {
12+
needsApi: [
13+
'query.coretimeAssignmentProvider.coreDescriptors'
14+
],
15+
needsApiInstances: true
16+
},
17+
group: 'network',
18+
icon: 'flask',
19+
name: 'coretime',
20+
text: t('nav.coretime', 'Coretime (Experimental)', { ns: 'apps-routing' })
21+
};
22+
}

packages/apps-routing/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import calendar from './calendar.js';
1414
import claims from './claims.js';
1515
import collator from './collator.js';
1616
import contracts from './contracts.js';
17+
import coretime from './coretime.js';
1718
import council from './council.js';
1819
import democracy from './democracy.js';
1920
import explorer from './explorer.js';
@@ -62,7 +63,9 @@ export default function create (t: TFunction): Routes {
6263
// Legacy staking Pre v14 pallet version.
6364
stakingLegacy(t),
6465
collator(t),
66+
// Coretime
6567
broker(t),
68+
coretime(t),
6669
// governance v2
6770
referenda(t),
6871
membership(t),

packages/apps-routing/tsconfig.build.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
{ "path": "../page-alliance/tsconfig.build.json" },
1212
{ "path": "../page-ambassador/tsconfig.build.json" },
1313
{ "path": "../page-assets/tsconfig.build.json" },
14+
{ "path": "../page-broker/tsconfig.build.json" },
1415
{ "path": "../page-bounties/tsconfig.build.json" },
1516
{ "path": "../page-calendar/tsconfig.build.json" },
1617
{ "path": "../page-claims/tsconfig.build.json" },
17-
{ "path": "../page-broker/tsconfig.build.json" },
1818
{ "path": "../page-collator/tsconfig.build.json" },
1919
{ "path": "../page-contracts/tsconfig.build.json" },
20+
{ "path": "../page-coretime/tsconfig.build.json" },
2021
{ "path": "../page-council/tsconfig.build.json" },
2122
{ "path": "../page-democracy/tsconfig.build.json" },
2223
{ "path": "../page-explorer/tsconfig.build.json" },

packages/page-broker/src/Overview/CoreTable.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import type { ApiPromise } from '@polkadot/api';
5+
import type { PalletBrokerConfigRecord } from '@polkadot/react-hooks/types';
56

67
import React, { useRef } from 'react';
78

@@ -14,11 +15,12 @@ import Workload from './Workload.js';
1415
interface Props {
1516
api: ApiPromise;
1617
core: number;
18+
config: PalletBrokerConfigRecord,
1719
workload?: CoreWorkloadType[],
1820
workplan?: CoreWorkplanType[],
1921
}
2022

21-
function CoreTable ({ api, core, workload, workplan }: Props): React.ReactElement<Props> {
23+
function CoreTable ({ api, config, core, workload, workplan }: Props): React.ReactElement<Props> {
2224
const { t } = useTranslation();
2325
const headerRef = useRef<([React.ReactNode?, string?] | false)[]>([[t('core')]]);
2426
const header: [React.ReactNode?, string?, number?, (() => void)?][] = [
@@ -39,6 +41,7 @@ function CoreTable ({ api, core, workload, workplan }: Props): React.ReactElemen
3941
>
4042
<Workload
4143
api={api}
44+
config={config}
4245
core={core}
4346
key={core}
4447
workload={workload}

packages/page-broker/src/Overview/CoresTables.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,26 @@ import type { CoreInfo } from '../types.js';
66

77
import React from 'react';
88

9+
import { useBrokerConfig } from '@polkadot/react-hooks';
10+
911
import CoreTable from './CoreTable.js';
1012

1113
interface Props {
1214
api: ApiPromise;
15+
isApiReady: boolean;
1316
data: CoreInfo[];
1417
}
1518

16-
function CoresTable ({ api, data }: Props): React.ReactElement<Props> {
19+
function CoresTable ({ api, data, isApiReady }: Props): React.ReactElement<Props> {
20+
const config = useBrokerConfig(api, isApiReady);
21+
1722
return (
1823
<>
19-
{data?.map((coreData) => {
24+
{config && data?.map((coreData) => {
2025
return (
2126
<CoreTable
2227
api={api}
28+
config={config}
2329
core={coreData?.core}
2430
key={coreData?.core}
2531
workload={coreData?.workload}

packages/page-broker/src/Overview/Summary.tsx

+51-15
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
import type { LinkOption } from '@polkadot/apps-config/endpoints/types';
55
import type { statsType } from '../types.js';
66

7-
import React from 'react';
7+
import React, { useMemo } from 'react';
88

99
import { CardSummary, styled, SummaryBox, UsageBar } from '@polkadot/react-components';
1010
import { defaultHighlight } from '@polkadot/react-components/styles';
11-
import { useApi, useBrokerSalesInfo, useBrokerStatus } from '@polkadot/react-hooks';
11+
import { useApi, useBrokerConfig, useBrokerSalesInfo, useBrokerStatus } from '@polkadot/react-hooks';
1212
import { type CoreWorkload } from '@polkadot/react-hooks/types';
13-
import { formatBalance } from '@polkadot/util';
13+
import { BN, BN_ZERO } from '@polkadot/util';
1414

1515
import { useTranslation } from '../translate.js';
16-
import { getStats } from '../utils.js';
16+
import { estimateTime, getStats } from '../utils.js';
1717
import RegionLength from './Summary/RegionLength.js';
1818
import Timeslice from './Summary/Timeslice.js';
1919
import TimeslicePeriod from './Summary/TimeslicePeriod.js';
@@ -41,12 +41,15 @@ interface Props {
4141

4242
function Summary ({ coreCount, workloadInfos }: Props): React.ReactElement {
4343
const { t } = useTranslation();
44-
const { api, apiEndpoint } = useApi();
45-
const totalCores = useBrokerStatus('coreCount');
44+
const { api, apiEndpoint, isApiReady } = useApi();
4645
const uiHighlight = apiEndpoint?.ui.color || defaultHighlight;
47-
const { idles, pools, tasks }: statsType = React.useMemo(() => getStats(totalCores, workloadInfos), [totalCores, workloadInfos]);
46+
const { idles, pools, tasks }: statsType = React.useMemo(() => getStats(coreCount, workloadInfos), [coreCount, workloadInfos]);
4847

49-
const salesInfo = useBrokerSalesInfo();
48+
const saleInfo = useBrokerSalesInfo(api, isApiReady);
49+
const config = useBrokerConfig(api, isApiReady);
50+
const status = useBrokerStatus(api, isApiReady);
51+
const currentRegionEnd = useMemo(() => saleInfo && config && saleInfo?.regionEnd - config?.regionLength, [saleInfo, config]);
52+
const currentRegionStart = useMemo(() => currentRegionEnd && config && currentRegionEnd - config?.regionLength, [currentRegionEnd, config]);
5053

5154
return (
5255
<SummaryBox>
@@ -63,24 +66,31 @@ function Summary ({ coreCount, workloadInfos }: Props): React.ReactElement {
6366
<CardSummary label={t('region (ts)')}>
6467
<RegionLength />
6568
</CardSummary>
66-
<CardSummary label={t('estimated bulk price')}>
67-
<div className='ui--balance-value'>
68-
{formatBalance(salesInfo?.endPrice) || '-'}
69-
</div>
70-
</CardSummary>
7169
<CardSummary label={t('total cores')}>
7270
{coreCount}
7371
</CardSummary>
7472
<CardSummary label={t('cores sold/offered')}>
7573
<div>
76-
{salesInfo?.coresSold} / {salesInfo?.coresOffered}
74+
{saleInfo?.coresSold} / {saleInfo?.coresOffered}
7775
</div>
7876
</CardSummary>
77+
<CardSummary
78+
label={t('cycle progress')}
79+
progress={{
80+
isBlurred: false,
81+
total: new BN(config?.regionLength || 0),
82+
value: (config?.regionLength && currentRegionEnd && status && new BN(config?.regionLength - (currentRegionEnd - status?.lastTimeslice))) || BN_ZERO,
83+
withTime: false
84+
}}
85+
/>
7986
</StyledDiv>
8087
</>
8188

8289
)}
83-
<div style={{ marginLeft: '2rem' }}>
90+
<div
91+
className='media--1400'
92+
style={{ marginLeft: '2rem' }}
93+
>
8494
<UsageBar
8595
data={[
8696
{ color: '#FFFFFF', label: 'Idle', value: idles },
@@ -91,6 +101,32 @@ function Summary ({ coreCount, workloadInfos }: Props): React.ReactElement {
91101

92102
</div>
93103
</StyledSection>
104+
<section>
105+
{status && currentRegionStart && currentRegionEnd &&
106+
(
107+
<>
108+
<CardSummary
109+
className='media--1200'
110+
label={t('cycle dates')}
111+
>
112+
<div>
113+
<div style={{ fontSize: '14px' }}>{estimateTime(currentRegionStart, status?.lastTimeslice * 80)}</div>
114+
<div style={{ fontSize: '14px' }}>{estimateTime(currentRegionEnd, status?.lastTimeslice * 80)}</div>
115+
</div>
116+
</CardSummary>
117+
<CardSummary
118+
className='media--1200'
119+
label={t('cycle ts')}
120+
>
121+
<div>
122+
<div style={{ fontSize: '14px' }}>{currentRegionStart}</div>
123+
<div style={{ fontSize: '14px' }}>{currentRegionEnd}</div>
124+
</div>
125+
</CardSummary>
126+
</>
127+
)
128+
}
129+
</section>
94130
</SummaryBox>
95131
);
96132
}

packages/page-broker/src/Overview/Summary/Cores.tsx

-24
This file was deleted.

packages/page-broker/src/Overview/Summary/RenewalPrice.tsx

-26
This file was deleted.

packages/page-broker/src/Overview/Summary/Timeslice.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33

44
import React from 'react';
55

6-
import { BrokerStatus } from '@polkadot/react-query';
6+
import { useApi, useBrokerStatus } from '@polkadot/react-hooks';
77

88
interface Props {
99
children?: React.ReactNode;
1010
className?: string;
1111
}
1212

1313
function Timeslice ({ children, className }: Props): React.ReactElement<Props> | null {
14+
const { api, isApiReady } = useApi();
15+
const info = useBrokerStatus(api, isApiReady);
16+
1417
return (
15-
<BrokerStatus
16-
className={className}
17-
query='lastTimeslice'
18-
>
18+
<div className={className}>
19+
{info?.lastTimeslice || '-'}
1920
{children}
20-
</BrokerStatus>
21-
);
21+
</div>);
2222
}
2323

2424
export default React.memo(Timeslice);

0 commit comments

Comments
 (0)