Skip to content

Commit

Permalink
chore(connect): a cosmetic change in Device types
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Oct 9, 2024
1 parent 1ee270b commit b718af4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
15 changes: 9 additions & 6 deletions packages/connect/src/device/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -906,21 +906,25 @@ export class Device extends TypedEmitter<DeviceEvents> {

// simplified object to pass via postMessage
toMessageObject(): DeviceTyped {
const { path } = this.originalDescriptor;
const { name } = this;
const base = {
path,
name,
};
if (this.unreadableError) {
return {
...base,
type: 'unreadable',
path: this.originalDescriptor.path,
error: this.unreadableError, // provide error details
label: 'Unreadable device',
name: this.name,
};
}
if (this.isUnacquired()) {
return {
...base,
type: 'unacquired',
path: this.originalDescriptor.path,
label: 'Unacquired device',
name: this.name,
};
}
const defaultLabel = 'My Trezor';
Expand All @@ -930,15 +934,14 @@ export class Device extends TypedEmitter<DeviceEvents> {
if (this.featuresNeedsReload) status = 'used';

return {
...base,
type: 'acquired',
id: this.features.device_id,
path: this.originalDescriptor.path,
label,
_state: this.getState(),
state: this.getState()?.staticSessionId,
status,
mode: this.getMode(),
name: this.name,
color: this.color,
firmware: this.firmwareStatus,
firmwareRelease: this.firmwareRelease,
Expand Down
25 changes: 12 additions & 13 deletions packages/connect/src/types/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,20 @@ export type FirmwareRevisionCheckResult =
error: FirmwareRevisionCheckError;
};

export type KnownDevice = {
type BaseDevice = {
path: string;
name: string;
};

export type KnownDevice = BaseDevice & {
type: 'acquired';
id: string | null;
path: string;
/** @deprecated, use features.label instead */
label: string;
error?: typeof undefined;
firmware: DeviceFirmwareStatus;
firmwareRelease?: ReleaseInfo | null;
firmwareType?: FirmwareType;
name: string;
color?: string;
status: DeviceStatus;
mode: DeviceMode;
Expand All @@ -81,18 +84,16 @@ export type KnownDevice = {
};
};

export type UnknownDevice = {
export type UnknownDevice = BaseDevice & {
type: 'unacquired';
id?: null;
path: string;
/** @deprecated, use features.label instead */
label: string;
label: 'Unacquired device';
id?: typeof undefined;
error?: typeof undefined;
features?: typeof undefined;
firmware?: typeof undefined;
firmwareRelease?: typeof undefined;
firmwareType?: typeof undefined;
name: string;
color?: typeof undefined;
status?: typeof undefined;
mode?: typeof undefined;
Expand All @@ -102,18 +103,16 @@ export type UnknownDevice = {
availableTranslations?: typeof undefined;
};

export type UnreadableDevice = {
export type UnreadableDevice = BaseDevice & {
type: 'unreadable';
id?: null;
path: string;
/** @deprecated, use features.label instead */
label: string;
label: 'Unreadable device';
error: string;
id?: typeof undefined;
features?: typeof undefined;
firmware?: typeof undefined;
firmwareRelease?: typeof undefined;
firmwareType?: typeof undefined;
name: string;
color?: typeof undefined;
status?: typeof undefined;
mode?: typeof undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import graphReducer from 'src/reducers/wallet/graphReducer';
import storageMiddleware from 'src/middlewares/wallet/storageMiddleware';
import { coinjoinReducer } from 'src/reducers/wallet/coinjoinReducer';
import { configureStore } from 'src/support/tests/configureStore';
import { AppState } from 'src/types/suite';
import { AcquiredDevice, AppState } from 'src/types/suite';
import { SETTINGS } from 'src/config/suite';
import { preloadStore } from 'src/support/suite/preloadStore';
import { extraDependencies } from 'src/support/extraDependencies';
Expand Down Expand Up @@ -424,7 +424,7 @@ describe('Storage actions', () => {
// Change device label inside a reducer
await store.dispatch(
deviceActions.updateSelectedDevice({
...dev1Connected,
...(dev1Connected as AcquiredDevice),
label: 'New Label',
}),
);
Expand Down
4 changes: 2 additions & 2 deletions suite-common/test-utils/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const getConnectDevice = (dev?: Partial<Device>, feat?: Partial<Features>): Devi
return {
type: 'unreadable',
path: dev && dev.path ? dev.path : '1',
label: dev && dev.label ? dev.label : 'My Trezor',
label: 'Unreadable device',
name: 'name of unreadable device',
error: 'unreadable device',
};
Expand All @@ -157,7 +157,7 @@ const getConnectDevice = (dev?: Partial<Device>, feat?: Partial<Features>): Devi
return {
type: dev.type,
path: dev && dev.path ? dev.path : '1',
label: dev && dev.label ? dev.label : 'My Trezor',
label: 'Unacquired device',
name: 'name of unacquired device',
};
}
Expand Down

0 comments on commit b718af4

Please sign in to comment.