Skip to content

Commit

Permalink
fix(suite): enforce that the Security Check List icon is NOT just a s…
Browse files Browse the repository at this point in the history
…tring (#16709)
  • Loading branch information
vojtatranta authored Jan 30, 2025
1 parent bc14291 commit 5d28e7b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { selectSuiteFlags } from 'src/reducers/suite/suiteReducer';

import { DeviceAuthenticity } from './DeviceAuthenticity';
import { SecurityChecklist } from './SecurityChecklist';
import { SecurityChecklistItem } from './types';

const StyledCard = styled(CollapsibleOnboardingCard)`
max-width: 840px;
Expand Down Expand Up @@ -90,15 +91,15 @@ const TooltipWrapper = styled.span`

const firmwareInstalledChecklist = [
{
icon: 'info',
icon: <Icon size={24} name="info" />,
content: <Translation id="TR_ONBOARDING_DEVICE_CHECK_4" />,
},
] as const;
] as const satisfies SecurityChecklistItem[];

const getNoFirmwareChecklist = (isMobileLayout: boolean) =>
[
{
icon: 'verified',
icon: <Icon size={24} name="verified" />,
content: (
<Translation
id="TR_ONBOARDING_DEVICE_CHECK_2"
Expand All @@ -118,7 +119,7 @@ const getNoFirmwareChecklist = (isMobileLayout: boolean) =>
),
},
{
icon: 'hologram',
icon: <Icon size={24} name="hologram" />,
content: (
<Translation
id="TR_ONBOARDING_DEVICE_CHECK_1"
Expand All @@ -139,10 +140,10 @@ const getNoFirmwareChecklist = (isMobileLayout: boolean) =>
),
},
{
icon: 'package',
icon: <Icon size={24} name="package" />,
content: <Translation id="TR_ONBOARDING_DEVICE_CHECK_3" />,
},
] as const;
] as const satisfies SecurityChecklistItem[];

type SecurityCheckContentProps = {
goToDeviceAuthentication: () => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Icon } from '@trezor/components';

import { SecurityChecklistItem } from '../types';

describe('SecurityChecklistItem', () => {
describe('type tests', () => {
it("should not accept icon: 'string' as an icon prop", () => {
const x: SecurityChecklistItem = {
// @ts-expect-error: this should correctly throw a TS error - it cannot be a string
icon: 'string',
content: <div />,
};

expect(x).toBeTruthy();
});

it('should accept icon: ReactElement<<Icon />> as an icon prop', () => {
const x: SecurityChecklistItem = {
icon: <Icon name="hologram" />,
content: <div />,
};

expect(x).toBeTruthy();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ReactNode } from 'react';
import { ReactElement, ReactNode } from 'react';

import { Icon, IconProps } from '@trezor/components';

export type SecurityChecklistItem = {
icon: ReactNode;
icon: ReactElement<IconProps, typeof Icon>;
content: ReactNode;
subtitle?: ReactNode;
};

0 comments on commit 5d28e7b

Please sign in to comment.