feat(connect): reexport device model internal enum and use

This commit is contained in:
tomasklim
2023-07-21 14:16:21 +02:00
committed by Matěj Kříž
parent 26c17386aa
commit a832fde9ff
13 changed files with 36 additions and 34 deletions

View File

@@ -2,7 +2,7 @@
import { UiRequestUnexpectedDeviceMode } from '@trezor/connect';
import { showView } from './common';
import { getDeviceDisplayName, getDeviceModel } from '@trezor/device-utils';
import { getDeviceDisplayName } from '@trezor/device-utils';
export const firmwareNotSupported = (device: UiRequestUnexpectedDeviceMode['payload']) => {
const view = showView('firmware-not-supported');
@@ -14,13 +14,10 @@ export const firmwareNotSupported = (device: UiRequestUnexpectedDeviceMode['payl
}
if (!device.features) return;
const deviceModel = getDeviceModel(device);
// universal message "Coin is not supported" is replaced by
const h3 = view.getElementsByTagName('h3')[0];
if (deviceModel) {
const deviceDisplayName = getDeviceDisplayName(deviceModel);
h3.innerHTML = `${deviceDisplayName} is not supported`;
}
const deviceDisplayName = getDeviceDisplayName(device.features.internal_model);
h3.innerHTML = `${deviceDisplayName} is not supported`;
};

View File

@@ -1,6 +1,6 @@
/* WARNING! This file should be imported ONLY in tests! */
import type { Features, FirmwareRelease } from './src/types';
import { DeviceModelInternal, type Features, type FirmwareRelease } from './src/types';
export const getDeviceFeatures = (feat?: Partial<Features>): Features => ({
vendor: 'trezor.io',
@@ -22,7 +22,7 @@ export const getDeviceFeatures = (feat?: Partial<Features>): Features => ({
needs_backup: false,
flags: 0,
model: 'T',
internal_model: 'T2T1',
internal_model: DeviceModelInternal.T2T1,
fw_major: null,
fw_minor: null,
fw_patch: null,

View File

@@ -70,6 +70,7 @@ export type UnreadableDevice = {
export type Device = KnownDevice | UnknownDevice | UnreadableDevice;
export type Features = PROTO.Features;
export { DeviceModelInternal } from '@trezor/transport/lib/types/messages';
type FeaturesNarrowing =
| {

View File

@@ -1,7 +1,7 @@
import { versionCompare } from './versionUtils';
import { PROTO } from '../constants';
import { config } from '../data/config';
import type { Features, CoinInfo, UnavailableCapabilities } from '../types';
import { Features, CoinInfo, UnavailableCapabilities, DeviceModelInternal } from '../types';
const DEFAULT_CAPABILITIES_T1: PROTO.Capability[] = [
'Capability_Bitcoin',
@@ -140,13 +140,12 @@ export const parseRevision = (features: Features) => {
return /^([a-f0-9])*$/gi.test(revisionUtf8) ? revisionUtf8 : revision;
};
export const ensureInternalModelFeature = (model: Features['model']) => {
export const ensureInternalModelFeature = (model: Features['model']): DeviceModelInternal => {
switch (model.toUpperCase()) {
case '1':
return 'T1B1';
case 'T':
return 'T2T1';
return DeviceModelInternal.T2T1;
case '1':
default:
return '';
return DeviceModelInternal.T1B1;
}
};

View File

@@ -11,6 +11,9 @@
"type-check": "tsc --build",
"build:lib": "rimraf lib && yarn tsc --build ./tsconfig.lib.json"
},
"dependencies": {
"@trezor/connect": "workspace:*"
},
"devDependencies": {
"typescript": "4.9.5"
}

View File

@@ -1,3 +1,5 @@
import { DeviceModelInternal } from '@trezor/connect';
import { PartialDevice } from './types';
export enum DeviceModel {
@@ -7,20 +9,13 @@ export enum DeviceModel {
UNKNOWN = '',
}
export enum DeviceInternalModel {
T1 = 'T1B1',
TT = 'T2T1',
T2B1 = 'T2B1',
UNKNOWN = '',
}
export const getDeviceDisplayName = (deviceModel: DeviceModel) => {
switch (deviceModel) {
case DeviceModel.T1:
export const getDeviceDisplayName = (deviceModelInternal?: DeviceModelInternal) => {
switch (deviceModelInternal) {
case DeviceModelInternal.T1B1:
return 'Trezor Model One';
case DeviceModel.TT:
case DeviceModelInternal.T2T1:
return 'Trezor Model T';
case DeviceModel.T2B1:
case DeviceModelInternal.T2B1:
return 'Trezor Model R';
default:
console.error('Unknown Trezor device');

View File

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

View File

@@ -53,6 +53,7 @@ const CoinsList = ({
const firmwareVersion = getFirmwareVersion(device);
// TODO
const supportField = deviceModel && support?.[deviceModel];
const supportedBySuite =
!firmwareVersion ||
@@ -87,7 +88,9 @@ const CoinsList = ({
<Translation
id={tooltipString}
values={{
deviceDisplayName: getDeviceDisplayName(deviceModel),
deviceDisplayName: getDeviceDisplayName(
device?.features?.internal_model,
),
}}
/>
)

View File

@@ -1,7 +1,7 @@
/* WARNING! This file should be imported ONLY in tests! */
/* eslint-disable require-await */
import { AccountUtxo, Device, Features } from '@trezor/connect';
import { AccountUtxo, Device, Features, DeviceModelInternal } from '@trezor/connect';
import {
TrezorDevice,
GuideNode,
@@ -17,7 +17,7 @@ import {
BlockchainNetworks,
} from '@suite-common/wallet-types';
import { networksCompatibility } from '@suite-common/wallet-config';
import { DeviceModel, DeviceInternalModel } from '@trezor/device-utils';
import { DeviceModel } from '@trezor/device-utils';
// in-memory implementation of indexedDB
import 'fake-indexeddb/auto';
@@ -111,7 +111,7 @@ const getDeviceFeatures = (feat?: Partial<Features>): Features => ({
needs_backup: false,
flags: 0,
model: DeviceModel.TT,
internal_model: DeviceInternalModel.TT,
internal_model: DeviceModelInternal.T2T1,
fw_major: null,
fw_minor: null,
fw_patch: null,

View File

@@ -14,6 +14,7 @@
"dependencies": {
"@reduxjs/toolkit": "1.9.5",
"@suite-common/suite-types": "workspace:*",
"@trezor/connect": "workspace:*",
"react": "18.2.0"
},
"devDependencies": {

View File

@@ -1,6 +1,7 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { TrezorDevice } from '@suite-common/suite-types';
import { DeviceModelInternal } from '@trezor/connect';
export const HIDDEN_DEVICE_ID = 'hiddenDeviceWithImportedAccounts';
export const HIDDEN_DEVICE_STATE = `state@${HIDDEN_DEVICE_ID}:1`;
@@ -34,9 +35,8 @@ export const hiddenDevice: TrezorDevice = {
firmware_present: null,
needs_backup: false,
flags: 0,
// TODO: use DeviceModel, DeviceInternalModel enums
model: 'T',
internal_model: 'T2T1',
internal_model: DeviceModelInternal.T2T1,
fw_major: null,
fw_minor: null,
fw_patch: null,

View File

@@ -4,6 +4,7 @@
"references": [
{
"path": "../../suite-common/suite-types"
}
},
{ "path": "../../packages/connect" }
]
}

View File

@@ -7216,6 +7216,7 @@ __metadata:
dependencies:
"@reduxjs/toolkit": 1.9.5
"@suite-common/suite-types": "workspace:*"
"@trezor/connect": "workspace:*"
jest: ^26.6.3
react: 18.2.0
typescript: 4.9.5
@@ -8107,6 +8108,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@trezor/device-utils@workspace:packages/device-utils"
dependencies:
"@trezor/connect": "workspace:*"
typescript: 4.9.5
languageName: unknown
linkType: soft