Skip to content

Commit

Permalink
feat: introduce internal_model UNKNOWN, add support for it in the Suite
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Dec 9, 2024
1 parent d10626c commit 7488355
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 16 deletions.
9 changes: 9 additions & 0 deletions packages/components/src/components/Image/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const SVG_IMAGES = {
UNI_SUCCESS: 'uni-success.svg',
UNI_WARNING: 'uni-warning.svg',
BRIDGE_CHECK_TREZOR_T2T1: 'bridge-check-trezor-t2t1.svg',
DEVICE_CONFIRM_TREZOR_UNKNOWN: 'trezor-unknown.svg',
DEVICE_CONFIRM_TREZOR_T1B1: 'device-confirm-trezor-t1b1.svg',
DEVICE_CONFIRM_TREZOR_T2T1: 'device-confirm-trezor-t2t1.svg',
DEVICE_CONFIRM_TREZOR_T2B1: 'device-confirm-trezor-t3b1.svg',
Expand Down Expand Up @@ -81,6 +82,8 @@ export const PNG_IMAGES = {
UNDERSTAND_2x: '[email protected]',
WALLET: 'wallet.png',
WALLET_2x: '[email protected]',
DONT_DISCONNECT_TREZOR_UNKNOWN: 'trezor-unknown.png',
DONT_DISCONNECT_TREZOR_UNKNOWN_2x: '[email protected]',
DONT_DISCONNECT_TREZOR_T2T1: 'dont-disconnect-trezor-t2t1.png',
DONT_DISCONNECT_TREZOR_T2T1_2x: '[email protected]',
DONT_DISCONNECT_TREZOR_T1B1: 'dont-disconnect-trezor-t1b1.png',
Expand All @@ -93,6 +96,8 @@ export const PNG_IMAGES = {
DONT_DISCONNECT_TREZOR_T3T1_2x: '[email protected]',
DONT_DISCONNECT_TREZOR_T3W1: 'dont-disconnect-trezor-t3w1.png',
DONT_DISCONNECT_TREZOR_T3W1_2x: '[email protected]',
TREZOR_UNKNOWN: 'trezor-unknown.png',
TREZOR_UNKNOWN_2x: '[email protected]',
TREZOR_T1B1: 'trezor-t1b1.png',
TREZOR_T1B1_2x: '[email protected]',
TREZOR_T2T1: 'trezor-t2t1.png',
Expand All @@ -105,6 +110,8 @@ export const PNG_IMAGES = {
TREZOR_T3T1_2x: '[email protected]',
TREZOR_T3W1: 'trezor-t3w1.png',
TREZOR_T3W1_2x: '[email protected]',
TREZOR_UNKNOWN_LARGE: 'trezor-unknown.png',
TREZOR_UNKNOWN_LARGE_2x: '[email protected]',
TREZOR_T1B1_LARGE: 'trezor-t1b1-large.png',
TREZOR_T1B1_LARGE_2x: '[email protected]',
TREZOR_T2T1_LARGE: 'trezor-t2t1-large.png',
Expand All @@ -117,6 +124,8 @@ export const PNG_IMAGES = {
TREZOR_T3T1_LARGE_2x: '[email protected]',
TREZOR_T3W1_LARGE: 'trezor-t3w1-large.png',
TREZOR_T3W1_LARGE_2x: '[email protected]',
TREZOR_UNKNOWN_GHOST: 'trezor-unknown.png',
TREZOR_UNKNOWN_GHOST_2x: '[email protected]',
TREZOR_T1B1_GHOST: 'trezor-t1b1-ghost.png',
TREZOR_T1B1_GHOST_2x: '[email protected]',
TREZOR_T2T1_GHOST: 'trezor-t2t1-ghost.png',
Expand Down
2 changes: 1 addition & 1 deletion packages/product-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export {
export { SearchAsset } from './components/SelectAssetModal/SearchAsset';
export { PassphraseTypeCard } from './components/PassphraseTypeCard/PassphraseTypeCard';
export { ConfirmOnDevice } from './components/ConfirmOnDevice/ConfirmOnDevice';
export { mapTrezorModelToIcon } from './utils/mapTrezorModelToIcon';
export { mapTrezorModelToIcon, mapTrezorModelToIconFilled } from './utils/mapTrezorModelToIcon';
export { RotateDeviceImage } from './components/RotateDeviceImage/RotateDeviceImage';
export { TrezorLogo } from './components/TrezorLogo/TrezorLogo';
export { PasswordStrengthIndicator } from './components/PasswordStrengthIndicator/PasswordStrengthIndicator';
Expand Down
15 changes: 14 additions & 1 deletion packages/product-components/src/utils/mapTrezorModelToIcon.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import { IconName } from '@trezor/components';
import { DeviceModelInternal } from '@trezor/connect';

export const mapTrezorModelToIcon: Record<DeviceModelInternal, IconName> = {
export const mapTrezorModelToIconFilled: Record<DeviceModelInternal, IconName> = {
[DeviceModelInternal.T1B1]: 'trezorModelOneFilled',
[DeviceModelInternal.T2T1]: 'trezorModelTFilled',
[DeviceModelInternal.T2B1]: 'trezorSafe3Filled',
[DeviceModelInternal.T3B1]: 'trezorSafe3Filled',
[DeviceModelInternal.T3T1]: 'trezorSafe5Filled',
[DeviceModelInternal.T3W1]: 'trezorSafe7Filled',

[DeviceModelInternal.UNKNOWN]: 'trezorModelOneFilled', // Just to provide something that wont break UI
};

export const mapTrezorModelToIcon: Record<DeviceModelInternal, IconName> = {
[DeviceModelInternal.T1B1]: 'trezorT1B1',
[DeviceModelInternal.T2T1]: 'trezorT2T1',
[DeviceModelInternal.T2B1]: 'trezorT2B1',
[DeviceModelInternal.T3B1]: 'trezorT3B1',
[DeviceModelInternal.T3T1]: 'trezorT3T1',
[DeviceModelInternal.T3W1]: 'trezorT3W1',

[DeviceModelInternal.UNKNOWN]: 'trezorT1B1', // Just to provide something that wont break UI
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export const ReconnectDevicePrompt = ({ onClose, onSuccess }: ReconnectDevicePro

const deviceFwVersion = getFirmwareVersion(uiEvent?.payload.device);
const switchToBootloaderMap: Record<DeviceModelInternal, TranslationKey> = {
// just to have something, I assume new models will have touch screen
[DeviceModelInternal.UNKNOWN]: 'TR_SWITCH_TO_BOOTLOADER_SWIPE_YOUR_FINGERS',

[DeviceModelInternal.T1B1]:
semver.valid(deviceFwVersion) && semver.satisfies(deviceFwVersion, '<1.8.0')
? 'TR_SWITCH_TO_BOOTLOADER_HOLD_BOTH_BUTTONS'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styled, { css, DefaultTheme, useTheme } from 'styled-components';
import { ComponentWithSubIcon, getIconSize, Icon, IconSize, iconSizes } from '@trezor/components';
import { borders, Color, CSSColor } from '@trezor/theme';
import { isDesktop } from '@trezor/env-utils';
import { mapTrezorModelToIcon } from '@trezor/product-components';
import { mapTrezorModelToIconFilled } from '@trezor/product-components';

import { useDevice } from '../../../../../../../hooks/suite';
import { QuickActionButton } from '../QuickActionButton';
Expand Down Expand Up @@ -110,7 +110,7 @@ const DeviceUpdateIcon = ({ iconSize, updateStatus, variant }: DeviceUpdateIconP
<Highlighted $isHighlighted={updateStatus !== 'up-to-date'}>
<Relative $size={iconSize}>
<Icon
name={mapTrezorModelToIcon[device.features.internal_model]}
name={mapTrezorModelToIconFilled[device.features.internal_model]}
size={iconSizes.medium}
variant={variant}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { spacings } from '@trezor/theme';
import { TranslationKey } from '@suite-common/intl-types';
import { getFirmwareVersion } from '@trezor/device-utils';
import { isDesktop } from '@trezor/env-utils';
import { mapTrezorModelToIcon } from '@trezor/product-components';
import { mapTrezorModelToIconFilled } from '@trezor/product-components';

import { Translation } from '../../../../../Translation';
import {
Expand Down Expand Up @@ -59,7 +59,7 @@ const DeviceRow = ({ updateStatus, onClick }: DeviceRowProps) => {
onClick={onClick}
leftItem={
<Icon
name={mapTrezorModelToIcon[device.features.internal_model]}
name={mapTrezorModelToIconFilled[device.features.internal_model]}
size={iconSizes.medium}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@trezor/components';
import type { Deferred } from '@trezor/utils';
import { spacings } from '@trezor/theme';
import { mapTrezorModelToIcon } from '@trezor/product-components';

import { Translation } from 'src/components/suite';
import { useDevice } from 'src/hooks/suite';
Expand Down Expand Up @@ -90,7 +91,7 @@ export const CoinmarketTermsModal = ({
<List.Item
bulletComponent={
<IconCircle
name={`trezor${device.features.internal_model}`}
name={mapTrezorModelToIcon[device.features.internal_model]}
{...iconProps}
/>
}
Expand Down
6 changes: 6 additions & 0 deletions packages/suite/src/constants/suite/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const DEFAULT_PASSPHRASE_PROTECTION = true;
export const DEFAULT_SKIP_BACKUP = true;

export const DEFAULT_STRENGTH: Record<DeviceModelInternal, number> = {
[DeviceModelInternal.UNKNOWN]: 128, // just to have something
[DeviceModelInternal.T1B1]: 256,
[DeviceModelInternal.T2T1]: 128,
[DeviceModelInternal.T2B1]: 128,
Expand All @@ -14,6 +15,7 @@ export const DEFAULT_STRENGTH: Record<DeviceModelInternal, number> = {
};

export const MAX_ROWS_PER_PAGE: Record<DeviceModelInternal, number> = {
[DeviceModelInternal.UNKNOWN]: 7, // just to have something
[DeviceModelInternal.T1B1]: 4,
[DeviceModelInternal.T2T1]: 5,
[DeviceModelInternal.T2B1]: 4,
Expand All @@ -23,6 +25,7 @@ export const MAX_ROWS_PER_PAGE: Record<DeviceModelInternal, number> = {
};

export const MAX_CHARACTERS_ON_ROW: Record<DeviceModelInternal, number> = {
[DeviceModelInternal.UNKNOWN]: 18, // just to have something
[DeviceModelInternal.T1B1]: 21,
[DeviceModelInternal.T2T1]: 17, // -1 for the space for the scrollbar (Trezor T only)
[DeviceModelInternal.T2B1]: 18,
Expand All @@ -32,6 +35,7 @@ export const MAX_CHARACTERS_ON_ROW: Record<DeviceModelInternal, number> = {
};

export const CHARACTER_OFFSET_FOR_CONTINUES_ARROW: Record<DeviceModelInternal, number> = {
[DeviceModelInternal.UNKNOWN]: 4, // just to have something
[DeviceModelInternal.T1B1]: 3,
[DeviceModelInternal.T2T1]: 4,
[DeviceModelInternal.T2B1]: 2,
Expand All @@ -41,6 +45,7 @@ export const CHARACTER_OFFSET_FOR_CONTINUES_ARROW: Record<DeviceModelInternal, n
};

export const CHARACTER_OFFSET_FOR_NEXT_ARROW: Record<DeviceModelInternal, number> = {
[DeviceModelInternal.UNKNOWN]: 4, // just to have something
[DeviceModelInternal.T1B1]: 0,
[DeviceModelInternal.T2T1]: 4,
[DeviceModelInternal.T2B1]: 2,
Expand All @@ -50,6 +55,7 @@ export const CHARACTER_OFFSET_FOR_NEXT_ARROW: Record<DeviceModelInternal, number
};

export const HAS_MONOCHROME_SCREEN: Record<DeviceModelInternal, boolean> = {
[DeviceModelInternal.UNKNOWN]: false, // just to have something
[DeviceModelInternal.T1B1]: true,
[DeviceModelInternal.T2T1]: false,
[DeviceModelInternal.T2B1]: true,
Expand Down
4 changes: 4 additions & 0 deletions packages/suite/src/constants/suite/homescreens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const safe3Homescreens = [

// original trezor images has to be first as they are send to device as '0' and the default image from fw is used
export const getHomescreens = (isBitcoinOnlyFirmware: boolean) => ({
[DeviceModelInternal.UNKNOWN]: [
isBitcoinOnlyFirmware ? 'orange' : 'green', // just to have something
isBitcoinOnlyFirmware ? 'green' : 'orange',
],
[DeviceModelInternal.T1B1]: [
'original_t1b1', // note - has to be first
'blank',
Expand Down
1 change: 1 addition & 0 deletions packages/suite/src/utils/suite/homescreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const deviceModelInformation: Record<
DeviceModelInternal,
{ width: number; height: number; supports: Array<'png' | 'jpeg'> }
> = {
[DeviceModelInternal.UNKNOWN]: { width: 280, height: 520, supports: ['jpeg'] }, // just to have something
[DeviceModelInternal.T1B1]: { width: 128, height: 64, supports: ['png', 'jpeg'] },
[DeviceModelInternal.T2T1]: { width: 240, height: 240, supports: ['jpeg'] },
[DeviceModelInternal.T2B1]: safe3Information,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const SHAMIR_TYPES: BackupType[] = ['shamir-single', 'shamir-advanced'];
export const isShamirBackupType = (type: BackupType) => SHAMIR_TYPES.includes(type);

export const defaultBackupTypeMap: Record<DeviceModelInternal, BackupType> = {
[DeviceModelInternal.UNKNOWN]: '12-words', // just to have something
[DeviceModelInternal.T1B1]: '24-words',
[DeviceModelInternal.T2T1]: '12-words',
[DeviceModelInternal.T2B1]: 'shamir-single',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ReactNode } from 'react';

import { Button, Tooltip } from '@trezor/components';
import { DeviceModelInternal } from '@trezor/connect';
import { mapTrezorModelToIcon } from '@trezor/product-components';

interface DeviceButtonProps {
isDisabled?: boolean;
Expand All @@ -25,7 +26,7 @@ export const DeviceButton = ({
isDisabled={isDisabled}
isLoading={isLoading}
onClick={onClick}
icon={`trezor${deviceModelInternal}`}
icon={mapTrezorModelToIcon[deviceModelInternal]}
>
{children}
</Button>
Expand Down
1 change: 1 addition & 0 deletions suite-common/suite-constants/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DeviceModelInternal } from '@trezor/connect';
export const DEFAULT_FLAGSHIP_MODEL = DeviceModelInternal.T3T1;

export const SUPPORTS_DEVICE_AUTHENTICITY_CHECK: Record<DeviceModelInternal, boolean> = {
[DeviceModelInternal.UNKNOWN]: true, // We must require device authenticity check so it cannot be used as and exploit to bypass it
[DeviceModelInternal.T1B1]: false,
[DeviceModelInternal.T2T1]: false,
[DeviceModelInternal.T2B1]: true,
Expand Down
12 changes: 6 additions & 6 deletions suite-common/suite-utils/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ export const getChangelogUrl = (device: TrezorDevice, revision?: string | null)
};

/**
Returns DeviceModelInternal, but returns T3B1 if T2B1 is provided.
This is desirable because they both represent the same model (differing internally in the chip) and should behave the same in most situations,
so we don't need to provide separate assets, translations keys, URLs etc. for both.
* Returns DeviceModelInternal, but returns T3B1 if T2B1 is provided.
* This is desirable because they both represent the same model (differing internally in the chip) and should behave the same in most situations,
* so we don't need to provide separate assets, translations keys, URLs etc. for both.
*/
export const getNarrowedDeviceModelInternal = <T extends DeviceModelInternal>(
model: T,
Expand All @@ -263,7 +263,7 @@ export const getNarrowedDeviceModelInternal = <T extends DeviceModelInternal>(
export const getCheckBackupUrl = (device?: TrezorDevice) => {
const deviceModelInternal = device?.features?.internal_model;

if (!deviceModelInternal) {
if (!deviceModelInternal || deviceModelInternal === DeviceModelInternal.UNKNOWN) {
return undefined;
}

Expand All @@ -273,7 +273,7 @@ export const getCheckBackupUrl = (device?: TrezorDevice) => {
export const getPackagingUrl = (device?: TrezorDevice) => {
const deviceModelInternal = device?.features?.internal_model;

if (!deviceModelInternal) {
if (!deviceModelInternal || deviceModelInternal === DeviceModelInternal.UNKNOWN) {
return '';
}

Expand All @@ -283,7 +283,7 @@ export const getPackagingUrl = (device?: TrezorDevice) => {
export const getFirmwareDowngradeUrl = (device?: TrezorDevice) => {
const deviceModelInternal = device?.features?.internal_model;

if (!deviceModelInternal) {
if (!deviceModelInternal || deviceModelInternal === DeviceModelInternal.UNKNOWN) {
return undefined;
}

Expand Down

0 comments on commit 7488355

Please sign in to comment.