feat(suite): device model utils + config changes

This commit is contained in:
tomasklim
2022-12-13 15:48:12 +01:00
committed by Tomáš Klíma
parent 12488cac7e
commit 6baf231ed0
17 changed files with 98 additions and 25 deletions

View File

@@ -18,6 +18,7 @@
},
"dependencies": {
"@tippyjs/react": "^4.2.6",
"@trezor/device-utils": "workspace:*",
"@trezor/dom-utils": "workspace:*",
"@trezor/react-utils": "workspace:*",
"date-fns": "^2.29.1",

View File

@@ -10,6 +10,7 @@
},
"include": ["."],
"references": [
{ "path": "../device-utils" },
{ "path": "../dom-utils" },
{ "path": "../react-utils" }
]

View File

@@ -1,3 +1,34 @@
import { PartialDevice } from './types';
export const getDeviceModel = (device?: PartialDevice) => device?.features?.model || '';
export enum DeviceModel {
T1 = '1',
TT = 'T',
TR = 'R',
UNKNOWN = '',
}
export const getDeviceModel = (device?: PartialDevice): DeviceModel => {
const deviceModel = device?.features?.model;
if (Object.values(DeviceModel).includes(deviceModel as DeviceModel)) {
return deviceModel as DeviceModel;
}
return DeviceModel.UNKNOWN;
};
export const pickByDeviceModel = <Type>(
deviceModel: DeviceModel | undefined,
options: {
default: Type;
[DeviceModel.T1]?: Type;
[DeviceModel.TT]?: Type;
[DeviceModel.TR]?: Type;
},
): Type => {
if (!deviceModel || typeof options[deviceModel] === 'undefined') {
return options.default;
}
return options[deviceModel] ?? options.default;
};

View File

@@ -14,6 +14,7 @@
"@sentry/browser": "6.17.2",
"@suite-common/formatters": "workspace:*",
"@suite-common/sentry": "workspace:*",
"@trezor/device-utils": "workspace:*",
"@trezor/suite": "workspace:*",
"react-helmet": "^6.1.0",
"react-redux": "7.2.2",

View File

@@ -7,6 +7,7 @@
"path": "../../suite-common/formatters"
},
{ "path": "../../suite-common/sentry" },
{ "path": "../device-utils" },
{ "path": "../suite" },
{
"path": "../../suite-common/test-utils"

View File

@@ -159,22 +159,24 @@ const ReconnectLabel = ({
const deviceModel = device?.features ? getDeviceModel(device) : 'T';
if (requestedMode === 'bootloader') {
if (deviceModel === '1') {
return semver.valid(deviceFwVersion) && semver.satisfies(deviceFwVersion, '<1.8.0') ? (
<Translation id="TR_HOLD_BOTH_BUTTONS" />
) : (
<Translation id="TR_HOLD_LEFT_BUTTON" />
);
}
const switchToBootloaderModeMessage = pickByDeviceModel(deviceModel, {
default: 'TR_SWITCH_TO_BOOTLOADER_HOLD_LEFT_BUTTON',
[DeviceModel.T1]:
semver.valid(deviceFwVersion) && semver.satisfies(deviceFwVersion, '<1.8.0')
? 'TR_SWITCH_TO_BOOTLOADER_HOLD_BOTH_BUTTONS'
: 'TR_SWITCH_TO_BOOTLOADER_HOLD_LEFT_BUTTON',
[DeviceModel.TT]: 'TR_SWITCH_TO_BOOTLOADER_SWIPE_YOUR_FINGERS',
} as const);
return <Translation id="TR_SWIPE_YOUR_FINGERS" />;
}
return deviceModel === '1' ? (
<Translation id="FIRMWARE_CONNECT_IN_NORMAL_MODEL_1" />
) : (
<Translation id="FIRMWARE_CONNECT_IN_NORMAL_MODEL_2" />
);
const switchToNormalModeMessage = pickByDeviceModel(deviceModel, {
default: 'FIRMWARE_CONNECT_IN_NORMAL_MODEL_NO_BUTTON',
[DeviceModel.TR]: 'FIRMWARE_CONNECT_IN_NORMAL_MODEL_NO_TOUCH',
} as const);
return <Translation id={switchToNormalModeMessage} />;
};
interface ReconnectStepProps {

View File

@@ -0,0 +1,6 @@
import { useSelector } from './useSelector';
import { TrezorDevice } from '@suite-types/index';
import { selectDeviceModel } from '@suite-reducers/suiteReducer';
export const useDeviceModel = (overrideDevice?: TrezorDevice) =>
useSelector(state => selectDeviceModel(state, overrideDevice));

View File

@@ -15,6 +15,7 @@ import type { InvityServerEnvironment } from '@wallet-types/invity';
import type { CoinjoinServerEnvironment } from '@wallet-types/coinjoin';
import { createSelector } from '@reduxjs/toolkit';
import { getIsTorEnabled, getIsTorLoading } from '@suite-utils/tor';
import { getDeviceModel } from '@trezor/device-utils';
export interface SuiteRootState {
suite: SuiteState;
@@ -247,6 +248,13 @@ export const selectTorState = createSelector(
export const selectDebug = (state: SuiteRootState) => state.suite.settings.debug;
export const selectDevice = (state: SuiteRootState) => state.suite.device;
export const selectDeviceModel = createSelector(
[selectDevice, (_state: SuiteRootState, overrideDevice?: TrezorDevice) => overrideDevice],
(device, overrideDevice?: TrezorDevice) => getDeviceModel(overrideDevice || device),
);
export const selectLanguage = (state: SuiteRootState) => state.suite.settings.language;
export default suiteReducer;

View File

@@ -60,7 +60,15 @@ export const RecoveryStep = () => {
<RecoveryStepBox
key={status} // to properly rerender in translation mode
heading={<Translation id="TR_RECOVER_YOUR_WALLET_FROM" />}
description={<Translation id="TR_RECOVER_SUBHEADING_MODEL_T" />}
description={
<Translation
id={pickByDeviceModel(deviceModel, {
default: 'TR_RECOVER_SUBHEADING_MODEL_TOUCH',
[DeviceModel.TT]: 'TR_RECOVER_SUBHEADING_MODEL_TOUCH',
[DeviceModel.TR]: 'TR_RECOVER_SUBHEADING_MODEL_BUTTONS',
})}
/>
}
innerActions={
<OnboardingButtonCta
data-test="@onboarding/recovery/start-button"

View File

@@ -159,11 +159,12 @@ export const Recovery = ({ onCancel }: ForegroundAppProps) => {
title={<Translation id="TR_ENTER_ALL_WORDS_IN_CORRECT" />}
>
<Translation
id={
isModelOne
? 'TR_ON_YOUR_COMPUTER_ENTER'
: 'TR_USING_TOUCHSCREEN'
}
id={pickByDeviceModel(deviceModel, {
default: 'TR_SEED_WORDS_ENTER_BUTTONS',
[DeviceModel.T1]: 'TR_SEED_WORDS_ENTER_COMPUTER',
[DeviceModel.TT]: 'TR_SEED_WORDS_ENTER_TOUCHSCREEN',
[DeviceModel.TR]: 'TR_SEED_WORDS_ENTER_BUTTONS',
})}
/>
</InstructionStep>
</StepsContainer>

View File

@@ -85,11 +85,12 @@ export const SettingsDevice = () => {
title={<Translation id="TR_SETTINGS_DEVICE_BANNER_TITLE_BOOTLOADER" />}
description={
<Translation
id={
deviceModel === '1'
? 'TR_SETTINGS_DEVICE_BANNER_DESCRIPTION_BOOTLOADER_MODEL_1'
: 'TR_SETTINGS_DEVICE_BANNER_DESCRIPTION_BOOTLOADER_MODEL_2'
}
id={pickByDeviceModel(deviceModel, {
default:
'TR_SETTINGS_DEVICE_BANNER_DESCRIPTION_BOOTLOADER_NO_BUTTONS',
[DeviceModel.TT]:
'TR_SETTINGS_DEVICE_BANNER_DESCRIPTION_BOOTLOADER_NO_TOUCH',
})}
/>
}
/>

View File

@@ -17,6 +17,7 @@
"@suite-common/wallet-config": "workspace:*",
"@suite-common/wallet-types": "workspace:*",
"@trezor/connect": "workspace:9.0.5",
"@trezor/device-utils": "workspace:*",
"@trezor/message-system": "workspace:*",
"@trezor/utils": "workspace:*",
"dropbox": "^10.32.0",

View File

@@ -7,6 +7,7 @@
{ "path": "../wallet-config" },
{ "path": "../wallet-types" },
{ "path": "../../packages/connect" },
{ "path": "../../packages/device-utils" },
{
"path": "../../packages/message-system"
},

View File

@@ -9,6 +9,9 @@
"lint:js": "yarn g:eslint '**/*.{ts,tsx,js}'",
"type-check": "tsc --build"
},
"dependencies": {
"@trezor/device-utils": "workspace:*"
},
"devDependencies": {
"jest": "^26.6.3",
"typescript": "4.9.3"

View File

@@ -1,5 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": { "outDir": "libDev" },
"references": []
"references": [
{ "path": "../../packages/device-utils" }
]
}

View File

@@ -129,6 +129,7 @@
"@backup-middlewares": ["./packages/suite/src/middlewares/backup/index"],
"@trezor/utils": ["./packages/utils/src"],
"@trezor/device-utils": ["./packages/device-utils/src"],
"@suite/*": ["./packages/suite/src/*"],
"@suite": ["./packages/suite/src/index"]

View File

@@ -6200,6 +6200,7 @@ __metadata:
"@suite-common/wallet-config": "workspace:*"
"@suite-common/wallet-types": "workspace:*"
"@trezor/connect": "workspace:9.0.5"
"@trezor/device-utils": "workspace:*"
"@trezor/message-system": "workspace:*"
"@trezor/utils": "workspace:*"
dropbox: ^10.32.0
@@ -6232,6 +6233,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@suite-common/wallet-config@workspace:suite-common/wallet-config"
dependencies:
"@trezor/device-utils": "workspace:*"
jest: ^26.6.3
typescript: 4.9.3
languageName: unknown
@@ -6930,6 +6932,7 @@ __metadata:
"@storybook/manager-webpack5": ^6.5.13
"@storybook/react": ^6.5.13
"@tippyjs/react": ^4.2.6
"@trezor/device-utils": "workspace:*"
"@trezor/dom-utils": "workspace:*"
"@trezor/react-utils": "workspace:*"
"@types/react": 18.0.25
@@ -7565,6 +7568,7 @@ __metadata:
"@suite-common/formatters": "workspace:*"
"@suite-common/sentry": "workspace:*"
"@suite-common/test-utils": "workspace:*"
"@trezor/device-utils": "workspace:*"
"@trezor/suite": "workspace:*"
"@trezor/trezor-user-env-link": "workspace:*"
"@trezor/utils": "workspace:*"