chore(device-utils): remove DeviceModel enum and getDeviceModel

This commit is contained in:
tomasklim
2023-07-26 11:31:31 +02:00
committed by Matěj Kříž
parent c9c7d7db09
commit 82a0db70db
4 changed files with 6 additions and 44 deletions

View File

@@ -1,14 +1,5 @@
import { DeviceModelInternal } from '@trezor/connect';
import { PartialDevice } from './types';
export enum DeviceModel {
T1 = '1',
TT = 'T',
T2B1 = 'R',
UNKNOWN = '',
}
export const getDeviceDisplayName = (deviceModelInternal?: DeviceModelInternal) => {
switch (deviceModelInternal) {
case DeviceModelInternal.T1B1:
@@ -18,33 +9,22 @@ export const getDeviceDisplayName = (deviceModelInternal?: DeviceModelInternal)
case DeviceModelInternal.T2B1:
return 'Trezor Model R';
default:
console.error('Unknown Trezor device');
return 'Trezor';
}
};
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,
deviceModelInternal: DeviceModelInternal | undefined,
options: {
default: Type;
[DeviceModel.T1]?: Type;
[DeviceModel.TT]?: Type;
[DeviceModel.T2B1]?: Type;
[DeviceModelInternal.T1B1]?: Type;
[DeviceModelInternal.T2T1]?: Type;
[DeviceModelInternal.T2B1]?: Type;
},
): Type => {
if (!deviceModel || typeof options[deviceModel] === 'undefined') {
if (!deviceModelInternal || typeof options[deviceModelInternal] === 'undefined') {
return options.default;
}
return options[deviceModel] ?? options.default;
return options[deviceModelInternal] ?? options.default;
};

View File

@@ -7,7 +7,6 @@ export { useGraph } from './useGraph';
export { useAccountSearch } from './useAccountSearch';
export { useFirmware } from './useFirmware';
export { useSelector } from './useSelector';
export { useDeviceModel } from './useDeviceModel';
export { useLoadingSkeleton } from './useLoadingSkeleton';
export { useTranslation } from './useTranslation';
export { useOnboarding } from './useOnboarding';

View File

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

View File

@@ -1,5 +1,4 @@
import * as utils from 'src/utils/suite/device';
import { getDeviceModel } from '@trezor/device-utils';
import { AcquiredDevice } from 'src/types/suite';
import fixtures from '../__fixtures__/device';
@@ -39,16 +38,6 @@ describe('isSelectedInstance', () => {
});
});
// getDeviceModel is not part of suite package. However, tests are dependant on definitions from suite package.
describe('getDeviceModel', () => {
fixtures.getDeviceModel.forEach(f => {
it(f.description, () => {
const instance = getDeviceModel(f.device);
expect(instance).toEqual(f.result);
});
});
});
describe('getNewInstanceNumber', () => {
fixtures.getNewInstanceNumber.forEach(f => {
it(f.description, () => {