diff --git a/src/containers/Network/UpgradeStatus.tsx b/src/containers/Network/UpgradeStatus.tsx index b5a6d77c4..e88c8f763 100644 --- a/src/containers/Network/UpgradeStatus.tsx +++ b/src/containers/Network/UpgradeStatus.tsx @@ -124,18 +124,19 @@ export const aggregateData = ( * (https://data.xrpl.org/v1/network/topology/nodes) * * Node versions often come in in this format: - * rippled-[version]-[release (optional)]+[rippled hash (optional)] + * (rippled|xrpld)-[version]-[release (optional)]+[hash (optional)] * Output format: * [version]-[release (optional)] * e.g. rippled-1.9.4+ba3c0e51455a88d76d90b996f20c0f102ac3f5a0.DEBUG should returns 1.9.4 * rippled-1.9.4-b1 should returns 1.9.4-b1 + * xrpld-3.2.0 should returns 3.2.0 * * @param version - The version retrieved from source data. * @returns - The correct version format. */ -const handleNodeVersion = (version: string | undefined) => { +export const handleNodeVersion = (version: string | undefined) => { let cleanedVersion = version - if (version?.startsWith('rippled')) + if (version?.startsWith('rippled') || version?.startsWith('xrpld')) cleanedVersion = `${version.split('-').slice(1).join('-')}` if (version?.includes('+')) cleanedVersion = `${cleanedVersion?.split('+')[0]}` diff --git a/src/containers/Network/test/upgradeStatus.test.js b/src/containers/Network/test/upgradeStatus.test.js index 5ba7a14fa..0d7b026c1 100644 --- a/src/containers/Network/test/upgradeStatus.test.js +++ b/src/containers/Network/test/upgradeStatus.test.js @@ -12,6 +12,7 @@ import { aggregateData, aggregateNodes, aggregateValidators, + handleNodeVersion, } from '../UpgradeStatus' import { UPGRADE_STATUS_ROUTE } from '../../App/routes' @@ -77,6 +78,38 @@ const nodesData = [ }, ] +describe('handleNodeVersion', () => { + it('strips the rippled- prefix', () => { + expect(handleNodeVersion('rippled-3.1.3')).toEqual('3.1.3') + }) + + it('strips the xrpld- prefix', () => { + expect(handleNodeVersion('xrpld-3.2.0')).toEqual('3.2.0') + }) + + it('preserves the release suffix', () => { + expect(handleNodeVersion('xrpld-3.2.0-b7')).toEqual('3.2.0-b7') + expect(handleNodeVersion('rippled-1.9.4-b1')).toEqual('1.9.4-b1') + }) + + it('strips the build hash after +', () => { + expect( + handleNodeVersion( + 'xrpld-3.3.0-b0+9af4fb521e169c056f9eff16779195b7146e8f92.DEBUG', + ), + ).toEqual('3.3.0-b0') + expect( + handleNodeVersion( + 'rippled-1.9.4+ba3c0e51455a88d76d90b996f20c0f102ac3f5a0.DEBUG', + ), + ).toEqual('1.9.4') + }) + + it('leaves an already-clean version untouched', () => { + expect(handleNodeVersion('3.2.0')).toEqual('3.2.0') + }) +}) + describe('UpgradeStatus test functions', () => { it('aggregate data works with validators without keys', () => { const validatorAggregate = aggregateValidators(undefinedValidatorsData)