mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-10 09:18:15 +01:00
chore(device-utils): remove DeviceModel enum and getDeviceModel
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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));
|
||||
@@ -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, () => {
|
||||
|
||||
Reference in New Issue
Block a user