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 Sale UI #11091

Merged
merged 21 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8a66802
added sales tab
piggydoughnut Nov 13, 2024
3224f74
draft for the progress bar
piggydoughnut Nov 13, 2024
1eef2e8
draft for calculating values for the coretime progress timeline
piggydoughnut Nov 14, 2024
a66a409
lint
piggydoughnut Nov 14, 2024
d69054c
added historical data on sales, button to see transactions on subscan
piggydoughnut Nov 19, 2024
2ca3e37
breaking down utils file logically
piggydoughnut Dec 10, 2024
fba3d70
improving calculations of phase configuration, sale details, etc
piggydoughnut Dec 10, 2024
86cd145
lint
piggydoughnut Dec 10, 2024
6910751
correctly calculated sale start/end blocks, dates and ts
piggydoughnut Dec 11, 2024
2f6abed
added core price calculation
piggydoughnut Dec 11, 2024
d35ff08
chainName type, adjustments for westend and paseo
piggydoughnut Dec 11, 2024
54c4090
ts fixes
piggydoughnut Dec 11, 2024
dce5cd2
used helper funcitons for getting relay blocks
piggydoughnut Dec 11, 2024
f73cf98
moved functionality to a new helper
piggydoughnut Dec 11, 2024
9d43169
Merge branch 'master' into dm-coretime-ui-sale
piggydoughnut Dec 27, 2024
8f361ef
Merge branch 'master' into dm-coretime-ui-sale
piggydoughnut Dec 27, 2024
1152ef7
moved constants from types file in react-hooks, page-broker, page-cor…
piggydoughnut Dec 27, 2024
a679d21
added dynamic coretime constants, wrapped page coretime in a context …
piggydoughnut Dec 28, 2024
3a0c51b
moved coretime constants to a separate hook for reusability
piggydoughnut Dec 28, 2024
3629e48
removed coretime consts and added useCoretimeConsts in page-broker
piggydoughnut Dec 28, 2024
f649e51
passing a correct block number for coretime price calculation
piggydoughnut Dec 28, 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
43 changes: 22 additions & 21 deletions packages/page-coretime/src/Overview/Summary.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
// Copyright 2017-2024 @polkadot/app-coretime authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { ApiPromise } from '@polkadot/api';
import type { BrokerStatus, CoreDescription, PalletBrokerConfigRecord, PalletBrokerSaleInfoRecord, RegionInfo } from '@polkadot/react-hooks/types';
import type { ChainName } from '../types.js';

import React, { useMemo } from 'react';

import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { useCall } from '@polkadot/react-hooks';
import { BN } from '@polkadot/util';

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

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

function Summary ({ api, config, parachainCount, saleInfo, status }: Props): React.ReactElement<Props> {
function Summary ({ chainName, config, parachainCount, saleInfo, status }: Props): React.ReactElement<Props> {
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 - FirstCycleStart[chainName]) / config.regionLength)
, [currentRegionEnd, chainName, config]);
const cycleNumber = useMemo(() => {
if (chainName && currentRegionEnd) {
return Math.floor(
(currentRegionEnd - FirstCycleStart.timeslice.coretime[chainName]) / config.regionLength
);
}

return undefined;
}, [currentRegionEnd, chainName, config]);

return (
<SummaryBox>
<section>
<CardSummary label={t('timeslice')}>
{status?.lastTimeslice}
</CardSummary>
<CardSummary label={t('cores sold')}>
{`${saleInfo?.coresSold} / ${saleInfo?.coresOffered}`}
</CardSummary>
<CardSummary label={t('parachains')}>
{parachainCount && parachainCount}
</CardSummary>
{status &&
<CardSummary label={t('cycle number')}>
<CardSummary label={t('sale number')}>
<div>
{cycleNumber}
</div>
</CardSummary>
}
<CardSummary label={t('timeslice')}>
{status?.lastTimeslice}
</CardSummary>
<CardSummary label={t('parachains')}>
{parachainCount && parachainCount}
</CardSummary>
{config && status &&
<CardSummary
className='media--800'
Expand All @@ -69,8 +70,8 @@ function Summary ({ api, config, parachainCount, saleInfo, status }: Props): Rea
{status &&
(<CardSummary 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 style={{ fontSize: '14px' }}>{estimateTime(currentRegionStart, get.blocks.relay(status?.lastTimeslice))}</div>
<div style={{ fontSize: '14px' }}>{estimateTime(currentRegionEnd, get.blocks.relay(status?.lastTimeslice))}</div>
</div>
</CardSummary>)
}
Expand Down
40 changes: 40 additions & 0 deletions packages/page-coretime/src/Overview/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2017-2024 @polkadot/app-coretime authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { CoretimeInformation } from '@polkadot/react-hooks/types';
import type { ChainName } from '../types.js';

import React from 'react';

import ParachainsTable from '../ParachainsTable.js';
import Summary from './Summary.js';

interface Props {
className?: string;
coretimeInfo: CoretimeInformation
chainName: ChainName
}

function Overview ({ chainName, className, coretimeInfo }: Props): React.ReactElement<Props> {
return (
<main className={className}>
{coretimeInfo && (
<Summary
chainName={chainName}
config={coretimeInfo?.config}
parachainCount={coretimeInfo.taskIds?.length || 0}
region={coretimeInfo?.region}
saleInfo={coretimeInfo?.salesInfo}
status={coretimeInfo?.status}
/>
)}
{!!coretimeInfo &&
<ParachainsTable
coretimeInfo={coretimeInfo}
/>
}
</main>
);
}

export default React.memo(Overview);
1 change: 1 addition & 0 deletions packages/page-coretime/src/ParachainsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function ParachainsTable ({ coretimeInfo }: Props): React.ReactElement<Props> {
header={headerRef.current}
isSplit={false}
>

{coretimeInfo?.taskIds?.map((taskId: number) => {
const chain = coretimeInfo.chainInfo[taskId];

Expand Down
6 changes: 3 additions & 3 deletions packages/page-coretime/src/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { ParaLink, styled, Tag } from '@polkadot/react-components';
import { ChainRenewalStatus } from '@polkadot/react-hooks/types';
import { BN, formatBalance, formatNumber } from '@polkadot/util';

import { estimateTime, get } from './utils/index.js';
import { CoreTimeTypes } from './types.js';
import { estimateTime } from './utils.js';

interface Props {
id: number
Expand Down Expand Up @@ -57,11 +57,11 @@ function Row ({ chainRecord, highlight = false, id, lastCommittedTimeslice, leas
<StyledCell
$p={highlight}
className='media--800'
>{showEstimates && formatNumber(targetTimeslice * 80).toString()}</StyledCell>
>{showEstimates && formatNumber(get.blocks.relay(targetTimeslice)).toString()}</StyledCell>
<StyledCell
$p={highlight}
className='media--1000'
>{showEstimates && estimateTime(targetTimeslice, lastCommittedTimeslice * 80)}</StyledCell>
>{showEstimates && estimateTime(targetTimeslice, get.blocks.relay(lastCommittedTimeslice))}</StyledCell>
<StyledCell
$p={highlight}
className='media--1200'
Expand Down
51 changes: 51 additions & 0 deletions packages/page-coretime/src/Sale/SaleTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2017-2024 @polkadot/app-coretime authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { SaleDetails } from '../types.js';

import React, { useRef } from 'react';

import { Table } from '@polkadot/react-components';

import { useTranslation } from '../translate.js';

interface Props {
saleDetails: SaleDetails
}

function SaleTable ({ saleDetails }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
[],
[t('Dates'), 'start media--800'],
[t('Blocks (relay)'), 'start'],
[t('Blocks(coretime)'), 'start'],
[t('Timeslices'), 'start']
]);

return (
<Table
emptySpinner={false}
header={headerRef.current}
isSplit={false}
>
<tr>
<td>Start</td>
<td>{saleDetails.date.start}</td>
<td>{saleDetails.relay.start.block}</td>
<td>{saleDetails.coretime.start.block}</td>
<td>{saleDetails.relay.start.ts}</td>
</tr>
<tr>
<td>End</td>
<td>{saleDetails.date.end}</td>
<td>{saleDetails.relay.end.block}</td>
<td>{saleDetails.coretime.end.block}</td>
<td>{saleDetails.relay.end.ts}</td>
</tr>

</Table>
);
}

export default React.memo(SaleTable);
86 changes: 86 additions & 0 deletions packages/page-coretime/src/Sale/Summary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright 2017-2024 @polkadot/app-coretime authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { ApiPromise } from '@polkadot/api';
import type { BrokerStatus, CoreDescription, PalletBrokerConfigRecord, PalletBrokerSaleInfoRecord, RegionInfo } from '@polkadot/react-hooks/types';

import React from 'react';

import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { BN, formatNumber } from '@polkadot/util';

import { useTranslation } from '../translate.js';
import { estimateTime, get, getCurrentRegionStartEndTs } from '../utils/index.js';

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

function Summary ({ config, cycleNumber, saleInfo, status }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { currentRegionEnd, currentRegionStart } = getCurrentRegionStartEndTs(saleInfo, config.regionLength);

return (
<SummaryBox>
<section>
{status &&
<CardSummary label={t('sale number')}>
<div>
{cycleNumber > -1 ? cycleNumber : '-'}
</div>
</CardSummary>
}
<CardSummary label={t('sold/offered')}>
{`${saleInfo?.coresSold} / ${saleInfo?.coresOffered}`}
</CardSummary>
<CardSummary label={t('sale end')}>
<div>{estimateTime(currentRegionEnd, get.blocks.relay(status?.lastTimeslice))}</div>
</CardSummary>
<CardSummary label={t('last block')}>
<div>{formatNumber(get.blocks.relay(currentRegionEnd))}</div>
</CardSummary>
<CardSummary label={t('last timeslice')}>
<div>{formatNumber(currentRegionEnd)}</div>
</CardSummary>
{config && status &&
<CardSummary
className='media--800'
label={t('sale progress')}
progress={{
isBlurred: false,
total: new BN(config?.regionLength),
value: new BN(config?.regionLength - (currentRegionEnd - status.lastTimeslice)),
withTime: false
}}
/>
}
</section>
<section className='media--1200'>
{status &&
(<CardSummary label={t('cycle dates')}>
<div>
<div style={{ fontSize: '14px' }}>{estimateTime(currentRegionStart, get.blocks.relay(status?.lastTimeslice))}</div>
<div style={{ fontSize: '14px' }}>{estimateTime(currentRegionEnd, get.blocks.relay(status?.lastTimeslice))}</div>
</div>
</CardSummary>)
}
{status &&
<CardSummary label={t('cycle ts')}>
<div>
<div style={{ fontSize: '14px' }}>{currentRegionStart}</div>
<div style={{ fontSize: '14px' }}>{currentRegionEnd}</div>
</div>
</CardSummary>
}
</section>
</SummaryBox>
);
}

export default React.memo(Summary);
Loading
Loading