chore(connect): improve type for releases and pick model

This commit is contained in:
tomasklim
2024-04-19 12:37:58 +02:00
committed by Tomáš Klíma
parent 5246784f25
commit 996e96de14
2 changed files with 5 additions and 13 deletions

View File

@@ -17,12 +17,10 @@ import type {
} from '../types';
import { DeviceModelInternal } from '../types';
const releases: Record<keyof typeof DeviceModelInternal, FirmwareRelease[]> = {
[DeviceModelInternal.T1B1]: [],
[DeviceModelInternal.T2T1]: [],
[DeviceModelInternal.T2B1]: [],
[DeviceModelInternal.T3T1]: [],
};
const releases = Object.values(DeviceModelInternal).reduce(
(acc, key) => ({ ...acc, [key]: [] }),
{} as Record<keyof typeof DeviceModelInternal, FirmwareRelease[]>,
);
export const parseFirmware = (json: any, deviceModel: DeviceModelInternal) => {
Object.keys(json).forEach(key => {

View File

@@ -2,13 +2,7 @@ import { DeviceModelInternal } from '@trezor/connect';
export const pickByDeviceModel = <Type>(
deviceModelInternal: DeviceModelInternal | undefined,
options: {
default: Type;
[DeviceModelInternal.T1B1]?: Type;
[DeviceModelInternal.T2T1]?: Type;
[DeviceModelInternal.T2B1]?: Type;
[DeviceModelInternal.T3T1]?: Type;
},
options: { default: Type } & Partial<Record<DeviceModelInternal, Type>>,
): Type => {
if (!deviceModelInternal || typeof options[deviceModelInternal] === 'undefined') {
return options.default;