mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-03 05:55:03 +01:00
refactor(suite): use new graph feature from networks instead of a constant on component level
This commit is contained in:
@@ -2,7 +2,7 @@ import { differenceInMonths, fromUnixTime, isWithinInterval } from 'date-fns';
|
||||
|
||||
import { getFiatRatesForTimestamps } from '@suite-common/fiat-services';
|
||||
import { resetTime } from '@suite-common/suite-utils';
|
||||
import { type NetworkSymbol, getNetwork, networks } from '@suite-common/wallet-config';
|
||||
import { type NetworkSymbol, getNetwork, getNetworkFeatures } from '@suite-common/wallet-config';
|
||||
import { Account } from '@suite-common/wallet-types';
|
||||
import { formatNetworkAmount } from '@suite-common/wallet-utils';
|
||||
import type { BaseCurrencyCode } from '@trezor/blockchain-link-types';
|
||||
@@ -66,7 +66,7 @@ export function getPristineAccounts(graph: AppState['wallet']['graph'], accounts
|
||||
* Does given network has backend type with support for retrieving transactions history, e.g. for showing graph?
|
||||
*/
|
||||
export function isNetworkWithGraphFeature(symbol: NetworkSymbol) {
|
||||
return networks[symbol].features.find(feature => feature === 'graph');
|
||||
return getNetworkFeatures(symbol).includes('graph');
|
||||
}
|
||||
|
||||
export const enhanceBlockchainAccountHistory = (
|
||||
|
||||
@@ -3,10 +3,14 @@ import { getNetworkFeatures } from '@suite-common/wallet-config';
|
||||
import { Account } from '@suite-common/wallet-types';
|
||||
import { Text } from '@trezor/components';
|
||||
import { hasBitcoinOnlyFirmware } from '@trezor/device-utils';
|
||||
import { capitalizeFirstLetter, union } from '@trezor/utils';
|
||||
|
||||
import { isNetworkWithGraphFeature } from 'src/utils/wallet/graph';
|
||||
|
||||
import { Translation } from '../../../components/suite';
|
||||
|
||||
const UNSUPPORTED_NETWORKS = ['ripple', 'solana', 'stellar'];
|
||||
const hasAnyAccountWithTokens = (accounts: Account[]): boolean =>
|
||||
accounts.some(account => getNetworkFeatures(account.symbol).includes('tokens'));
|
||||
|
||||
export const useUnsupportedNetworkMessage = ({
|
||||
showGraphControls,
|
||||
@@ -17,25 +21,16 @@ export const useUnsupportedNetworkMessage = ({
|
||||
device?: TrezorDevice;
|
||||
accounts: Account[];
|
||||
}) => {
|
||||
const hasAnyAccountWithTokens = (accounts: Account[]): boolean =>
|
||||
accounts.some(account => {
|
||||
const features = getNetworkFeatures(account.symbol);
|
||||
|
||||
return features?.includes('tokens') ?? false;
|
||||
});
|
||||
|
||||
const affectedAccounts =
|
||||
showGraphControls &&
|
||||
!hasBitcoinOnlyFirmware(device) &&
|
||||
accounts
|
||||
.filter(
|
||||
account => account.history && UNSUPPORTED_NETWORKS.includes(account.networkType),
|
||||
)
|
||||
.map(({ networkType }) => networkType);
|
||||
showGraphControls && !hasBitcoinOnlyFirmware(device)
|
||||
? accounts
|
||||
.filter(account => account.history && !isNetworkWithGraphFeature(account.symbol))
|
||||
.map(({ networkType }) => networkType)
|
||||
: [];
|
||||
|
||||
const affectedNetworks = [...new Set(affectedAccounts || [])];
|
||||
const affectedNetworks = union(affectedAccounts);
|
||||
const hasTokens = hasAnyAccountWithTokens(accounts);
|
||||
const showMissingDataTooltip = affectedNetworks.length > 0 || hasTokens;
|
||||
const showMissingDataTooltip = affectedNetworks.length > 0 || hasAnyAccountWithTokens(accounts);
|
||||
|
||||
return { affectedNetworks, showMissingDataTooltip, hasTokens };
|
||||
};
|
||||
@@ -45,8 +40,6 @@ type MessageProps = {
|
||||
hasTokens: boolean;
|
||||
};
|
||||
|
||||
const capitalizeFirstLetter = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
|
||||
|
||||
const Message = ({ affectedNetworks, hasTokens }: MessageProps) => {
|
||||
const hasNetworks = affectedNetworks.length > 0;
|
||||
const networksString = affectedNetworks
|
||||
|
||||
@@ -61,3 +61,4 @@ export * from './zip';
|
||||
export * from './removeTrailingSlashes';
|
||||
export * from './getIntegerInRangeFromString';
|
||||
export * from './safeBigIntStringify';
|
||||
export * from './union';
|
||||
|
||||
3
packages/utils/src/union.ts
Normal file
3
packages/utils/src/union.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function union<T extends string | number>(data: T[]) {
|
||||
return [...new Set(data)];
|
||||
}
|
||||
Reference in New Issue
Block a user