chore: unify resolveStaticPath

This commit is contained in:
Jiri Zbytovsky
2025-11-18 14:49:54 +01:00
committed by Jiri Zbytovsky
parent 25954795c0
commit 318272410b
26 changed files with 25 additions and 58 deletions

View File

@@ -1,7 +1,8 @@
import styled from 'styled-components';
import { resolveStaticPath } from '@trezor/env-utils';
import { FLAGS } from './flags';
import { resolveStaticPath } from '../../utils/resolveStaticPath';
import { IMAGES_PATH } from '../Image/Image';
export type FlagType = keyof typeof FLAGS;

View File

@@ -2,6 +2,7 @@ import { ImgHTMLAttributes } from 'react';
import styled from 'styled-components';
import { resolveStaticPath } from '@trezor/env-utils';
import { isArrayMember, typedObjectEntries } from '@trezor/utils';
import { IMAGES, ImageType } from './images';
@@ -11,7 +12,6 @@ import {
pickAndPrepareFrameProps,
withFrameProps,
} from '../../utils/frameProps';
import { resolveStaticPath } from '../../utils/resolveStaticPath';
import { TransientProps } from '../../utils/transientProps';
export const allowedImageFrameProps = [

View File

@@ -7,9 +7,9 @@ import styled from 'styled-components';
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { DEFAULT_FLAGSHIP_MODEL } from '@suite-common/suite-constants';
import { DeviceModelInternal } from '@trezor/device-utils';
import { resolveStaticPath } from '@trezor/env-utils';
import { AnimationWrapper, Shape } from './AnimationPrimitives';
import { resolveStaticPath } from '../../utils/resolveStaticPath';
const StyledLottie = styled(Lottie)`
width: 100%;

View File

@@ -1,16 +0,0 @@
import { isWeb } from '@trezor/env-utils';
// This needs to be set as `.` so it loads from appDir of the Electron app.
// For example (in case of AppImage): `file:///tmp/.mount_TrezorAvGo8g/resources/app.asar/build`,
// where the requested asset (for example: `static/images/images/app-store-badge.svg`) is located.
const DEFAULT_ASSET_PREFIX = isWeb() ? '' : '.';
// todo: this should be shared with resolveStaticPath in suite-common/suite-utils/src/resolveStaticPath
// the problem is that @trezor scoped package must not import from @suite-common scoped package
// followup: create SuiteImage, SuiteDeviceAnimation component wrapper that will use resolveStaticPath util and pass it to Image component
// https://github.com/trezor/trezor-suite/issues/8433
export const resolveStaticPath = (
path: string,
pathPrefix: string | undefined = typeof process !== 'undefined'
? process.env.ASSET_PREFIX
: DEFAULT_ASSET_PREFIX,
) => `${pathPrefix || DEFAULT_ASSET_PREFIX}/static/${path.replace(/^\/+/, '')}`;

View File

@@ -0,0 +1,5 @@
const baseConfig = require('../../jest.config.base');
module.exports = {
...baseConfig,
};

View File

@@ -23,6 +23,8 @@
"scripts": {
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"test:unit": "yarn g:jest",
"test-unit:watch": "yarn g:jest -o --watch",
"build:lib": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.lib.json && ../../scripts/replace-imports.sh ./lib",
"prepublishOnly": "yarn tsx ../../scripts/prepublishNPM.js",
"prepublish": "yarn tsx ../../scripts/prepublish.js"

View File

@@ -38,3 +38,5 @@ export const {
getJWSPublicKey,
getFirmwareReleaseJwsPublicKey,
} = envUtils;
export { resolveStaticPath, resolveConnectPath } from './resolveStaticPath';

View File

@@ -1,8 +1,8 @@
import { isWeb } from '@trezor/env-utils';
const isWeb = () => process.env.SUITE_TYPE === 'web'; // duplicated with envUtils.ts to prevent importing it in mobile
// This needs to be set as `.` so it loads from appDir of the Electron app.
// For example (in case of AppImage): `file:///tmp/.mount_TrezorAvGo8g/resources/app.asar/build`,
// where the requested asset (for example: `static/images/images/app-store-badge.svg`) is located.
const DEFAULT_ASSET_PREFIX = isWeb() ? '' : '.';
export const resolveStaticPath = (

View File

@@ -2,7 +2,7 @@ import { MouseEventHandler } from 'react';
import styled from 'styled-components';
import { resolveStaticPath } from '../../utils/resolveStaticPath';
import { resolveStaticPath } from '@trezor/env-utils';
const StyledVideo = styled.video`
max-width: 100%;
max-height: 100%;

View File

@@ -1,6 +1,5 @@
import { IMAGES_PATH } from '@trezor/components';
import { resolveStaticPath } from '../../utils/resolveStaticPath';
import { resolveStaticPath } from '@trezor/env-utils';
export const LOGOS: { [key: string]: any } = {
HORIZONTAL: resolveStaticPath(`${IMAGES_PATH}/logos/trezor_logo_horizontal.svg`),

View File

@@ -1,16 +0,0 @@
import { isWeb } from '@trezor/env-utils';
// This needs to be set as `.` so it loads from appDir of the Electron app.
// For example (in case of AppImage): `file:///tmp/.mount_TrezorAvGo8g/resources/app.asar/build`,
// where the requested asset (for example: `static/images/images/app-store-badge.svg`) is located.
const DEFAULT_ASSET_PREFIX = isWeb() ? '' : '.';
// todo: this should be shared with resolveStaticPath in suite-common/suite-utils/src/resolveStaticPath
// the problem is that @trezor scoped package must not import from @suite-common scoped package
// followup: create SuiteImage, SuiteDeviceAnimation component wrapper that will use resolveStaticPath util and pass it to Image component
// https://github.com/trezor/trezor-suite/issues/8433
export const resolveStaticPath = (
path: string,
pathPrefix: string | undefined = typeof process !== 'undefined'
? process.env.ASSET_PREFIX
: DEFAULT_ASSET_PREFIX,
) => `${pathPrefix || DEFAULT_ASSET_PREFIX}/static/${path.replace(/^\/+/, '')}`;

View File

@@ -19,7 +19,6 @@
},
"dependencies": {
"@suite-common/suite-types": "workspace:*",
"@suite-common/suite-utils": "workspace:*",
"@trezor/env-utils": "workspace:*",
"semver": "^7.7.1"
},

View File

@@ -3,7 +3,7 @@ import * as fs from 'fs-extra';
import { join } from 'path';
import { GuideNode } from '@suite-common/suite-types';
import { resolveStaticPath } from '@suite-common/suite-utils';
import { resolveStaticPath } from '@trezor/env-utils';
/** Removes the front-matter from beginning of a string. */
const clean = (markdown: string): string => markdown.replace(/^---\n.*?\n---\n/s, '');

View File

@@ -9,9 +9,6 @@
{
"path": "../../suite-common/suite-types"
},
{
"path": "../../suite-common/suite-utils"
},
{ "path": "../env-utils" },
{ "path": "../eslint" }
]

View File

@@ -1,7 +1,7 @@
import styled from 'styled-components';
import { resolveStaticPath } from '@suite-common/suite-utils';
import { IMAGES, IMAGES_PATH, Image } from '@trezor/components';
import { resolveStaticPath } from '@trezor/env-utils';
const ImageWrapper = styled.div<{
$maxHeight?: number;

View File

@@ -1,8 +1,8 @@
import styled from 'styled-components';
import { resolveStaticPath } from '@suite-common/suite-utils';
import { IMAGES, IMAGES_PATH, Image } from '@trezor/components';
import { DeviceModelInternal } from '@trezor/device-utils';
import { resolveStaticPath } from '@trezor/env-utils';
export const DEFAULT_CONNECT_DEVICE_NAME = 'T3T1-CONNECT-ON' as const;
// component taken from native part of app, edit for desktop & web usage only for one model

View File

@@ -3,8 +3,8 @@ import { ReactNode } from 'react';
import styled, { useTheme } from 'styled-components';
import { GuideNode as GuideNodeType } from '@suite-common/suite-types';
import { resolveStaticPath } from '@suite-common/suite-utils';
import { Icon, variables } from '@trezor/components';
import { resolveStaticPath } from '@trezor/env-utils';
import { EventType, analytics } from '@trezor/suite-analytics';
import { borders, spacings } from '@trezor/theme';

View File

@@ -1,8 +1,8 @@
import styled from 'styled-components';
import { resolveStaticPath } from '@suite-common/suite-utils';
import { Grid } from '@trezor/components';
import { DeviceModelInternal, hasBitcoinOnlyFirmware } from '@trezor/device-utils';
import { resolveStaticPath } from '@trezor/env-utils';
import { borders, spacings } from '@trezor/theme';
import { exhaustive } from '@trezor/type-utils';

View File

@@ -1,7 +1,7 @@
import styled, { useTheme } from 'styled-components';
import { resolveStaticPath } from '@suite-common/suite-utils';
import { Box, Button, Column, IMAGES, IMAGES_PATH, Row, Text } from '@trezor/components';
import { resolveStaticPath } from '@trezor/env-utils';
import { borders, colorVariants, spacings, spacingsPx } from '@trezor/theme';
import { DASHBOARD_BANNER_TEX_URL } from '@trezor/urls';

View File

@@ -1,7 +1,7 @@
import styled from 'styled-components';
import { resolveStaticPath } from '@suite-common/suite-utils';
import { Card, IMAGES, variables } from '@trezor/components';
import { resolveStaticPath } from '@trezor/env-utils';
import TooltipSymbol from 'src/components/suite/TooltipSymbol';
import { Translation } from 'src/components/suite/Translation';

View File

@@ -13,7 +13,6 @@
"@reduxjs/toolkit": "2.10.1",
"@suite-common/redux-utils": "workspace:*",
"@suite-common/suite-types": "workspace:*",
"@suite-common/suite-utils": "workspace:*",
"@suite-common/thp": "workspace:*",
"@suite-common/wallet-core": "workspace:*",
"@trezor/connect": "workspace:*",

View File

@@ -1,6 +1,5 @@
import { createThunk } from '@suite-common/redux-utils';
import { resolveConnectPath } from '@suite-common/suite-utils';
import { isDesktop } from '@trezor/env-utils';
import { isDesktop, resolveConnectPath } from '@trezor/env-utils';
import { FIRMWARE_MODULE_PREFIX } from './firmwareActions';

View File

@@ -4,7 +4,6 @@
"references": [
{ "path": "../redux-utils" },
{ "path": "../suite-types" },
{ "path": "../suite-utils" },
{ "path": "../thp" },
{ "path": "../wallet-core" },
{ "path": "../../packages/connect" },

View File

@@ -2,7 +2,6 @@ export * from './date';
export * from './device';
export * from './features';
export * from './build';
export * from './resolveStaticPath';
export * from './txsPerPage';
export * from './parseFirmwareChangelog';
export * from './protocol';

View File

@@ -10528,7 +10528,6 @@ __metadata:
"@reduxjs/toolkit": "npm:2.10.1"
"@suite-common/redux-utils": "workspace:*"
"@suite-common/suite-types": "workspace:*"
"@suite-common/suite-utils": "workspace:*"
"@suite-common/thp": "workspace:*"
"@suite-common/wallet-core": "workspace:*"
"@trezor/connect": "workspace:*"
@@ -14264,7 +14263,6 @@ __metadata:
dependencies:
"@mobily/ts-belt": "npm:^3.13.1"
"@suite-common/suite-types": "workspace:*"
"@suite-common/suite-utils": "workspace:*"
"@trezor/env-utils": "workspace:*"
"@trezor/eslint": "workspace:*"
"@types/fs-extra": "npm:^11.0.4"