// Copyright 2017-2026 @pezkuwi/app-coretime authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { FlagColor } from '@pezkuwi/react-components/types'; import type { ChainWorkTaskInformation, LegacyLease } from '@pezkuwi/react-hooks/types'; import type { RelayName } from './types.js'; import React from 'react'; import { MarkWarning, ParaLink, styled, Tag } from '@pezkuwi/react-components'; import { ParaLinkType } from '@pezkuwi/react-components/ParaLink'; import { ChainRenewalStatus, CoreTimeTypes } from '@pezkuwi/react-hooks/constants'; import { BN, formatBalance, formatNumber } from '@pezkuwi/util'; import { coretimeTypeColours, estimateTime } from './utils/index.js'; import { useCoretimeContext } from './CoretimeContext.js'; interface Props { id: number chainRecord: ChainWorkTaskInformation regionEnd: number regionBegin: number lastCommittedTimeslice: number lease: LegacyLease | undefined highlight?: boolean relayName: RelayName } interface StyledCellProps { $p: boolean; $width?: string; } const StyledCell = styled.td` && { background-color: ${({ $p }) => ($p ? '#F9FAFB' : undefined)}; width: ${({ $width }) => $width}; } height: 55px; `; const StyledMarkWarning = styled(MarkWarning)` width: fit-content; margin: 0; display: inline-block; vertical-align: middle; &.mark { margin: 0 0 0 1rem; display: inline; } `; const EXPIRES_IN_DAYS = 7; function Row ({ chainRecord, highlight = false, id, lastCommittedTimeslice, lease, regionBegin, regionEnd, relayName }: Props): React.ReactElement { // Group status checks const { renewalStatus } = chainRecord; const isRenewed = renewalStatus === ChainRenewalStatus.Renewed; const isEligible = renewalStatus === ChainRenewalStatus.Eligible; const chainRegionEnd = isRenewed ? regionEnd : regionBegin; const renewalLink = isEligible && ( Renew on RegionX ); const renewalValue = isRenewed ? chainRecord.renewalStatusMessage : (isEligible ? renewalLink : '-'); const targetTimeslice = lease?.until || chainRegionEnd; const showEstimates = !!targetTimeslice && Object.values(CoreTimeTypes)[chainRecord.type] !== CoreTimeTypes.Reservation; const { coretimeInfo, get } = useCoretimeContext(); const estimatedTime = showEstimates && get && coretimeInfo && estimateTime(targetTimeslice, get.blocks.relay(lastCommittedTimeslice), coretimeInfo?.constants?.relay); const isWithinWeek = !!estimatedTime && new Date(estimatedTime.timestamp).getTime() - Date.now() < EXPIRES_IN_DAYS * 24 * 60 * 60 * 1000; const isReservation = chainRecord.type === CoreTimeTypes.Reservation; return ( {id} {} {chainRecord?.workload?.core} {showEstimates && chainRecord?.lastBlock && relayName && {formatNumber(chainRecord?.lastBlock)} } {estimatedTime && estimatedTime?.formattedDate} {!!isWithinWeek && !isReservation && chainRecord?.renewalStatus !== ChainRenewalStatus.Renewed && ( )} {renewalValue} {chainRecord?.renewal ? formatBalance(chainRecord.renewal?.price.toString()) : ''} {
}
{highlight && }
); } export default React.memo(Row);