Skip to content

Commit 94060db

Browse files
committed
adding
1 parent b00a330 commit 94060db

File tree

3 files changed

+56
-19
lines changed

3 files changed

+56
-19
lines changed

src/app/[network]/(App)/paraId/ParaIdFetch2.tsx

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import GeneralTableWithButtons from '@/components/table/GeneralTableWithButtons'
44
import WalletStatus from '@/components/walletStatus/WalletStatus'
55
import { network_list } from '@/config/network'
66
import { ParachainInfo, ParachainState } from '@/hooks/useParachainInfo'
7+
import { useCurrentRelayBlockNumber } from '@/hooks/useSubstrateQuery'
8+
import { blocksToTimeFormat } from '@/utils/broker/blockTime'
79
import { useInkathon } from '@poppyseed/lastic-sdk'
810
import { ChangeEvent, useState } from 'react'
911

@@ -14,14 +16,30 @@ const statusColors = {
1416
Reserved: 'bg-red-200',
1517
Onboarding: 'bg-purple-200',
1618
Parathread: 'bg-indigo-200',
17-
'Idle(In workplan)': 'bg-pink-200',
19+
'Idle - In workplan': 'bg-pink-200',
1820
'Holding Slot': 'bg-orange-200',
1921
}
2022

23+
const statusDescriptions = {
24+
'System Chain':
25+
'A system chain is the main chain of a blockchain network, responsible for its core functionality.',
26+
'Currently Active':
27+
'An active parachain is currently producing blocks and participating in the relay chain.',
28+
'Idle Chain': 'An idle chain is not currently active or producing blocks.',
29+
Reserved: 'Reserved parachains have slots that are reserved but not yet active.',
30+
Onboarding: 'Parachains that are currently in the process of onboarding to the network.',
31+
Parathread:
32+
'Parathreads are parachains that are not continuously active but can participate in the network on demand.',
33+
'Idle - In workplan':
34+
'Idle parachains that are included in a work plan but are not currently active.',
35+
'Holding Slot': 'Parachains that hold a slot but are not actively producing blocks.',
36+
}
37+
2138
const ParaIdFetch = ({ parachains }: { parachains: ParachainInfo[] }) => {
22-
const { activeChain } = useInkathon()
39+
const { activeChain, relayApi } = useInkathon()
2340
const [filter, setFilter] = useState<string>('all')
2441
const [paraIdSET, setParaId] = useState<number | null>(null)
42+
const currentBlockNumber = useCurrentRelayBlockNumber(relayApi)
2543

2644
if (!activeChain) {
2745
return (
@@ -57,6 +75,7 @@ const ParaIdFetch = ({ parachains }: { parachains: ParachainInfo[] }) => {
5775
<button
5876
onClick={() => setFilter('all')}
5977
className={`px-4 py-2 rounded-full text-black dark:text-white ${filter === 'all' ? 'font-bold' : ''}`}
78+
title="Show all parachains"
6079
>
6180
All
6281
</button>
@@ -65,6 +84,7 @@ const ParaIdFetch = ({ parachains }: { parachains: ParachainInfo[] }) => {
6584
key={stateKey}
6685
onClick={() => setFilter(stateValue)}
6786
className={`px-4 py-2 rounded-full text-black ${statusColors[stateValue]} ${filter === stateValue ? 'font-bold' : ''}`}
87+
title={statusDescriptions[stateValue]}
6888
>
6989
{stateValue}
7090
</button>
@@ -74,17 +94,24 @@ const ParaIdFetch = ({ parachains }: { parachains: ParachainInfo[] }) => {
7494
{filteredParachains.length > 0 ? (
7595
<div className="w-full overflow-x-auto">
7696
<GeneralTableWithButtons
77-
tableData={filteredParachains.map(({ paraId, state, network }, idx) => ({
78-
data: [
79-
paraId.toString(),
80-
network_list[network]?.paraId[paraId.toString()]?.name,
81-
network_list[network]?.paraId[paraId.toString()]?.description,
82-
<span key={idx} className={`${statusColors[state]} px-4 py-1 rounded-full`}>
83-
{state}
84-
</span>,
85-
network_list[network]?.paraId[paraId.toString()]?.lease?.toString(),
86-
],
87-
}))}
97+
tableData={filteredParachains.map(({ paraId, state, network }, idx) => {
98+
const leaseEndBlock = network_list[network]?.paraId[paraId.toString()]?.lease
99+
const remainingBlocks =
100+
leaseEndBlock !== null && currentBlockNumber !== null
101+
? leaseEndBlock - currentBlockNumber
102+
: null
103+
return {
104+
data: [
105+
paraId.toString(),
106+
network_list[network]?.paraId[paraId.toString()]?.name,
107+
network_list[network]?.paraId[paraId.toString()]?.description,
108+
<span key={idx} className={`${statusColors[state]} px-4 py-1 rounded-full`}>
109+
{state}
110+
</span>,
111+
blocksToTimeFormat(remainingBlocks, 'RELAY'),
112+
],
113+
}
114+
})}
88115
tableHeader={[
89116
{ title: 'ParaId' },
90117
{ title: 'Name' },

src/hooks/useParachainInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export enum ParachainState {
2323
RESERVED = 'Reserved',
2424
ONBOARDING = 'Onboarding',
2525
ONDEMAND_PARACHAIN = 'Parathread',
26-
IN_WORKPLAN = 'Idle(In workplan)',
26+
IN_WORKPLAN = 'Idle - In workplan',
2727
LEASE_HOLDING = 'Holding Slot',
2828
}
2929

src/utils/broker/blockTime.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ export const getBlockTimestamp = async (
4040
* Use for future blocks only and approximations only.
4141
*/
4242
export const blocksToTimeFormat = (
43-
nbOfBlocks: number,
43+
nbOfBlocks: number | null,
4444
typeOfChain?: 'PARA' | 'RELAY' | 'LOCAL',
4545
): string => {
46+
if (!nbOfBlocks) {
47+
return '-'
48+
}
4649
let secondsPerBlock: number = 6 // Default value for relay chain
4750
if (typeOfChain === 'PARA') {
4851
secondsPerBlock = 12 // Parachain
@@ -53,13 +56,20 @@ export const blocksToTimeFormat = (
5356
}
5457

5558
const totalSeconds = nbOfBlocks * secondsPerBlock
56-
const days = Math.floor(totalSeconds / (24 * 3600))
57-
const hours = Math.floor((totalSeconds - days * 24 * 3600) / 3600)
59+
60+
const months = Math.floor(totalSeconds / (30 * 24 * 3600))
61+
const weeks = Math.floor((totalSeconds % (30 * 24 * 3600)) / (7 * 24 * 3600))
62+
const days = Math.floor((totalSeconds % (7 * 24 * 3600)) / (24 * 3600))
63+
const hours = Math.floor((totalSeconds % (24 * 3600)) / 3600)
5864
const minutes = Math.floor((totalSeconds % 3600) / 60)
5965
const seconds = totalSeconds % 60
6066

61-
if (days > 0) {
62-
return `${days} days ${hours} hours ${minutes} min ${seconds} sec`
67+
if (months > 0) {
68+
return `${months} months ${weeks} weeks ${days} days`
69+
} else if (weeks > 0) {
70+
return `${weeks} weeks ${days} days ${hours} hours`
71+
} else if (days > 0) {
72+
return `${days} days ${hours} hours ${minutes} min`
6373
} else if (hours > 0) {
6474
return `${hours} hours ${minutes} min ${seconds} sec`
6575
} else if (minutes > 0) {

0 commit comments

Comments
 (0)