|
| 1 | +import Border from '@/components/border/Border' |
| 2 | +import NumberField from '@/components/inputField/NumberField' |
| 3 | +import GeneralTableWithButtons from '@/components/table/GeneralTableWithButtons' |
| 4 | +import WalletStatus from '@/components/walletStatus/WalletStatus' |
| 5 | +import { network_list } from '@/config/network' |
| 6 | +import { ParachainInfo, ParachainState } from '@/hooks/useParachainInfo' |
| 7 | +import { useCurrentRelayBlockNumber } from '@/hooks/useSubstrateQuery' |
| 8 | +import { blocksToTimeFormat } from '@/utils/broker/blockTime' |
| 9 | +import { useInkathon } from '@poppyseed/lastic-sdk' |
| 10 | +import { ChangeEvent, useState } from 'react' |
| 11 | + |
| 12 | +const statusColors = { |
| 13 | + 'System Chain': 'bg-blue-200', |
| 14 | + 'Currently Active': 'bg-green-200', |
| 15 | + 'Idle Chain': 'bg-yellow-200', |
| 16 | + Reserved: 'bg-red-200', |
| 17 | + Onboarding: 'bg-purple-200', |
| 18 | + Parathread: 'bg-indigo-200', |
| 19 | + 'Idle - In workplan': 'bg-pink-200', |
| 20 | + 'Holding Slot': 'bg-orange-200', |
| 21 | +} |
| 22 | + |
| 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 | + |
| 38 | +const ParaIdFetch = ({ parachains }: { parachains: ParachainInfo[] }) => { |
| 39 | + const { activeChain, relayApi } = useInkathon() |
| 40 | + const [filter, setFilter] = useState<string>('all') |
| 41 | + const [paraIdSET, setParaId] = useState<number | null>(null) |
| 42 | + const currentBlockNumber = useCurrentRelayBlockNumber(relayApi) |
| 43 | + |
| 44 | + if (!activeChain) { |
| 45 | + return ( |
| 46 | + <Border className="h-full flex flex-row justify-center items-center"> |
| 47 | + <WalletStatus /> |
| 48 | + </Border> |
| 49 | + ) |
| 50 | + } |
| 51 | + |
| 52 | + const handleParaIdChange = (e: ChangeEvent<HTMLInputElement>) => { |
| 53 | + const value = e.target.value |
| 54 | + setParaId(value ? parseFloat(value) : null) |
| 55 | + } |
| 56 | + |
| 57 | + const filteredParachains = parachains.filter((parachain) => { |
| 58 | + const matchesFilter = filter === 'all' || parachain.state === filter |
| 59 | + const matchesParaId = paraIdSET === null || parachain.paraId === paraIdSET |
| 60 | + return matchesFilter && matchesParaId |
| 61 | + }) |
| 62 | + |
| 63 | + return ( |
| 64 | + <Border className="h-full flex flex-row justify-center items-center"> |
| 65 | + <div className="h-full w-full flex flex-col justify-start items-start p-10"> |
| 66 | + <h1 className="text-xl font-bold uppercase mb-5">Status of {filter} cores</h1> |
| 67 | + <div className="grid grid-cols-3 gap-10 items-start"> |
| 68 | + <NumberField |
| 69 | + label="ParaId" |
| 70 | + value={paraIdSET !== null ? paraIdSET.toString() : ''} |
| 71 | + onChange={handleParaIdChange} |
| 72 | + className="mb-5" |
| 73 | + /> |
| 74 | + <div className="flex flex-wrap col-span-2 gap-3 mb-5"> |
| 75 | + <button |
| 76 | + onClick={() => setFilter('all')} |
| 77 | + className={`px-4 py-2 rounded-full text-black dark:text-white ${filter === 'all' ? 'font-bold' : ''}`} |
| 78 | + title="Show all parachains" |
| 79 | + > |
| 80 | + All |
| 81 | + </button> |
| 82 | + {Object.entries(ParachainState).map(([stateKey, stateValue]) => ( |
| 83 | + <button |
| 84 | + key={stateKey} |
| 85 | + onClick={() => setFilter(stateValue)} |
| 86 | + className={`px-4 py-2 rounded-full text-black ${statusColors[stateValue]} ${filter === stateValue ? 'font-bold' : ''}`} |
| 87 | + title={statusDescriptions[stateValue]} |
| 88 | + > |
| 89 | + {stateValue} |
| 90 | + </button> |
| 91 | + ))} |
| 92 | + </div> |
| 93 | + </div> |
| 94 | + {filteredParachains.length > 0 ? ( |
| 95 | + <div className="w-full overflow-x-auto"> |
| 96 | + <GeneralTableWithButtons |
| 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 | + })} |
| 115 | + tableHeader={[ |
| 116 | + { title: 'ParaId' }, |
| 117 | + { title: 'Name' }, |
| 118 | + { title: 'Description' }, |
| 119 | + { title: 'Status' }, |
| 120 | + { title: 'Lease Period' }, |
| 121 | + ]} |
| 122 | + colClass="grid-cols-5" |
| 123 | + /> |
| 124 | + </div> |
| 125 | + ) : ( |
| 126 | + <p>No data available.</p> |
| 127 | + )} |
| 128 | + </div> |
| 129 | + </Border> |
| 130 | + ) |
| 131 | +} |
| 132 | + |
| 133 | +export default ParaIdFetch |
0 commit comments