chore(monorepo): remove dependency on connect in components and device-utils

This commit is contained in:
Martin Varmuza
2025-03-05 12:11:49 +01:00
committed by martin
parent e6c1f3e8ca
commit 465f40a072
42 changed files with 154 additions and 110 deletions

View File

@@ -26,9 +26,9 @@
"@suite-common/validators": "workspace:*",
"@testing-library/jest-dom": "^6.6.3",
"@trezor/asset-utils": "workspace:*",
"@trezor/connect": "workspace:*",
"@trezor/dom-utils": "workspace:*",
"@trezor/env-utils": "workspace:*",
"@trezor/protobuf": "workspace:*",
"@trezor/react-utils": "workspace:*",
"@trezor/styles": "workspace:*",
"@trezor/theme": "workspace:*",

View File

@@ -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/protobuf';
import { AnimationWrapper, Shape } from './AnimationPrimitives';
import { resolveStaticPath } from '../../utils/resolveStaticPath';

View File

@@ -5,7 +5,8 @@ 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';
// todo: components should not rely on @trezor/protobuf
import { DeviceModelInternal } from '@trezor/protobuf';
import { AnimationWrapper, Shape } from './AnimationPrimitives';
import { resolveStaticPath } from '../../utils/resolveStaticPath';

View File

@@ -27,9 +27,9 @@
"path": "../../suite-common/validators"
},
{ "path": "../asset-utils" },
{ "path": "../connect" },
{ "path": "../dom-utils" },
{ "path": "../env-utils" },
{ "path": "../protobuf" },
{ "path": "../react-utils" },
{ "path": "../styles" },
{ "path": "../theme" },

View File

@@ -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:*",

View File

@@ -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';

View File

@@ -1,4 +1,4 @@
import type { VersionArray } from '../../types/firmware';
import type { VersionArray } from '@trezor/device-utils';
/**
* parse firmware headers
* based on

View File

@@ -1,5 +1,7 @@
// origin: https://github.com/trezor/connect/blob/develop/src/js/data/FirmwareInfo.js
import { VersionArray } from '@trezor/device-utils';
import { DeviceModelInternal } from '@trezor/protobuf';
import { versionUtils } from '@trezor/utils';
import type {
@@ -8,9 +10,7 @@ import type {
IntermediaryVersion,
ReleaseInfo,
StrictFeatures,
VersionArray,
} from '../types';
import { DeviceModelInternal } from '../types';
import {
filterSafeListByBootloader,
filterSafeListByFirmware,

View File

@@ -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;

View File

@@ -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';

View File

View File

@@ -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>;

View File

@@ -1,3 +1,4 @@
import { FeaturesNarrowing, FirmwareType } from '@trezor/device-utils';
import { Descriptor } from '@trezor/transport';
import type { PROTO } from '../constants';
@@ -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 = {
@@ -163,46 +159,4 @@ export { DeviceModelInternal } from '@trezor/protobuf';
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;

View File

@@ -1,3 +1,4 @@
import { VersionArray } from '@trezor/device-utils';
import { DeviceModelInternal } from '@trezor/protobuf';
import { Type } from '@trezor/schema-utils';
@@ -9,8 +10,6 @@ export type FirmwareRange = Record<
}
>;
export type VersionArray = [number, number, number];
export type FirmwareRelease = {
required: boolean;
url: string;

View File

@@ -42,3 +42,5 @@ export type {
Target as TransactionTarget,
AccountBalanceHistory as BlockchainAccountBalanceHistory,
} from '@trezor/blockchain-link';
export { FirmwareType, type VersionArray } from '@trezor/device-utils';

View File

@@ -8,6 +8,7 @@
{ "path": "../connect-analytics" },
{ "path": "../connect-common" },
{ "path": "../crypto-utils" },
{ "path": "../device-utils" },
{ "path": "../protobuf" },
{ "path": "../protocol" },
{ "path": "../schema-utils" },

View File

@@ -24,6 +24,9 @@
{
"path": "../crypto-utils"
},
{
"path": "../device-utils"
},
{
"path": "../protobuf"
},

View File

@@ -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:*"
"test:unit": "yarn g:jest -c ../../jest.config.base.js --passWithNoTests"
}
}

View File

@@ -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 || '';
@@ -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!}`
: '';
}

View File

@@ -1,4 +1,4 @@
export * from './firmwareUtils';
export * from './bootloaderUtils';
export * from './modelUtils';
export * from './modeUtils';
export * from './types';

View File

@@ -1,8 +1,80 @@
import { Device } from '@trezor/connect';
export type PartialDevice = {
features?: Device['features'];
firmwareType?: Device['firmwareType'];
};
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 = {
firmwareType?: FirmwareType;
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;
};
};

View File

@@ -1,10 +0,0 @@
import { pickByDeviceModel } from '../src';
import { OPTIONS, fixtures } from './__fixtures__/modelUtils';
describe('pickByDeviceModel', () => {
fixtures.forEach(f => {
it(f.description, () => {
expect(pickByDeviceModel(f.deviceModelInternal, OPTIONS)).toBe(f.expectedResult);
});
});
});

View File

@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": { "outDir": "libDev" },
"references": [{ "path": "../connect" }]
"references": []
}

View File

@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.lib.json",
"compilerOptions": {
"outDir": "./lib",
"types": ["w3c-web-usb", "node"]
},
"include": ["./src"],
"references": []
}

View File

@@ -19,10 +19,11 @@
"@suite-common/validators": "workspace:*",
"@suite-common/wallet-config": "workspace:*",
"@suite-common/wallet-utils": "workspace:*",
"@trezor/blockchain-link-types": "workspace:*",
"@trezor/components": "workspace:*",
"@trezor/connect": "workspace:*",
"@trezor/dom-utils": "workspace:*",
"@trezor/env-utils": "workspace:*",
"@trezor/protobuf": "workspace:*",
"@trezor/react-utils": "workspace:*",
"@trezor/theme": "workspace:*",
"@trezor/urls": "workspace:*",

View File

@@ -1,7 +1,8 @@
import { Meta, StoryFn } from '@storybook/react';
import { StoryColumn } from '@trezor/components';
import { DeviceModelInternal } from '@trezor/connect';
// todo: product-components should not depend on protobuf
import { DeviceModelInternal } from '@trezor/protobuf';
import { ConfirmOnDevice as ConfirmOnDeviceComponent } from './ConfirmOnDevice';

View File

@@ -3,7 +3,7 @@ import { ReactNode } from 'react';
import styled, { css, keyframes } from 'styled-components';
import { ElevationUp } from '@trezor/components';
import { DeviceModelInternal } from '@trezor/connect';
import { DeviceModelInternal } from '@trezor/protobuf';
import { borders, spacingsPx } from '@trezor/theme';
import { ConfirmOnDeviceContent } from './ConfirmOnDeviceContent';

View File

@@ -3,7 +3,7 @@ import { ReactNode } from 'react';
import styled, { css } from 'styled-components';
import { Column, IconButton, Row, Text } from '@trezor/components';
import { DeviceModelInternal } from '@trezor/connect';
import { DeviceModelInternal } from '@trezor/protobuf';
import { borders, spacings, spacingsPx } from '@trezor/theme';
import { RotateDeviceImage } from '../RotateDeviceImage/RotateDeviceImage';

View File

@@ -3,7 +3,7 @@ import { FormattedMessage } from 'react-intl';
import styled, { useTheme } from 'styled-components';
import { Icon, Image, Row, Text } from '@trezor/components';
import { DeviceModelInternal } from '@trezor/connect';
import { DeviceModelInternal } from '@trezor/protobuf';
import { spacings } from '@trezor/theme';
import { CardButton } from '../CardButton/CardButton';

View File

@@ -5,8 +5,8 @@ import styled, { css } from 'styled-components';
import { formInputsMaxLength } from '@suite-common/validators';
import { TooltipProps } from '@trezor/components';
import { DeviceModelInternal, Features } from '@trezor/connect';
import { setCaretPosition } from '@trezor/dom-utils';
import { DeviceModelInternal } from '@trezor/protobuf';
import { useKeyPress } from '@trezor/react-utils';
import { borders, spacingsPx } from '@trezor/theme';
import { countBytesInString } from '@trezor/utils';
@@ -64,7 +64,7 @@ export type PassphraseTypeCardProps = {
offerPassphraseOnDevice?: boolean;
singleColModal?: boolean;
deviceModel?: DeviceModelInternal;
deviceBackup?: Features['backup_type'] | null;
deviceBackup?: string | null;
onSubmit: (value: string, passphraseOnDevice?: boolean) => void;
learnMoreTooltipOnClick?: TooltipProps['addon'];
learnMoreTooltipAppendTo?: TooltipProps['appendTo'];

View File

@@ -1,6 +1,6 @@
import { Meta, StoryObj } from '@storybook/react';
import { DeviceModelInternal } from '@trezor/connect';
import { DeviceModelInternal } from '@trezor/protobuf';
import {
RotateDeviceImage as RotateDeviceImageComponent,

View File

@@ -1,7 +1,7 @@
import React from 'react';
import { DeviceAnimation } from '@trezor/components';
import { DeviceModelInternal } from '@trezor/connect';
import { DeviceModelInternal } from '@trezor/protobuf';
export type RotateDeviceImageProps = {
deviceModel?: DeviceModelInternal;

View File

@@ -2,8 +2,8 @@ import styled, { css } from 'styled-components';
import { NetworkSymbol, getCoingeckoId } from '@suite-common/wallet-config';
import { getContractAddressForNetworkSymbol } from '@suite-common/wallet-utils';
import { type TokenInfo } from '@trezor/blockchain-link-types';
import { AssetLogo, useElevation } from '@trezor/components';
import { TokenInfo } from '@trezor/connect';
import { Elevation, borders, mapElevationToBackground, mapElevationToBorder } from '@trezor/theme';
export type TokenIconSetProps = {

View File

@@ -1,5 +1,5 @@
import { IconName } from '@trezor/components';
import { DeviceModelInternal } from '@trezor/connect';
import { DeviceModelInternal } from '@trezor/protobuf';
export const mapTrezorModelToIcon: Record<DeviceModelInternal, IconName> = {
[DeviceModelInternal.UNKNOWN]: 'trezorModelOneFilled', // Just to provide something that wont break UI

View File

@@ -22,10 +22,11 @@
{
"path": "../../suite-common/wallet-utils"
},
{ "path": "../blockchain-link-types" },
{ "path": "../components" },
{ "path": "../connect" },
{ "path": "../dom-utils" },
{ "path": "../env-utils" },
{ "path": "../protobuf" },
{ "path": "../react-utils" },
{ "path": "../theme" },
{ "path": "../urls" },

View File

@@ -71,6 +71,7 @@
"@trezor/env-utils": "workspace:*",
"@trezor/ipc-proxy": "workspace:*",
"@trezor/product-components": "workspace:*",
"@trezor/protobuf": "workspace:*",
"@trezor/react-utils": "workspace:*",
"@trezor/styles": "workspace:*",
"@trezor/suite-analytics": "workspace:*",

View File

@@ -1,12 +1,14 @@
import { DeviceModelInternal } from '@trezor/connect';
import { DeviceModelInternal } from '@trezor/protobuf';
export const OPTIONS = {
import { pickByDeviceModel } from '../modelUtils';
const OPTIONS = {
default: 'default',
[DeviceModelInternal.T1B1]: null,
[DeviceModelInternal.T3T1]: 'T3T1',
};
export const fixtures = [
const fixtures = [
{
description: 'should return correct value for a given device',
deviceModelInternal: DeviceModelInternal.T3T1,
@@ -28,3 +30,11 @@ export const fixtures = [
expectedResult: 'default',
},
];
describe('pickByDeviceModel', () => {
fixtures.forEach(f => {
it(f.description, () => {
expect(pickByDeviceModel(f.deviceModelInternal, OPTIONS)).toBe(f.expectedResult);
});
});
});

View File

@@ -3,7 +3,6 @@ import styled from 'styled-components';
import { isDeviceWithButtons } from '@suite-common/suite-utils';
import { selectSelectedDevice } from '@suite-common/wallet-core';
import { DeviceModelInternal } from '@trezor/connect';
import { pickByDeviceModel } from '@trezor/device-utils';
import { goToNextStep, updateAnalytics } from 'src/actions/onboarding/onboardingActions';
import { OnboardingButtonCta } from 'src/components/onboarding';
@@ -11,6 +10,7 @@ import { SelectRecoveryType, SelectRecoveryWord, SelectWordCount } from 'src/com
import { Translation } from 'src/components/suite';
import { useDispatch, useRecovery, useSelector } from 'src/hooks/suite';
import { selectIsActionAbortable } from 'src/reducers/suite/suiteReducer';
import { pickByDeviceModel } from 'src/utils/device/modelUtils';
import RecoveryStepBox from './RecoveryStepBox';

View File

@@ -9,7 +9,6 @@ import {
} from '@suite-common/suite-utils';
import { BulletList, Card, H2, H3, Image, NewModal, Paragraph } from '@trezor/components';
import TrezorConnect, { DeviceModelInternal } from '@trezor/connect';
import { pickByDeviceModel } from '@trezor/device-utils';
import { spacings } from '@trezor/theme';
import {
@@ -26,6 +25,7 @@ import { useDevice, useDispatch, useSelector } from 'src/hooks/suite';
import messages from 'src/support/messages';
import type { WordCount } from 'src/types/recovery';
import type { ForegroundAppProps } from 'src/types/suite';
import { pickByDeviceModel } from 'src/utils/device/modelUtils';
import { EnterOnDeviceStep } from './steps/EnterOnDeviceStep';
import { T1B1InputStep } from './steps/T1B1InputStep';

View File

@@ -102,6 +102,7 @@
{ "path": "../env-utils" },
{ "path": "../ipc-proxy" },
{ "path": "../product-components" },
{ "path": "../protobuf" },
{ "path": "../react-utils" },
{ "path": "../styles" },
{ "path": "../suite-analytics" },

View File

@@ -11676,10 +11676,10 @@ __metadata:
"@testing-library/react": "npm:14.2.1"
"@testing-library/user-event": "npm:^14.6.1"
"@trezor/asset-utils": "workspace:*"
"@trezor/connect": "workspace:*"
"@trezor/dom-utils": "workspace:*"
"@trezor/env-utils": "workspace:*"
"@trezor/eslint": "workspace:*"
"@trezor/protobuf": "workspace:*"
"@trezor/react-utils": "workspace:*"
"@trezor/styles": "workspace:*"
"@trezor/theme": "workspace:*"
@@ -12046,6 +12046,7 @@ __metadata:
"@trezor/connect-analytics": "workspace:*"
"@trezor/connect-common": "workspace:*"
"@trezor/crypto-utils": "workspace:*"
"@trezor/device-utils": "workspace:*"
"@trezor/eslint": "workspace:*"
"@trezor/protobuf": "workspace:*"
"@trezor/protocol": "workspace:*"
@@ -12093,8 +12094,6 @@ __metadata:
"@trezor/device-utils@workspace:*, @trezor/device-utils@workspace:packages/device-utils":
version: 0.0.0-use.local
resolution: "@trezor/device-utils@workspace:packages/device-utils"
dependencies:
"@trezor/connect": "workspace:*"
languageName: unknown
linkType: soft
@@ -12185,11 +12184,12 @@ __metadata:
"@suite-common/validators": "workspace:*"
"@suite-common/wallet-config": "workspace:*"
"@suite-common/wallet-utils": "workspace:*"
"@trezor/blockchain-link-types": "workspace:*"
"@trezor/components": "workspace:*"
"@trezor/connect": "workspace:*"
"@trezor/dom-utils": "workspace:*"
"@trezor/env-utils": "workspace:*"
"@trezor/eslint": "workspace:*"
"@trezor/protobuf": "workspace:*"
"@trezor/react-utils": "workspace:*"
"@trezor/theme": "workspace:*"
"@trezor/urls": "workspace:*"
@@ -12654,6 +12654,7 @@ __metadata:
"@trezor/eslint": "workspace:*"
"@trezor/ipc-proxy": "workspace:*"
"@trezor/product-components": "workspace:*"
"@trezor/protobuf": "workspace:*"
"@trezor/react-utils": "workspace:*"
"@trezor/styles": "workspace:*"
"@trezor/suite-analytics": "workspace:*"