chore(utils): move isArrayMember to utils

This commit is contained in:
Jiri Zbytovsky
2024-10-22 18:48:56 +02:00
committed by Jiri Zbytovsky
parent 403eebc6c5
commit 0be00e9571
15 changed files with 21 additions and 27 deletions

View File

@@ -28,7 +28,6 @@
"@trezor/blockchain-link": "workspace:*",
"@trezor/blockchain-link-types": "workspace:*",
"@trezor/blockchain-link-utils": "workspace:*",
"@trezor/type-utils": "workspace:*",
"@trezor/utils": "workspace:*",
"@trezor/utxo-lib": "workspace:*",
"cross-fetch": "^4.0.0",

View File

@@ -1,7 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-var-requires */
import { isArrayMember } from '@trezor/type-utils';
import { isArrayMember } from '@trezor/utils';
import { CoinjoinBackend } from '../../src/backend/CoinjoinBackend';
import type { CoinjoinBackendSettings } from '../../src/types';

View File

@@ -5,7 +5,6 @@
{ "path": "../blockchain-link" },
{ "path": "../blockchain-link-types" },
{ "path": "../blockchain-link-utils" },
{ "path": "../type-utils" },
{ "path": "../utils" },
{ "path": "../utxo-lib" }
]

View File

@@ -2,7 +2,7 @@ import { TranslationKey } from '@suite-common/intl-types';
import { Banner } from '@trezor/components';
import { FirmwareHashCheckError, FirmwareRevisionCheckError } from '@trezor/connect';
import { HELP_CENTER_FIRMWARE_REVISION_CHECK } from '@trezor/urls';
import { isArrayMember } from '@trezor/type-utils';
import { isArrayMember } from '@trezor/utils';
import { Translation, TrezorLink } from 'src/components/suite';
import { useSelector } from 'src/hooks/suite';

View File

@@ -3,7 +3,7 @@ import styled from 'styled-components';
import { selectBannerMessage } from '@suite-common/message-system';
import { selectDevice } from '@suite-common/wallet-core';
import { isArrayMember } from '@trezor/type-utils';
import { isArrayMember } from '@trezor/utils';
import { isDesktop } from '@trezor/env-utils';
import { spacingsPx } from '@trezor/theme';

View File

@@ -1,4 +1,4 @@
import { isArrayMember } from '@trezor/type-utils';
import { isArrayMember } from '@trezor/utils';
class Regional {
unknownCountry = 'unknown';

View File

@@ -1,5 +1,5 @@
import { Account } from '@suite-common/wallet-types';
import { isArrayMember } from '@trezor/type-utils';
import { isArrayMember } from '@trezor/utils';
export function hasNetworkTypeTradableTokens(networkType: Account['networkType']) {
return isArrayMember(networkType, ['ethereum', 'solana'] satisfies Account['networkType'][]);

View File

@@ -58,17 +58,3 @@ export type PartialRecord<K extends keyof any, T> = {
// distributive conditional types to the rescue! This way we can infer union literal type from ReturnType but exclude undefined
export type DefinedUnionMember<T> = T extends string ? T : never;
/**
* Type-guard if a value is a subset of an array.
* Useful to narrow down a union type `value` to a subset of the union (typeof `arr`).
*
* Example:
* type Variant = 'a' | 'b' | 'c' | 'd';
* const skippedVariants = ['a', 'b'] satisfies Variant[];
* if(isArrayMember(variant, skippedVariants)) // variant is 'a' | 'b', else 'c' | 'd'
*/
export const isArrayMember = <Value extends string, Subset extends Value>(
value: Value,
arr: readonly Subset[],
): value is Subset => arr.some(v => v === value);

View File

@@ -25,6 +25,7 @@ export * from './getRandomInt';
export * from './getWeakRandomId';
export * from './getWeakRandomInt';
export * from './hasUppercaseLetter';
export * from './isArrayMember';
export * from './isAscii';
export * from './isHex';
export * from './isNotUndefined';

View File

@@ -0,0 +1,13 @@
/**
* Type-guard if a value is a subset of an array.
* Useful to narrow down a union type `value` to a subset of the union (typeof `arr`).
*
* Example:
* type Variant = 'a' | 'b' | 'c' | 'd';
* const skippedVariants = ['a', 'b'] satisfies Variant[];
* if(isArrayMember(variant, skippedVariants)) // variant is 'a' | 'b', else 'c' | 'd'
*/
export const isArrayMember = <Value extends string, Subset extends Value>(
value: Value,
arr: readonly Subset[],
): value is Subset => arr.some(v => v === value);

View File

@@ -22,7 +22,6 @@
"@suite-common/wallet-utils": "workspace:*",
"@trezor/blockchain-link": "workspace:*",
"@trezor/connect": "workspace:*",
"@trezor/type-utils": "workspace:*",
"@trezor/utils": "workspace:*",
"date-fns": "^2.30.0",
"react": "18.2.0",

View File

@@ -1,5 +1,5 @@
import { NetworkSymbol } from '@suite-common/wallet-config';
import { isArrayMember } from '@trezor/type-utils';
import { isArrayMember } from '@trezor/utils';
// Going over 180 will broke graph in mobile app
export const NUMBER_OF_POINTS = 40;

View File

@@ -12,7 +12,6 @@
"path": "../../packages/blockchain-link"
},
{ "path": "../../packages/connect" },
{ "path": "../../packages/type-utils" },
{ "path": "../../packages/utils" }
]
}

View File

@@ -10,7 +10,7 @@ import {
} from '@suite-common/wallet-types';
import { FiatCurrencyCode } from '@suite-common/suite-config';
import { FeeLevel } from '@trezor/connect';
import { isArrayMember } from '@trezor/type-utils';
import { isArrayMember } from '@trezor/utils';
// Used when Everstake pool stats are not available from the API.
export const BACKUP_ETH_APY = 4.13;

View File

@@ -9179,7 +9179,6 @@ __metadata:
"@suite-common/wallet-utils": "workspace:*"
"@trezor/blockchain-link": "workspace:*"
"@trezor/connect": "workspace:*"
"@trezor/type-utils": "workspace:*"
"@trezor/utils": "workspace:*"
date-fns: "npm:^2.30.0"
react: "npm:18.2.0"
@@ -11247,7 +11246,6 @@ __metadata:
"@trezor/blockchain-link": "workspace:*"
"@trezor/blockchain-link-types": "workspace:*"
"@trezor/blockchain-link-utils": "workspace:*"
"@trezor/type-utils": "workspace:*"
"@trezor/utils": "workspace:*"
"@trezor/utxo-lib": "workspace:*"
cross-fetch: "npm:^4.0.0"