Display Basic Chain Info, Apps, API, and Metadata in Settings (#11584)

* feat(page-settings): add runtime version and current block

* feat(page-settings): add SystemVersion component to display node, API and apps versions

* style: enhance responsive design for table layout

* refactor(apps-config): move packageInfo export to ui

* refactor(apps-config): centralize apps version as getPackageVersion utility fn

* refactor: optimize apps version retrieval in NodeInfo and SystemVersion components

---------

Co-authored-by: Arjun Porwal <porwalarjun95@gmail.com>
This commit is contained in:
rajk93 2025-05-28 21:55:54 +05:30 committed by GitHub
parent d3c695e675
commit c4c36e62e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 141 additions and 8 deletions

View File

@ -1,6 +1,7 @@
// Copyright 2017-2025 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { packageInfo } from '../packageInfo.js';
import { identityNodes, identitySpec } from './identityIcons/index.js';
import { sanitize } from './util.js';
@ -11,3 +12,7 @@ export function getSystemIcon (systemName: string, specName: string): 'beachball
'substrate'
) as 'substrate';
}
export function getPackageVersion () {
return `apps v${packageInfo.version.replace('-x', '')}`;
}

View File

@ -5,13 +5,12 @@ import type { BareProps as Props } from '@polkadot/react-components/types';
import React from 'react';
import { getPackageVersion } from '@polkadot/apps-config';
import { styled } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { NodeName, NodeVersion } from '@polkadot/react-query';
import { packageInfo } from '../packageInfo.js';
const uiInfo = `apps v${packageInfo.version.replace('-x', '')}`;
const appsVersion = getPackageVersion();
function NodeInfo ({ className = '' }: Props): React.ReactElement<Props> {
const { api, isApiReady } = useApi();
@ -25,7 +24,7 @@ function NodeInfo ({ className = '' }: Props): React.ReactElement<Props> {
</div>
)}
<div>{api.libraryInfo.replace('@polkadot/', '')}</div>
<div>{uiInfo}</div>
<div>{appsVersion}</div>
</StyledDiv>
);
}

View File

@ -1,13 +1,15 @@
// Copyright 2017-2025 @polkadot/app-settings authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { BlockNumber, RuntimeVersion } from '@polkadot/types/interfaces';
import type { NetworkSpecsStruct } from '@polkadot/ui-settings/types';
import type { ChainInfo, ChainType } from '../types.js';
import React, { useCallback, useEffect, useReducer, useRef, useState } from 'react';
import { ChainImg, Input, QrNetworkSpecs, Spinner, styled, Table } from '@polkadot/react-components';
import { useApi, useDebounce } from '@polkadot/react-hooks';
import { useApi, useCall, useDebounce } from '@polkadot/react-hooks';
import { formatNumber } from '@polkadot/util';
import { useTranslation } from '../translate.js';
import ChainColorIndicator from './ChainColorIndicator.js';
@ -45,9 +47,11 @@ const initialState = {
function NetworkSpecs ({ chainInfo, className }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { isApiReady, systemChain } = useApi();
const { api, isApiReady, systemChain } = useApi();
const [qrData, setQrData] = useState<NetworkSpecsStructWithType>(initialState);
const debouncedQrData = useDebounce(qrData, 500);
const runtimeVersion = useCall<RuntimeVersion>(isApiReady && api.rpc.state.subscribeRuntimeVersion);
const blockNumber = useCall<BlockNumber>(isApiReady && api.derive.chain.bestNumber);
const reducer = (state: NetworkSpecsStructWithType, delta: Partial<NetworkSpecsStructWithType>): NetworkSpecsStructWithType => {
const newState = {
@ -107,7 +111,6 @@ function NetworkSpecs ({ chainInfo, className }: Props): React.ReactElement<Prop
empty={t('No open tips')}
header={headerRef.current}
>
<tr>
<td>
<div className='settings--networkSpecs-name'>
@ -120,7 +123,7 @@ function NetworkSpecs ({ chainInfo, className }: Props): React.ReactElement<Prop
<ChainImg className='settings--networkSpecs-logo' />
</div>
</td>
<td rowSpan={7}>
<td rowSpan={9}>
{qrData.genesisHash && (
<QrNetworkSpecs
className='settings--networkSpecs-qr'
@ -205,6 +208,26 @@ function NetworkSpecs ({ chainInfo, className }: Props): React.ReactElement<Prop
/>
</td>
</tr>
<tr>
<td>
<Input
className='full'
isDisabled
label={t('Runtime Version')}
value={runtimeVersion ? `${runtimeVersion.specName.toString()}/${runtimeVersion.specVersion.toNumber()}` : ''}
/>
</td>
</tr>
<tr>
<td>
<Input
className='full'
isDisabled
label={t('Current Block')}
value={blockNumber ? formatNumber(blockNumber) : ''}
/>
</td>
</tr>
</StyledTable>
);
}
@ -219,6 +242,15 @@ const StyledTable = styled(Table)`
}
}
@media (max-width: 900px) {
tr {
&:first-child {
display: flex;
flex-direction: column;
}
}
}
.settings--networkSpecs-name {
position: relative;

View File

@ -0,0 +1,95 @@
// Copyright 2017-2025 @polkadot/app-settings authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { BareProps as Props } from '@polkadot/react-components/types';
import React, { useRef } from 'react';
import { getPackageVersion } from '@polkadot/apps-config';
import { Input, Spinner, styled, Table } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { useTranslation } from '../translate.js';
const appsVersion = getPackageVersion();
function SystemVersion ({ className }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api, isApiReady, systemName, systemVersion } = useApi();
const headerRef = useRef<[React.ReactNode?, string?, number?][]>([
[t('system version'), 'start', 2]
]);
if (!isApiReady) {
return <Spinner />;
}
return (
<StyledTable
className={className}
empty={t('No version information available')}
header={headerRef.current}
>
<tr>
<td>
<Input
className='full'
isDisabled
label={t('Node version')}
value={systemName + ' v' + systemVersion}
/>
</td>
</tr>
<tr>
<td>
<Input
className='full'
isDisabled
label={t('API Version')}
value={`${api.libraryInfo.replace('@polkadot/api ', '')}`}
/>
</td>
</tr>
<tr>
<td>
<Input
className='full'
isDisabled
label={t('Apps Version')}
value={`${appsVersion.replace('apps ', '')}`}
/>
</td>
</tr>
</StyledTable>
);
}
const StyledTable = styled(Table)`
td {
padding: 0;
text-align: left;
.input.ui--Input input {
border: none !important;
background: transparent;
padding: 0;
margin-left: 0;
}
.ui--Labelled-content .ui.input > input {
padding-left: 0 !important;
}
.ui--Labelled:not(.isSmall) {
padding-left: 0;
}
.ui--Labelled > label, .ui--Labelled > .ui--Labelled-content {
left: 0 !important;
padding-left: 0;
}
}
`;
export default React.memo(SystemVersion);

View File

@ -9,6 +9,7 @@ import useChainInfo from '../useChainInfo.js';
import useRawMetadata from '../useRawMetadata.js';
import Extensions from './Extensions.js';
import NetworkSpecs from './NetworkSpecs.js';
import SystemVersion from './SystemVersion.js';
export default function Metadata (): React.ReactElement {
const { isDevelopment } = useApi();
@ -24,6 +25,7 @@ export default function Metadata (): React.ReactElement {
/>
)}
<NetworkSpecs chainInfo={chainInfo} />
<SystemVersion />
</>
);
}