feat(connect): trezor name in device object

This commit is contained in:
tomasklim
2023-09-05 12:55:41 +02:00
committed by Tomáš Klíma
parent 6d80197523
commit a0ecb66390
6 changed files with 17 additions and 22 deletions

View File

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

View File

@@ -25,6 +25,7 @@ import {
UnavailableCapabilities,
FirmwareType,
} from '../types';
import { models } from '../data/models';
// custom log
const _log = initLog('Device');
@@ -122,6 +123,8 @@ export class Device extends TypedEmitter<DeviceEvents> {
firmwareType?: FirmwareType;
name = 'Trezor';
constructor(transport: Transport, descriptor: Descriptor) {
super();
@@ -545,6 +548,10 @@ export class Device extends TypedEmitter<DeviceEvents> {
? FirmwareType.BitcoinOnly
: FirmwareType.Regular;
}
const deviceInfo = models[feat.internal_model];
this.name = deviceInfo.name;
}
isUnacquired() {
@@ -680,6 +687,7 @@ export class Device extends TypedEmitter<DeviceEvents> {
path: this.originalDescriptor.path,
error: this.unreadableError, // provide error details
label: 'Unreadable device',
name: this.name,
};
}
if (this.isUnacquired()) {
@@ -687,6 +695,7 @@ export class Device extends TypedEmitter<DeviceEvents> {
type: 'unacquired',
path: this.originalDescriptor.path,
label: 'Unacquired device',
name: this.name,
};
}
const defaultLabel = 'My Trezor';
@@ -702,6 +711,7 @@ export class Device extends TypedEmitter<DeviceEvents> {
state: this.getExternalState(),
status,
mode: this.getMode(),
name: this.name,
firmware: this.firmwareStatus,
firmwareRelease: this.firmwareRelease,
firmwareType: this.firmwareType,

View File

@@ -32,6 +32,7 @@ export type KnownDevice = {
firmware: DeviceFirmwareStatus;
firmwareRelease?: ReleaseInfo | null;
firmwareType?: FirmwareType;
name: string;
status: DeviceStatus;
mode: DeviceMode;
state?: string;
@@ -49,6 +50,7 @@ export type UnknownDevice = {
firmware?: typeof undefined;
firmwareRelease?: typeof undefined;
firmwareType?: typeof undefined;
name: string;
status?: typeof undefined;
mode?: typeof undefined;
state?: typeof undefined;
@@ -65,6 +67,7 @@ export type UnreadableDevice = {
firmware?: typeof undefined;
firmwareRelease?: typeof undefined;
firmwareType?: typeof undefined;
name: string;
status?: typeof undefined;
mode?: typeof undefined;
state?: typeof undefined;

View File

@@ -1,18 +1,5 @@
import { DeviceModelInternal } from '@trezor/connect';
export const getDeviceDisplayName = (deviceModelInternal?: DeviceModelInternal) => {
switch (deviceModelInternal) {
case DeviceModelInternal.T1B1:
return 'Trezor Model One';
case DeviceModelInternal.T2T1:
return 'Trezor Model T';
case DeviceModelInternal.T2B1:
return 'Trezor Model R';
default:
return 'Trezor';
}
};
export const pickByDeviceModel = <Type>(
deviceModelInternal: DeviceModelInternal | undefined,
options: {

View File

@@ -4,11 +4,7 @@ import { Tooltip } from '@trezor/components';
import { Coin, Translation } from 'src/components/suite';
import { useDevice, useSelector } from 'src/hooks/suite';
import type { Network } from 'src/types/wallet';
import {
getDeviceDisplayName,
getFirmwareVersion,
isDeviceInBootloaderMode,
} from '@trezor/device-utils';
import { getFirmwareVersion, isDeviceInBootloaderMode } from '@trezor/device-utils';
import { selectSupportedNetworks } from 'src/reducers/suite/suiteReducer';
import { versionUtils } from '@trezor/utils';
import { getCoinUnavailabilityMessage } from 'src/utils/suite/device';
@@ -49,7 +45,7 @@ export const CoinsList = ({
const isBootloaderMode = isDeviceInBootloaderMode(device);
const firmwareVersion = getFirmwareVersion(device);
const deviceDisplayName = getDeviceDisplayName(device?.features?.internal_model);
const deviceDisplayName = device?.name;
return (
<Wrapper>

View File

@@ -16,6 +16,7 @@ export const hiddenDevice: TrezorDevice = {
label: 'Hidden device with imported accounts',
path: '1',
firmware: 'valid',
name: 'Trezor Model T',
features: {
vendor: 'trezor.io',
major_version: 2,