Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(monorepo): remove dependency on connect in components and produ… #17153

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@suite-common/validators": "workspace:*",
"@testing-library/jest-dom": "^6.6.3",
"@trezor/asset-utils": "workspace:*",
"@trezor/connect": "workspace:*",
"@trezor/device-utils": "workspace:*",
"@trezor/dom-utils": "workspace:*",
"@trezor/env-utils": "workspace:*",
"@trezor/react-utils": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import styled, { useTheme } from 'styled-components';

import { DEFAULT_FLAGSHIP_MODEL } from '@suite-common/suite-constants';
import { getNarrowedDeviceModelInternal } from '@suite-common/suite-utils';
import { DeviceModelInternal } from '@trezor/connect';
import { DeviceModelInternal } from '@trezor/device-utils';

import { AnimationWrapper, Shape } from './AnimationPrimitives';
import { resolveStaticPath } from '../../utils/resolveStaticPath';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styled from 'styled-components';

import { DEFAULT_FLAGSHIP_MODEL } from '@suite-common/suite-constants';
import { getNarrowedDeviceModelInternal } from '@suite-common/suite-utils';
import { DeviceModelInternal } from '@trezor/connect';
import { DeviceModelInternal } from '@trezor/device-utils';

import { AnimationWrapper, Shape } from './AnimationPrimitives';
import { resolveStaticPath } from '../../utils/resolveStaticPath';
Expand Down
2 changes: 1 addition & 1 deletion packages/components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"path": "../../suite-common/validators"
},
{ "path": "../asset-utils" },
{ "path": "../connect" },
{ "path": "../device-utils" },
{ "path": "../dom-utils" },
{ "path": "../env-utils" },
{ "path": "../react-utils" },
Expand Down
1 change: 1 addition & 0 deletions packages/connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@trezor/connect-analytics": "workspace:*",
"@trezor/connect-common": "workspace:*",
"@trezor/crypto-utils": "workspace:*",
"@trezor/device-utils": "workspace:*",
"@trezor/protobuf": "workspace:*",
"@trezor/protocol": "workspace:*",
"@trezor/schema-utils": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { VersionArray } from '@trezor/device-utils';
import { versionUtils } from '@trezor/utils';

import { getBinary } from './getBinary';
import { GetInfoProps, getInfo } from '../../data/firmwareInfo';
import { IntermediaryVersion, VersionArray } from '../../types';
import { IntermediaryVersion } from '../../types';
import { httpRequest } from '../../utils/assets';
import { isStrictFeatures } from '../../utils/firmwareUtils';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { VersionArray } from '../../types/firmware';
import type { VersionArray } from '@trezor/device-utils';
/**
* parse firmware headers
* based on
Expand Down
3 changes: 1 addition & 2 deletions packages/connect/src/data/firmwareInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// origin: https://github.com/trezor/connect/blob/develop/src/js/data/FirmwareInfo.js

import { DeviceModelInternal, VersionArray } from '@trezor/device-utils';
import { versionUtils } from '@trezor/utils';

import type {
Expand All @@ -8,9 +9,7 @@ import type {
IntermediaryVersion,
ReleaseInfo,
StrictFeatures,
VersionArray,
} from '../types';
import { DeviceModelInternal } from '../types';
import {
filterSafeListByBootloader,
filterSafeListByFirmware,
Expand Down
2 changes: 1 addition & 1 deletion packages/connect/src/data/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeviceModelInternal } from '@trezor/protobuf';
import { DeviceModelInternal } from '@trezor/device-utils';

type ModelConfig = {
name: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FetchError } from 'node-fetch';

import { DeviceModelInternal } from '@trezor/protobuf';
import { DeviceModelInternal } from '@trezor/device-utils';

import { FirmwareRelease, FirmwareRevisionCheckResult } from '../../exports';
import * as utilsAssets from '../../utils/assets';
Expand Down
3 changes: 1 addition & 2 deletions packages/connect/src/device/calculateRevisionForDevice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { VersionArray } from '@trezor/device-utils';
import { isNewer } from '@trezor/utils/src/versionUtils';

import { VersionArray } from '../exports';

type calculateRevisionForDeviceParams = {
commitRevision: string;
version: VersionArray;
Expand Down
3 changes: 2 additions & 1 deletion packages/connect/src/events/device.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { VersionArray } from '@trezor/device-utils';

import type { PROTO } from '../constants';
import type { Device } from '../types/device';
import type { VersionArray } from '../types/firmware';
import type { MessageFactoryFn } from '../types/utils';

export const DEVICE_EVENT = 'DEVICE_EVENT';
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion packages/connect/src/types/api/firmwareUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { VersionArray } from '@trezor/device-utils';
import { Static, Type } from '@trezor/schema-utils';

import type { VersionArray } from '../firmware';
import type { Params, Response } from '../params';

export type FirmwareUpdate = Static<typeof FirmwareUpdate>;
Expand Down
50 changes: 2 additions & 48 deletions packages/connect/src/types/device.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FeaturesNarrowing, FirmwareType } from '@trezor/device-utils';
import { Descriptor } from '@trezor/transport';

import type { PROTO } from '../constants';
Expand Down Expand Up @@ -26,11 +27,6 @@ export type UnavailableCapability =
| 'update-required'
| 'trezor-connect-outdated';

export enum FirmwareType {
BitcoinOnly = 'bitcoin-only',
Regular = 'regular',
}

export type StaticSessionId = `${string}@${string}:${number}`;

export type DeviceState = {
Expand Down Expand Up @@ -152,50 +148,8 @@ export type UnreadableDevice = BaseDevice & {
export type Device = KnownDevice | UnknownDevice | UnreadableDevice;
export type Features = PROTO.Features;

export { DeviceModelInternal } from '@trezor/protobuf';
export { DeviceModelInternal } from '@trezor/device-utils';

export type DisplayRotation = PROTO.DisplayRotation;

type FeaturesNarrowing =
| {
major_version: 2;
fw_major: null;
fw_minor: null;
fw_patch: null;
bootloader_mode: true;
firmware_present: false;
}
| {
major_version: 2;
fw_major: null;
fw_minor: null;
fw_patch: null;
bootloader_mode: null;
firmware_present: null;
}
| {
major_version: 2;
fw_major: 2;
fw_minor: number;
fw_patch: number;
bootloader_mode: true;
firmware_present: true;
}
| {
major_version: 1;
fw_major: null;
fw_minor: null;
fw_patch: null;
bootloader_mode: true;
firmware_present: false;
}
| {
major_version: 1;
fw_major: null;
fw_minor: null;
fw_patch: null;
bootloader_mode: true;
firmware_present: true;
};

export type StrictFeatures = Features & FeaturesNarrowing;
4 changes: 1 addition & 3 deletions packages/connect/src/types/firmware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeviceModelInternal } from '@trezor/protobuf';
import { DeviceModelInternal, VersionArray } from '@trezor/device-utils';
import { Type } from '@trezor/schema-utils';

export type FirmwareRange = Record<
Expand All @@ -9,8 +9,6 @@ export type FirmwareRange = Record<
}
>;

export type VersionArray = [number, number, number];

export type FirmwareRelease = {
required: boolean;
url: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/connect/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ export type {
Target as TransactionTarget,
AccountBalanceHistory as BlockchainAccountBalanceHistory,
} from '@trezor/blockchain-link';

export { FirmwareType, type VersionArray } from '@trezor/device-utils';
1 change: 1 addition & 0 deletions packages/connect/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{ "path": "../connect-analytics" },
{ "path": "../connect-common" },
{ "path": "../crypto-utils" },
{ "path": "../device-utils" },
{ "path": "../protobuf" },
{ "path": "../protocol" },
{ "path": "../schema-utils" },
Expand Down
3 changes: 3 additions & 0 deletions packages/connect/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
{
"path": "../crypto-utils"
},
{
"path": "../device-utils"
},
{
"path": "../protobuf"
},
Expand Down
4 changes: 1 addition & 3 deletions packages/device-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
"sideEffects": false,
"main": "src/index",
"scripts": {
"build:lib": "yarn g:rimraf -rf lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"test:unit": "yarn g:jest -c ../../jest.config.base.js"
},
"dependencies": {
"@trezor/connect": "workspace:*"
}
}
9 changes: 9 additions & 0 deletions packages/device-utils/src/customTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum DeviceModelInternal {
T1B1 = 'T1B1',
T2T1 = 'T2T1',
T2B1 = 'T2B1',
T3B1 = 'T3B1',
T3T1 = 'T3T1',
T3W1 = 'T3W1',
UNKNOWN = 'UNKNOWN',
}
7 changes: 2 additions & 5 deletions packages/device-utils/src/firmwareUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { FirmwareType, VersionArray } from '@trezor/connect';

import { isDeviceInBootloaderMode } from './modeUtils';
import { FirmwareVersionString, PartialDevice } from './types';
import { FirmwareType, FirmwareVersionString, PartialDevice, VersionArray } from './types';

export const getFirmwareRevision = (device?: PartialDevice) => device?.features?.revision || '';

Expand All @@ -26,9 +24,8 @@ export const getFirmwareVersion = (device?: PartialDevice): '' | FirmwareVersion
}
const { features } = device;
if (isDeviceInBootloaderMode(device)) {
// @ts-expect-error fw_minor and fw_patch is imho always defined. maybe only for some very old firmwares only major version is defined.
return features.fw_major
? `${features.fw_major}.${features.fw_minor}.${features.fw_patch}`
? `${features.fw_major}.${features.fw_minor!}.${features.fw_patch!}`
: '';
}

Expand Down
2 changes: 2 additions & 0 deletions packages/device-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export * from './firmwareUtils';
export * from './bootloaderUtils';
export * from './modelUtils';
export * from './modeUtils';
export * from './types';
export * from './customTypes';
2 changes: 1 addition & 1 deletion packages/device-utils/src/modelUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeviceModelInternal } from '@trezor/connect';
import { DeviceModelInternal } from './customTypes';

export const pickByDeviceModel = <Type>(
deviceModelInternal: DeviceModelInternal | undefined,
Expand Down
82 changes: 77 additions & 5 deletions packages/device-utils/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,80 @@
import { Device } from '@trezor/connect';
export type FirmwareVersionString = `${number}.${number}.${number}`;

export enum FirmwareType {
BitcoinOnly = 'bitcoin-only',
Regular = 'regular',
}

export type VersionArray = [number, number, number];

export type FeaturesNarrowing =
| {
major_version: 2;
minor_version: number;
patch_version: number;
fw_major: null;
fw_minor: null;
fw_patch: null;
bootloader_mode: true;
firmware_present: false;
}
| {
major_version: 2;
minor_version: number;
patch_version: number;
fw_major: null;
fw_minor: null;
fw_patch: null;
bootloader_mode: null;
firmware_present: null;
}
| {
major_version: 2;
minor_version: number;
patch_version: number;
fw_major: 2;
fw_minor: number;
fw_patch: number;
bootloader_mode: true;
firmware_present: true;
}
| {
major_version: 1;
minor_version: number;
patch_version: number;
fw_major: null;
fw_minor: null;
fw_patch: null;
bootloader_mode: true;
firmware_present: false;
}
| {
major_version: 1;
minor_version: number;
patch_version: number;
fw_major: null;
fw_minor: null;
fw_patch: null;
bootloader_mode: true;
firmware_present: true;
};

// todo: this is copy-pasted from packages/protobuf/src/messages
export type PartialDevice = {
features?: Device['features'];
firmwareType?: Device['firmwareType'];
};
firmwareType?: FirmwareType;

export type FirmwareVersionString = `${number}.${number}.${number}`;
features?: {
major_version: number;
minor_version: number;
patch_version: number;
bootloader_mode: boolean | null;
initialized: boolean | null;
revision: string | null;
bootloader_hash: string | null;
fw_major: number | null;
fw_minor: number | null;
fw_patch: number | null;
no_backup: boolean | null;
unit_btconly?: boolean;
};
};
2 changes: 1 addition & 1 deletion packages/device-utils/tests/__fixtures__/modelUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeviceModelInternal } from '@trezor/connect';
import { DeviceModelInternal } from '../../src';

export const OPTIONS = {
default: 'default',
Expand Down
2 changes: 1 addition & 1 deletion packages/device-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": { "outDir": "libDev" },
"references": [{ "path": "../connect" }]
"references": []
}
9 changes: 9 additions & 0 deletions packages/device-utils/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.lib.json",
"compilerOptions": {
"outDir": "./lib",
"types": ["w3c-web-usb", "node"]
},
"include": ["./src"],
"references": []
}
Loading
Loading