mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-03 05:55:03 +01:00
chore: prune dead code from suite-common and utils
This commit is contained in:
committed by
Jiri Zbytovsky
parent
283e9a51a4
commit
40754b1f15
@@ -2,11 +2,3 @@ import { PartialDevice } from './types';
|
||||
|
||||
export const isDeviceInBootloaderMode = (device?: PartialDevice) =>
|
||||
!!device?.features?.bootloader_mode;
|
||||
|
||||
export const getDeviceMode = (device?: PartialDevice) => {
|
||||
if (device?.features?.bootloader_mode) return 'bootloader';
|
||||
if (!device?.features?.initialized) return 'initialize';
|
||||
if (device?.features?.no_backup) return 'seedless';
|
||||
|
||||
return 'normal';
|
||||
};
|
||||
|
||||
@@ -9,7 +9,6 @@ export function getLocaleSeparators(locale: string): {
|
||||
|
||||
// Find the thousand and decimal separators
|
||||
let thousandsSeparator = ' ';
|
||||
let decimalSeparator = '.';
|
||||
|
||||
// Since the number is 1,234,567.89 or 1.234.567,89 or similar,
|
||||
// the last non-numeric character before the last 2 digits is the decimal separator
|
||||
@@ -21,7 +20,7 @@ export function getLocaleSeparators(locale: string): {
|
||||
}
|
||||
}
|
||||
|
||||
decimalSeparator = formattedNumber[formattedNumber.length - 3];
|
||||
const decimalSeparator = formattedNumber[formattedNumber.length - 3];
|
||||
|
||||
return { decimalSeparator, thousandsSeparator };
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { type Locale } from 'date-fns';
|
||||
import {
|
||||
differenceInCalendarMonths,
|
||||
differenceInMinutes,
|
||||
differenceInMonths,
|
||||
eachDayOfInterval,
|
||||
eachMonthOfInterval,
|
||||
@@ -73,19 +72,6 @@ export const calcTicksFromData = (data: { time: number }[]) => {
|
||||
return timestamps;
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated It's not needed anymore, new blockbook will handle it
|
||||
*/
|
||||
export const getBlockbookSafeTime = (timestamp?: number) => {
|
||||
const currentTimestamp = getUnixTime(new Date());
|
||||
if (timestamp && differenceInMinutes(currentTimestamp * 1000, timestamp * 1000) > 3) {
|
||||
// timestamp is older than 3 mins, no adjustment needed
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
return currentTimestamp - 180;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets hh:mm:ss to 00:00:00 in local timezone (UTC time may be different).
|
||||
* If `resetDay` is true sets date to the first of the month
|
||||
@@ -105,26 +91,3 @@ export const resetTime = (ts: number, resetDay?: boolean) => {
|
||||
|
||||
return getUnixTime(sanitizedTimestamp);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets hh:mm:ss to 00:00:00 in UTC.
|
||||
* If `resetDay` is true sets date to the first of the month
|
||||
* Returns unix timestamp
|
||||
*
|
||||
* @param {number} ts
|
||||
* @param {boolean} [resetDay]
|
||||
* @returns
|
||||
*/
|
||||
export const resetUTCTime = (ts: number, resetDay?: boolean) => {
|
||||
let sanitizedTimestamp = fromUnixTime(ts);
|
||||
sanitizedTimestamp = fromUnixTime(sanitizedTimestamp.setUTCHours(0) / 1000);
|
||||
sanitizedTimestamp = fromUnixTime(sanitizedTimestamp.setUTCMinutes(0) / 1000);
|
||||
sanitizedTimestamp = fromUnixTime(sanitizedTimestamp.setUTCSeconds(0) / 1000);
|
||||
|
||||
if (resetDay) {
|
||||
sanitizedTimestamp = fromUnixTime(sanitizedTimestamp.setUTCDate(1) / 1000);
|
||||
}
|
||||
const sanitizedUnixTimestamp = getUnixTime(sanitizedTimestamp);
|
||||
|
||||
return sanitizedUnixTimestamp;
|
||||
};
|
||||
|
||||
@@ -5,6 +5,5 @@ export * from './build';
|
||||
export * from './resolveStaticPath';
|
||||
export * from './txsPerPage';
|
||||
export * from './parseFirmwareChangelog';
|
||||
export * from './uppercaseType';
|
||||
export * from './protocol';
|
||||
export * from './invariant';
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export function toUppercaseType<T extends string>(value: T): Uppercase<T> {
|
||||
return value.toUpperCase() as Uppercase<T>;
|
||||
}
|
||||
@@ -22,8 +22,6 @@ import {
|
||||
} from '../../utils';
|
||||
import { buyUtils } from '../../utils/buy/buyUtils';
|
||||
|
||||
export const BUY_THUNK_COMMON_PREFIX = '@trading-buy/thunk';
|
||||
|
||||
type GetQuotesRequest = {
|
||||
requestData: BuyTradeQuoteRequest;
|
||||
signal: AbortSignal | null;
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
type NetworkFeature,
|
||||
type NetworkSymbol,
|
||||
type NetworkSymbolExtended,
|
||||
type NormalizedNetworkAccount,
|
||||
} from './types';
|
||||
|
||||
export const NORMAL_ACCOUNT_TYPE = 'normal' satisfies AccountType;
|
||||
@@ -28,23 +27,6 @@ export const getTestnets = (debug = false) =>
|
||||
|
||||
export const getTestnetSymbols = () => getTestnets().map(n => n.symbol);
|
||||
|
||||
/**
|
||||
* For a given network, return a collection of accounts incl. 'normal', and with missing properties backfilled from 'normal'
|
||||
*/
|
||||
export const normalizeNetworkAccounts = (network: Network): NormalizedNetworkAccount[] => {
|
||||
const normalAccount: NormalizedNetworkAccount = {
|
||||
accountType: NORMAL_ACCOUNT_TYPE,
|
||||
bip43Path: network.bip43Path,
|
||||
features: network.features,
|
||||
};
|
||||
const alternativeAccounts = Object.values(network.accountTypes).map(account => ({
|
||||
...normalAccount,
|
||||
...account,
|
||||
}));
|
||||
|
||||
return [normalAccount, ...alternativeAccounts];
|
||||
};
|
||||
|
||||
export const isBlockbookBasedNetwork = (symbol: NetworkSymbol) =>
|
||||
networks[symbol]?.backendTypes.some(backend => backend === 'blockbook');
|
||||
|
||||
@@ -67,8 +49,6 @@ export const getNetworkFeatures = (symbol: NetworkSymbol): NetworkFeature[] =>
|
||||
|
||||
export const getCoingeckoId = (symbol: NetworkSymbol) => networks[symbol].coingeckoId;
|
||||
|
||||
export const getTradeCryptoId = (symbol: NetworkSymbol) => networks[symbol].tradeCryptoId;
|
||||
|
||||
export const isNetworkSymbol = (symbol: NetworkSymbolExtended): symbol is NetworkSymbol =>
|
||||
Object.prototype.hasOwnProperty.call(networks, symbol);
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { TranslationKey } from '@suite-common/intl-types';
|
||||
import { testMocks } from '@suite-common/test-utils';
|
||||
import type {
|
||||
Bip43Path,
|
||||
Bip43PathTemplate,
|
||||
@@ -8,47 +7,6 @@ import type {
|
||||
|
||||
import { ACCOUNTS } from './accounts';
|
||||
|
||||
const DISCOVERIES = [
|
||||
{
|
||||
deviceState: '1stTestnet@device_id:0',
|
||||
index: 0,
|
||||
status: 4,
|
||||
total: 35,
|
||||
bundleSize: 0,
|
||||
loaded: 39,
|
||||
failed: [],
|
||||
networks: ['btc', 'btc', 'btc', 'test', 'test', 'test', 'eth', 'txrp'],
|
||||
},
|
||||
];
|
||||
|
||||
export const getDiscoveryProcess = [
|
||||
{
|
||||
testName: 'Discovery for 1stTestnet@device_id:0 device',
|
||||
discoveries: DISCOVERIES,
|
||||
device: testMocks.getSuiteDevice({
|
||||
state: '1stTestnet@device_id:0',
|
||||
}),
|
||||
result: {
|
||||
bundleSize: 0,
|
||||
deviceState: '1stTestnet@device_id:0',
|
||||
failed: [],
|
||||
index: 0,
|
||||
loaded: 39,
|
||||
networks: ['btc', 'btc', 'btc', 'test', 'test', 'test', 'eth', 'txrp'],
|
||||
status: 4,
|
||||
total: 35,
|
||||
},
|
||||
},
|
||||
{
|
||||
testName: 'Discovery for 1stTestnet@device_id:1 device',
|
||||
discoveries: DISCOVERIES,
|
||||
device: testMocks.getSuiteDevice({
|
||||
state: '1stTestnet@device_id:1',
|
||||
}),
|
||||
result: null,
|
||||
},
|
||||
];
|
||||
|
||||
export const accountTitleCoinjoinFixture: Array<{
|
||||
symbol: NetworkSymbolExtended;
|
||||
title: TranslationKey;
|
||||
|
||||
@@ -286,9 +286,6 @@ export const getAccountTypeUrl = (path: string) => {
|
||||
|
||||
export const getAccountDecimals = (symbol: NetworkSymbol) => networks[symbol]?.decimals;
|
||||
|
||||
export const stripNetworkAmount = (amount: string, decimals: number) =>
|
||||
new BigNumber(amount).toFixed(decimals, 1);
|
||||
|
||||
export const formatAmount = (amount: BigNumberValue, decimals: number) => {
|
||||
const safeAmount = amount || '0';
|
||||
const bAmount = new BigNumber(safeAmount);
|
||||
@@ -451,13 +448,6 @@ export const getAllAccounts = (
|
||||
export const getAccountKey = (descriptor: string, symbol: string, deviceState: string) =>
|
||||
`${descriptor}-${symbol}-${deviceState}`;
|
||||
|
||||
export const countUniqueCoins = (accounts: Account[]) => {
|
||||
const coins = new Set();
|
||||
accounts.forEach(acc => coins.add(acc.symbol));
|
||||
|
||||
return coins.size;
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear invalid tokens and formats amounts
|
||||
*
|
||||
@@ -622,27 +612,6 @@ export const getAccountTokensFiatBalance = (
|
||||
}, new BigNumber(0))
|
||||
.toFixed();
|
||||
|
||||
export const getAssetTokensFiatBalance = (
|
||||
accounts: Account[],
|
||||
localCurrency: FiatCurrencyCode,
|
||||
rates?: RatesByKey,
|
||||
) => {
|
||||
const totalBalance = accounts
|
||||
.reduce((total, account) => {
|
||||
const tokensBalance = getAccountTokensFiatBalance(
|
||||
account,
|
||||
localCurrency,
|
||||
rates,
|
||||
account.tokens,
|
||||
);
|
||||
|
||||
return total.plus(tokensBalance ?? 0);
|
||||
}, new BigNumber(0))
|
||||
.toFixed();
|
||||
|
||||
return totalBalance;
|
||||
};
|
||||
|
||||
export const getStakingFiatBalance = (account: Account, rate: number | undefined) => {
|
||||
const balance = getAccountTotalStakingBalance(account) ?? '0';
|
||||
|
||||
|
||||
@@ -255,9 +255,6 @@ export const getInputState = (
|
||||
}
|
||||
};
|
||||
|
||||
export const getNonComposeErrorMessage = (error: FieldError | undefined) =>
|
||||
(error?.type !== 'compose' && error?.message) ?? null;
|
||||
|
||||
export const isLowAnonymityWarning = (error?: Merge<FieldError, FieldErrorsImpl<Output>>) =>
|
||||
error?.amount?.type === COMPOSE_ERROR_TYPES.ANONYMITY;
|
||||
|
||||
|
||||
@@ -721,14 +721,6 @@ export const enhanceTransaction = (
|
||||
hex: (origTx.blockHeight ?? 0) <= 0 && origTx.rbf ? origTx.hex : undefined, // store tx hex **only** for pending transactions (used by rbf)
|
||||
});
|
||||
|
||||
export const getOriginalTransaction = ({
|
||||
descriptor,
|
||||
deviceState,
|
||||
symbol,
|
||||
rbfParams,
|
||||
...tx
|
||||
}: WalletAccountTransaction): AccountTransaction => tx;
|
||||
|
||||
const groupTransactionIdsByAddress = (transactions: WalletAccountTransaction[]) => {
|
||||
const addresses: { [address: string]: string[] } = {};
|
||||
const addAddress = (txid: string, addrs: string[] | undefined) => {
|
||||
|
||||
Reference in New Issue
Block a user