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 all commits
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
4 changes: 2 additions & 2 deletions packages/apps-config/src/endpoints/testingRelayPaseo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export const testParasPaseoCommon: EndpointOption[] = [
}
},
{
info: 'BridgeHub',
info: 'PaseoBridgeHub',
isPeopleForIdentity: true,
paraId: 1002,
providers: {
Expand All @@ -367,7 +367,7 @@ export const testParasPaseoCommon: EndpointOption[] = [
}
},
{
info: 'Coretime',
info: 'PaseoCoretime',
isPeopleForIdentity: true,
paraId: 1005,
providers: {
Expand Down
22 changes: 22 additions & 0 deletions packages/apps-routing/src/coretime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2017-2024 @polkadot/apps-routing authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { Route, TFunction } from './types.js';

import Component from '@polkadot/app-coretime';

export default function create (t: TFunction): Route {
return {
Component,
display: {
needsApi: [
'query.coretimeAssignmentProvider.coreDescriptors'
],
needsApiInstances: true
},
group: 'network',
icon: 'flask',
name: 'coretime',
text: t('nav.coretime', 'Coretime (Experimental)', { ns: 'apps-routing' })
};
}
3 changes: 3 additions & 0 deletions packages/apps-routing/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import calendar from './calendar.js';
import claims from './claims.js';
import collator from './collator.js';
import contracts from './contracts.js';
import coretime from './coretime.js';
import council from './council.js';
import democracy from './democracy.js';
import explorer from './explorer.js';
Expand Down Expand Up @@ -62,7 +63,9 @@ export default function create (t: TFunction): Routes {
// Legacy staking Pre v14 pallet version.
stakingLegacy(t),
collator(t),
// Coretime
broker(t),
coretime(t),
// governance v2
referenda(t),
membership(t),
Expand Down
3 changes: 2 additions & 1 deletion packages/apps-routing/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
{ "path": "../page-alliance/tsconfig.build.json" },
{ "path": "../page-ambassador/tsconfig.build.json" },
{ "path": "../page-assets/tsconfig.build.json" },
{ "path": "../page-broker/tsconfig.build.json" },
{ "path": "../page-bounties/tsconfig.build.json" },
{ "path": "../page-calendar/tsconfig.build.json" },
{ "path": "../page-claims/tsconfig.build.json" },
{ "path": "../page-broker/tsconfig.build.json" },
{ "path": "../page-collator/tsconfig.build.json" },
{ "path": "../page-contracts/tsconfig.build.json" },
{ "path": "../page-coretime/tsconfig.build.json" },
{ "path": "../page-council/tsconfig.build.json" },
{ "path": "../page-democracy/tsconfig.build.json" },
{ "path": "../page-explorer/tsconfig.build.json" },
Expand Down
5 changes: 4 additions & 1 deletion packages/page-broker/src/Overview/CoreTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

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

import React, { useRef } from 'react';

Expand All @@ -14,11 +15,12 @@ import Workload from './Workload.js';
interface Props {
api: ApiPromise;
core: number;
config: PalletBrokerConfigRecord,
workload?: CoreWorkloadType[],
workplan?: CoreWorkplanType[],
}

function CoreTable ({ api, core, workload, workplan }: Props): React.ReactElement<Props> {
function CoreTable ({ api, config, core, workload, workplan }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const headerRef = useRef<([React.ReactNode?, string?] | false)[]>([[t('core')]]);
const header: [React.ReactNode?, string?, number?, (() => void)?][] = [
Expand All @@ -39,6 +41,7 @@ function CoreTable ({ api, core, workload, workplan }: Props): React.ReactElemen
>
<Workload
api={api}
config={config}
core={core}
key={core}
workload={workload}
Expand Down
10 changes: 8 additions & 2 deletions packages/page-broker/src/Overview/CoresTables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@ import type { CoreInfo } from '../types.js';

import React from 'react';

import { useBrokerConfig } from '@polkadot/react-hooks';

import CoreTable from './CoreTable.js';

interface Props {
api: ApiPromise;
isApiReady: boolean;
data: CoreInfo[];
}

function CoresTable ({ api, data }: Props): React.ReactElement<Props> {
function CoresTable ({ api, data, isApiReady }: Props): React.ReactElement<Props> {
const config = useBrokerConfig(api, isApiReady);

return (
<>
{data?.map((coreData) => {
{config && data?.map((coreData) => {
return (
<CoreTable
api={api}
config={config}
core={coreData?.core}
key={coreData?.core}
workload={coreData?.workload}
Expand Down
66 changes: 51 additions & 15 deletions packages/page-broker/src/Overview/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import type { LinkOption } from '@polkadot/apps-config/endpoints/types';
import type { statsType } from '../types.js';

import React from 'react';
import React, { useMemo } from 'react';

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

import { useTranslation } from '../translate.js';
import { getStats } from '../utils.js';
import { estimateTime, getStats } from '../utils.js';
import RegionLength from './Summary/RegionLength.js';
import Timeslice from './Summary/Timeslice.js';
import TimeslicePeriod from './Summary/TimeslicePeriod.js';
Expand Down Expand Up @@ -41,12 +41,15 @@ interface Props {

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

const salesInfo = useBrokerSalesInfo();
const saleInfo = useBrokerSalesInfo(api, isApiReady);
const config = useBrokerConfig(api, isApiReady);
const status = useBrokerStatus(api, isApiReady);
const currentRegionEnd = useMemo(() => saleInfo && config && saleInfo?.regionEnd - config?.regionLength, [saleInfo, config]);
const currentRegionStart = useMemo(() => currentRegionEnd && config && currentRegionEnd - config?.regionLength, [currentRegionEnd, config]);

return (
<SummaryBox>
Expand All @@ -63,24 +66,31 @@ function Summary ({ coreCount, workloadInfos }: Props): React.ReactElement {
<CardSummary label={t('region (ts)')}>
<RegionLength />
</CardSummary>
<CardSummary label={t('estimated bulk price')}>
<div className='ui--balance-value'>
{formatBalance(salesInfo?.endPrice) || '-'}
</div>
</CardSummary>
<CardSummary label={t('total cores')}>
{coreCount}
</CardSummary>
<CardSummary label={t('cores sold/offered')}>
<div>
{salesInfo?.coresSold} / {salesInfo?.coresOffered}
{saleInfo?.coresSold} / {saleInfo?.coresOffered}
</div>
</CardSummary>
<CardSummary
label={t('cycle progress')}
progress={{
isBlurred: false,
total: new BN(config?.regionLength || 0),
value: (config?.regionLength && currentRegionEnd && status && new BN(config?.regionLength - (currentRegionEnd - status?.lastTimeslice))) || BN_ZERO,
withTime: false
}}
/>
</StyledDiv>
</>

)}
<div style={{ marginLeft: '2rem' }}>
<div
className='media--1400'
style={{ marginLeft: '2rem' }}
>
<UsageBar
data={[
{ color: '#FFFFFF', label: 'Idle', value: idles },
Expand All @@ -91,6 +101,32 @@ function Summary ({ coreCount, workloadInfos }: Props): React.ReactElement {

</div>
</StyledSection>
<section>
{status && currentRegionStart && currentRegionEnd &&
(
<>
<CardSummary
className='media--1200'
label={t('cycle dates')}
>
<div>
<div style={{ fontSize: '14px' }}>{estimateTime(currentRegionStart, status?.lastTimeslice * 80)}</div>
<div style={{ fontSize: '14px' }}>{estimateTime(currentRegionEnd, status?.lastTimeslice * 80)}</div>
</div>
</CardSummary>
<CardSummary
className='media--1200'
label={t('cycle ts')}
>
<div>
<div style={{ fontSize: '14px' }}>{currentRegionStart}</div>
<div style={{ fontSize: '14px' }}>{currentRegionEnd}</div>
</div>
</CardSummary>
</>
)
}
</section>
</SummaryBox>
);
}
Expand Down
24 changes: 0 additions & 24 deletions packages/page-broker/src/Overview/Summary/Cores.tsx

This file was deleted.

26 changes: 0 additions & 26 deletions packages/page-broker/src/Overview/Summary/RenewalPrice.tsx

This file was deleted.

14 changes: 7 additions & 7 deletions packages/page-broker/src/Overview/Summary/Timeslice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@

import React from 'react';

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

interface Props {
children?: React.ReactNode;
className?: string;
}

function Timeslice ({ children, className }: Props): React.ReactElement<Props> | null {
const { api, isApiReady } = useApi();
const info = useBrokerStatus(api, isApiReady);

return (
<BrokerStatus
className={className}
query='lastTimeslice'
>
<div className={className}>
{info?.lastTimeslice || '-'}
{children}
</BrokerStatus>
);
</div>);
}

export default React.memo(Timeslice);
Loading