From 01412736330f2530a61874b76025c940a172eded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Thu, 7 Apr 2022 08:58:33 +0200 Subject: [PATCH 1/2] [DDW-1072] Remove unused cpu parsing files --- .../renderer/app/utils/formatCpuInfo.spec.ts | 80 ------------------- source/renderer/app/utils/formatCpuInfo.ts | 46 ----------- 2 files changed, 126 deletions(-) delete mode 100644 source/renderer/app/utils/formatCpuInfo.spec.ts delete mode 100644 source/renderer/app/utils/formatCpuInfo.ts diff --git a/source/renderer/app/utils/formatCpuInfo.spec.ts b/source/renderer/app/utils/formatCpuInfo.spec.ts deleted file mode 100644 index 5e103086b0..0000000000 --- a/source/renderer/app/utils/formatCpuInfo.spec.ts +++ /dev/null @@ -1,80 +0,0 @@ -import formatCpuInfo from './formatCpuInfo'; - -describe('Formatters/formatCpuInfo', () => { - it('gives correct model name and clock speed for Intel format', () => { - expect( - formatCpuInfo([ - // @ts-ignore ts-migrate(2741) FIXME: Property 'times' is missing in type '{ model: stri... Remove this comment to see the full error message - { - model: 'Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz', - speed: 2600, - }, - ]) - ).toEqual('Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz'); - }); - it('gives correct model name and clock speed for AMD format', () => { - expect( - formatCpuInfo([ - // @ts-ignore ts-migrate(2741) FIXME: Property 'times' is missing in type '{ model: stri... Remove this comment to see the full error message - { - model: 'AMD Ryzen 7 3700U with Radeon Vega Mobile Gfx', - speed: 2400, - }, - ]) - ).toEqual('AMD Ryzen 7 3700U with Radeon Vega Mobile Gfx @ 2.40GHz'); - }); - it('removes all unnecessary whitespace characters', () => { - expect( - formatCpuInfo([ - // @ts-ignore ts-migrate(2741) FIXME: Property 'times' is missing in type '{ model: stri... Remove this comment to see the full error message - { - model: ' Super Fast NextGen\tProcessor ', - speed: 1000, - }, - ]) - ).toEqual('Super Fast NextGen Processor @ 1.00GHz'); - }); - it('returns empty string if there is no any thread data present', () => { - expect(formatCpuInfo([])).toEqual(''); - }); - it('returns empty string if there is no model property present', () => { - expect( - formatCpuInfo([ - // @ts-ignore ts-migrate(2739) FIXME: Type '{ speed: number; }' is missing the following... Remove this comment to see the full error message - { - speed: 1000, - }, - ]) - ).toEqual(''); - }); - it('returns model name if there is no speed property present', () => { - expect( - formatCpuInfo([ - // @ts-ignore ts-migrate(2739) FIXME: Type '{ model: string; }' is missing the following... Remove this comment to see the full error message - { - model: 'Model name', - }, - ]) - ).toEqual('Model name'); - }); - it('returns parsed model if there is no speed property present but the model property contains speed expressed in GHz', () => { - expect( - formatCpuInfo([ - // @ts-ignore ts-migrate(2739) FIXME: Type '{ model: string; }' is missing the following... Remove this comment to see the full error message - { - model: 'Model name @ 0.5 GHz', - }, - ]) - ).toEqual('Model name @ 0.50GHz'); - }); - it('returns model name if there is no speed property present and neither speed correctly expressed in the model', () => { - expect( - formatCpuInfo([ - // @ts-ignore ts-migrate(2739) FIXME: Type '{ model: string; }' is missing the following... Remove this comment to see the full error message - { - model: 'Model name @ 1 MHz', - }, - ]) - ).toEqual('Model name'); - }); -}); diff --git a/source/renderer/app/utils/formatCpuInfo.ts b/source/renderer/app/utils/formatCpuInfo.ts deleted file mode 100644 index 04511145e5..0000000000 --- a/source/renderer/app/utils/formatCpuInfo.ts +++ /dev/null @@ -1,46 +0,0 @@ -import type { - Cpu, - CpuThreadData, -} from '../../../common/types/environment.types'; -import { formattedNumber } from './formatters'; - -type FormatArgs = { - modelName: string; - speedValue: string; -}; - -const format = ({ modelName, speedValue }: FormatArgs) => - `${modelName} @ ${speedValue}GHz`; - -const formatCpuInfo = (cpu: Cpu): string => { - const { model, speed } = cpu?.[0] || ({} as CpuThreadData); - if (!model) return ''; - const [modelName, modelSpeedSection] = model - .split('@') - .map((stringPart) => stringPart.trim().replace(/\s+/g, ' ')); - - if (speed) { - const speedValue = formattedNumber(speed / 1000, 2); - return format({ - modelName, - speedValue, - }); - } - - const modelSpeedSectionExpressedInGHz = !!modelSpeedSection?.match(/GHz/); - - if (!modelSpeedSection && !modelSpeedSectionExpressedInGHz) { - return modelName; - } - - const rawSpeedValue = modelSpeedSection.match(/([\d,.]+)\s*GHz/)?.[1]; - const parsedSpeedValue = parseFloat(rawSpeedValue); - if (!parsedSpeedValue) return modelName; - const speedValue = formattedNumber(parsedSpeedValue, 2); - return format({ - modelName, - speedValue, - }); -}; - -export default formatCpuInfo; From b31b4083e21382eca0099bf9782ceb68e4d96b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Thu, 7 Apr 2022 11:08:42 +0200 Subject: [PATCH 2/2] [DDW-1072] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f57bff07b4..34f9ecb232 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ ### Chores +- Removed unused files ([PR 2950](https://github.com/input-output-hk/daedalus/pull/2950)) - Fixed Daedalus menu in Storybook used for theme and language selection ([PR 2886](https://github.com/input-output-hk/daedalus/pull/2886)) ## 4.9.0-FC1