diff --git a/packages/product-components/src/components/CoinLogo/coinLogos.stories.tsx b/packages/product-components/src/components/CoinLogo/coinLogos.stories.tsx index 03056d600afd..2ff0b7a584f4 100644 --- a/packages/product-components/src/components/CoinLogo/coinLogos.stories.tsx +++ b/packages/product-components/src/components/CoinLogo/coinLogos.stories.tsx @@ -2,10 +2,9 @@ import styled from 'styled-components'; import { Meta, StoryObj } from '@storybook/react'; import { StoryColumn } from '@trezor/components'; -import { NetworkSymbol } from '@suite-common/wallet-config'; import { CoinLogo } from '../../index'; -import { COINS } from './coins'; +import { COINS, isCoinSymbol } from './coins'; const CoinName = styled.div` margin-bottom: 0.5rem; @@ -36,14 +35,16 @@ export const All: StoryObj = { render: () => ( - {Object.keys(COINS).map(symbol => ( - - {symbol} - + {Object.keys(COINS).map(coinSymbol => ( + + {coinSymbol} + {isCoinSymbol(coinSymbol) && ( + + )} ))} diff --git a/packages/product-components/src/components/CoinLogo/coins.ts b/packages/product-components/src/components/CoinLogo/coins.ts index 567ff33c0132..aa0fc7458748 100644 --- a/packages/product-components/src/components/CoinLogo/coins.ts +++ b/packages/product-components/src/components/CoinLogo/coins.ts @@ -35,3 +35,8 @@ export const COINS: Record = { xtz: require('../../images/coins/xtz.svg'), zec: require('../../images/coins/zec.svg'), }; + +export const isCoinSymbol = ( + coinSymbol: string, +): coinSymbol is NetworkSymbol | LegacyNetworkSymbol => + Object.prototype.hasOwnProperty.call(COINS, coinSymbol); diff --git a/packages/product-components/src/components/SelectAssetModal/AssetItem.tsx b/packages/product-components/src/components/SelectAssetModal/AssetItem.tsx index 86e31936882a..b05596072c52 100644 --- a/packages/product-components/src/components/SelectAssetModal/AssetItem.tsx +++ b/packages/product-components/src/components/SelectAssetModal/AssetItem.tsx @@ -2,12 +2,11 @@ import styled from 'styled-components'; import { spacings, spacingsPx } from '@trezor/theme'; import { AssetLogo, Badge, Column, Row, Text } from '@trezor/components'; -import { NetworkSymbol } from '@suite-common/wallet-config'; import { getContractAddressForNetworkSymbol } from '@suite-common/wallet-utils'; import { CoinLogo } from '../CoinLogo/CoinLogo'; import { AssetOptionBaseProps } from './SelectAssetModal'; -import { COINS } from '../CoinLogo/coins'; +import { isCoinSymbol } from '../CoinLogo/coins'; const ClickableContainer = styled.div` cursor: pointer; @@ -42,8 +41,8 @@ export const AssetItem = ({ contractAddress, handleClick, }: AssetItemProps) => { - // TODO: use isCoinSymbol - prepared in chore(suite): update network symbol naming 7 - const symbolHelper = symbol in COINS ? (symbol as NetworkSymbol) : undefined; + const getCoinLogo = () => + isCoinSymbol(symbol) ? : null; return ( ) : ( - symbolHelper && + getCoinLogo() )} diff --git a/suite-common/graph/src/graphDataFetching.ts b/suite-common/graph/src/graphDataFetching.ts index 81a2f11779e9..363a98d42b0a 100644 --- a/suite-common/graph/src/graphDataFetching.ts +++ b/suite-common/graph/src/graphDataFetching.ts @@ -456,9 +456,9 @@ export const getMultipleAccountBalanceHistoryWithFiat = async ({ }); const coins = Array.from(coinsSet).map(coin => { - const [coinSymbol, contractId] = coin.split('-'); + const [symbol, contractId] = coin.split('-') as [NetworkSymbol, TokenAddress | undefined]; - return { coin: coinSymbol as NetworkSymbol, contractId: contractId as TokenAddress }; + return { coin: symbol, contractId }; }); const pairs = await Promise.all( diff --git a/suite-common/token-definitions/src/__fixtures__/utils.ts b/suite-common/token-definitions/src/__fixtures__/utils.ts index f458fcd2297c..02f5f13feea4 100644 --- a/suite-common/token-definitions/src/__fixtures__/utils.ts +++ b/suite-common/token-definitions/src/__fixtures__/utils.ts @@ -1,40 +1,38 @@ -import { NetworkSymbol } from '@suite-common/wallet-config'; - import { DefinitionType } from '../tokenDefinitionsTypes'; export const isTokenDefinitionKnownFixtures = [ { testName: 'Token definition known, case-insensitive network', tokenDefinitions: ['0xa', '0xb'], - networkSymbol: 'eth' as NetworkSymbol, + networkSymbol: 'eth' as const, contractAddress: '0xA', result: true, }, { testName: 'Token definition unknown, case-sensitive network', tokenDefinitions: ['0xa', '0xb'], - networkSymbol: 'sol' as NetworkSymbol, + networkSymbol: 'sol' as const, contractAddress: '0xA', result: false, }, { testName: 'Token definition known, case-sensitive network', tokenDefinitions: ['0xA', '0xb'], - networkSymbol: 'sol' as NetworkSymbol, + networkSymbol: 'sol' as const, contractAddress: '0xA', result: true, }, { testName: 'Token definition not known', tokenDefinitions: ['0xa', '0xb'], - networkSymbol: 'eth' as NetworkSymbol, + networkSymbol: 'eth' as const, contractAddress: '0xC', result: false, }, { testName: 'Token definitions are undefined', tokenDefinitions: undefined, - networkSymbol: 'eth' as NetworkSymbol, + networkSymbol: 'eth' as const, contractAddress: '0xA', result: false, }, @@ -43,20 +41,20 @@ export const isTokenDefinitionKnownFixtures = [ export const getSupportedDefinitionTypesFixtures = [ { testName: 'Supports both token and NFT definitions', - networkSymbol: 'eth' as NetworkSymbol, + networkSymbol: 'eth' as const, features: ['coin-definitions', 'nft-definitions'], result: [DefinitionType.COIN, DefinitionType.NFT], }, // Temporarily skipped while token definitions are disabled for Cardano. // { // testName: 'Supports only token definitions', - // networkSymbol: 'ada' as NetworkSymbol, + // networkSymbol: 'ada' as const, // features: ['coin-definitions'], // result: [DefinitionType.COIN], // }, { testName: 'Supports neither token nor NFT definitions', - networkSymbol: 'ltc' as NetworkSymbol, + networkSymbol: 'ltc' as const, features: [], result: [], }, diff --git a/suite-common/wallet-core/src/accounts/accountsReducer.ts b/suite-common/wallet-core/src/accounts/accountsReducer.ts index 97c61d827b79..77e74cf596e5 100644 --- a/suite-common/wallet-core/src/accounts/accountsReducer.ts +++ b/suite-common/wallet-core/src/accounts/accountsReducer.ts @@ -439,15 +439,13 @@ export const selectDeviceAccountKeyByDescriptorAndNetworkSymbol = createMemoized account => account?.key ?? null, ); -export const selectAccountsSymbols = createMemoizedSelector( - [selectAccounts], - accounts => - pipe( - accounts, - A.map(a => a.symbol), - A.uniq, - returnStableArrayIfEmpty, - ) as NetworkSymbol[], +export const selectAccountsSymbols = createMemoizedSelector([selectAccounts], accounts => + pipe( + accounts, + A.map(a => a.symbol), + A.uniq, + returnStableArrayIfEmpty, + ), ); export const selectIsDeviceAccountless = createMemoizedSelector( diff --git a/suite-common/wallet-core/src/device/deviceReducer.ts b/suite-common/wallet-core/src/device/deviceReducer.ts index 9b9d9df15234..43a81d7fceec 100644 --- a/suite-common/wallet-core/src/device/deviceReducer.ts +++ b/suite-common/wallet-core/src/device/deviceReducer.ts @@ -10,7 +10,7 @@ import { hasBitcoinOnlyFirmware, isBitcoinOnlyDevice, } from '@trezor/device-utils'; -import { NetworkSymbol, networks } from '@suite-common/wallet-config'; +import { networkSymbolCollection } from '@suite-common/wallet-config'; import { createReducerWithExtraDeps, createWeakMapSelector, @@ -789,24 +789,22 @@ export const selectDeviceStatus = createMemoizedSelector( export const selectDeviceSupportedNetworks = createMemoizedSelector([selectDevice], device => { const firmwareVersion = getFirmwareVersion(device); - const result = Object.entries(networks) - .filter(([symbol]) => { - const unavailableCapability = device?.unavailableCapabilities?.[symbol]; - // if device does not have fw, do not show coins which are not supported by device in any case - if (!firmwareVersion && unavailableCapability === 'no-support') { - return false; - } - // if device has fw, do not show coins which are not supported by current fw - if ( - firmwareVersion && - ['no-support', 'no-capability'].includes(unavailableCapability || '') - ) { - return false; - } + const result = networkSymbolCollection.filter(symbol => { + const unavailableCapability = device?.unavailableCapabilities?.[symbol]; + // if device does not have fw, do not show coins which are not supported by device in any case + if (!firmwareVersion && unavailableCapability === 'no-support') { + return false; + } + // if device has fw, do not show coins which are not supported by current fw + if ( + firmwareVersion && + ['no-support', 'no-capability'].includes(unavailableCapability || '') + ) { + return false; + } - return true; - }) - .map(([symbol]) => symbol as NetworkSymbol); + return true; + }); return returnStableArrayIfEmpty(result); }); diff --git a/suite-common/wallet-core/src/fiat-rates/fiatRatesThunks.ts b/suite-common/wallet-core/src/fiat-rates/fiatRatesThunks.ts index 7b656b99f0b1..67a53df88f82 100644 --- a/suite-common/wallet-core/src/fiat-rates/fiatRatesThunks.ts +++ b/suite-common/wallet-core/src/fiat-rates/fiatRatesThunks.ts @@ -15,7 +15,7 @@ import { groupTokensTransactionsByContractAddress, isTestnet, } from '@suite-common/wallet-utils'; -import { getNetworkFeatures, NetworkSymbol } from '@suite-common/wallet-config'; +import { getNetworkFeatures } from '@suite-common/wallet-config'; import { selectIsSpecificCoinDefinitionKnown } from '@suite-common/token-definitions'; import { TimerId } from '@trezor/type-utils'; @@ -61,7 +61,7 @@ export const updateTxsFiatRatesThunk = createThunk( if (hasCoinDefinitions) { const isTokenKnown = selectIsSpecificCoinDefinitionKnown( getState(), - account.symbol as NetworkSymbol, + account.symbol, token as TokenAddress, ); @@ -75,7 +75,7 @@ export const updateTxsFiatRatesThunk = createThunk( ) as Timestamp[]; await fetchTransactionsRates( { - symbol: account.symbol as NetworkSymbol, + symbol: account.symbol, tokenAddress: token as TokenAddress, }, tokenTimestamps, diff --git a/suite-common/wallet-utils/src/accountUtils.ts b/suite-common/wallet-utils/src/accountUtils.ts index ceecac8a67b8..836191018761 100644 --- a/suite-common/wallet-utils/src/accountUtils.ts +++ b/suite-common/wallet-utils/src/accountUtils.ts @@ -22,6 +22,7 @@ import { type Bip43PathTemplate, getNetwork, type NetworkSymbolExtended, + networkSymbolCollection, } from '@suite-common/wallet-config'; import { Account, @@ -439,13 +440,11 @@ export const formatTokenAmount = (tokenTransfer: TokenTransfer) => { * - primary: by network `symbol` * - secondary: by `accountType` */ -export const sortByCoin = (accounts: Account[]) => { - const orderedNetworkSymbols = Object.keys(networks) as NetworkSymbol[]; - - return accounts.sort((a, b) => { +export const sortByCoin = (accounts: Account[]) => + accounts.sort((a, b) => { // primary sorting: by order of network keys - const aSymbolIndex = orderedNetworkSymbols.indexOf(a.symbol); - const bSymbolIndex = orderedNetworkSymbols.indexOf(b.symbol); + const aSymbolIndex = networkSymbolCollection.indexOf(a.symbol); + const bSymbolIndex = networkSymbolCollection.indexOf(b.symbol); if (aSymbolIndex !== bSymbolIndex) return aSymbolIndex - bSymbolIndex; // when it is sorted by network, sort by order of accountType keys within the same network @@ -459,7 +458,6 @@ export const sortByCoin = (accounts: Account[]) => { // if both are same, keep the original order in `accounts` return a.index - b.index; }); -}; export const findAccountsByNetwork = (symbol: NetworkSymbol, accounts: Account[]) => accounts.filter(a => a.symbol === symbol); @@ -655,7 +653,7 @@ export const getAccountTokensFiatBalance = ( // sum fiat value of all tokens tokens?.forEach(t => { const tokenFiatRateKey = getFiatRateKey( - account.symbol as NetworkSymbol, + account.symbol, localCurrency as FiatCurrencyCode, t.contract as TokenAddress, ); @@ -712,7 +710,7 @@ export const getAccountFiatBalance = ({ shouldIncludeTokens?: boolean; shouldIncludeStaking?: boolean; }) => { - const coinFiatRateKey = getFiatRateKey(account.symbol as NetworkSymbol, localCurrency); + const coinFiatRateKey = getFiatRateKey(account.symbol, localCurrency); const coinFiatRate = rates?.[coinFiatRateKey]; if (!coinFiatRate?.rate) return null; diff --git a/suite-native/accounts/src/utils.ts b/suite-native/accounts/src/utils.ts index 4ef996f8549b..5e8e6b30fb2a 100644 --- a/suite-native/accounts/src/utils.ts +++ b/suite-native/accounts/src/utils.ts @@ -1,9 +1,14 @@ import { A, D, G } from '@mobily/ts-belt'; -import { AccountType, getNetwork, networks } from '@suite-common/wallet-config'; +import { + AccountType, + getNetwork, + networks, + networkSymbolCollection, +} from '@suite-common/wallet-config'; import { formattedAccountTypeMap } from '@suite-common/wallet-core'; import { Account } from '@suite-common/wallet-types'; -import { orderedNetworkSymbols, orderedAccountTypes } from '@suite-native/config'; +import { orderedAccountTypes } from '@suite-native/config'; const accountTypeToSectionHeader: Readonly>> = { normal: 'default', @@ -79,8 +84,8 @@ export const groupAccountsByNetworkAccountType = A.groupBy((account: Account) => export const sortAccountsByNetworksAndAccountTypes = (accounts: readonly Account[]) => { return A.sort(accounts, (a, b) => { - const aOrder = orderedNetworkSymbols.indexOf(a.symbol) ?? Number.MAX_SAFE_INTEGER; - const bOrder = orderedNetworkSymbols.indexOf(b.symbol) ?? Number.MAX_SAFE_INTEGER; + const aOrder = networkSymbolCollection.indexOf(a.symbol) ?? Number.MAX_SAFE_INTEGER; + const bOrder = networkSymbolCollection.indexOf(b.symbol) ?? Number.MAX_SAFE_INTEGER; if (aOrder === bOrder) { const aAccountTypeOrder = diff --git a/suite-native/assets/package.json b/suite-native/assets/package.json index f5f1f0afeeec..0e9591708db0 100644 --- a/suite-native/assets/package.json +++ b/suite-native/assets/package.json @@ -21,7 +21,6 @@ "@suite-common/wallet-utils": "workspace:*", "@suite-native/accounts": "workspace:*", "@suite-native/atoms": "workspace:*", - "@suite-native/config": "workspace:*", "@suite-native/formatters": "workspace:*", "@suite-native/icons": "workspace:*", "@suite-native/intl": "workspace:*", diff --git a/suite-native/assets/src/assetsSelectors.ts b/suite-native/assets/src/assetsSelectors.ts index 9932b520b6ca..a104bf13b86f 100644 --- a/suite-native/assets/src/assetsSelectors.ts +++ b/suite-native/assets/src/assetsSelectors.ts @@ -7,7 +7,7 @@ import { selectTokenDefinitions, TokenDefinitionsRootState, } from '@suite-common/token-definitions'; -import { NetworkSymbol } from '@suite-common/wallet-config'; +import { NetworkSymbol, networkSymbolCollection } from '@suite-common/wallet-config'; import { AccountsRootState, DeviceRootState, @@ -20,7 +20,6 @@ import { import { getAccountFiatBalance } from '@suite-common/wallet-utils'; import { getAccountListSections } from '@suite-native/accounts'; import { sortAccountsByNetworksAndAccountTypes } from '@suite-native/accounts/src/utils'; -import { orderedNetworkSymbols } from '@suite-native/config'; import { selectFiatCurrencyCode, SettingsSliceRootState } from '@suite-native/settings'; import { getAccountCryptoBalanceWithStaking, NativeStakingRootState } from '@suite-native/staking'; @@ -65,8 +64,8 @@ export const selectDeviceNetworksWithAssets = createMemoizedSelector( A.map(account => account.symbol), A.uniq, A.sort((a, b) => { - const aOrder = orderedNetworkSymbols.indexOf(a) ?? Number.MAX_SAFE_INTEGER; - const bOrder = orderedNetworkSymbols.indexOf(b) ?? Number.MAX_SAFE_INTEGER; + const aOrder = networkSymbolCollection.indexOf(a) ?? Number.MAX_SAFE_INTEGER; + const bOrder = networkSymbolCollection.indexOf(b) ?? Number.MAX_SAFE_INTEGER; return aOrder - bOrder; }), diff --git a/suite-native/assets/tsconfig.json b/suite-native/assets/tsconfig.json index 859b6f035e2f..42704aac9aa9 100644 --- a/suite-native/assets/tsconfig.json +++ b/suite-native/assets/tsconfig.json @@ -23,7 +23,6 @@ }, { "path": "../accounts" }, { "path": "../atoms" }, - { "path": "../config" }, { "path": "../formatters" }, { "path": "../icons" }, { "path": "../intl" }, diff --git a/suite-native/atoms/src/Badge.tsx b/suite-native/atoms/src/Badge.tsx index 8e3ff7eb0f8f..3f2dd414b4a3 100644 --- a/suite-native/atoms/src/Badge.tsx +++ b/suite-native/atoms/src/Badge.tsx @@ -5,7 +5,7 @@ import { G } from '@mobily/ts-belt'; import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; import { Icon, IconSize, IconName, icons, CryptoIcon } from '@suite-native/icons'; import { Color } from '@trezor/theme'; -import { NetworkSymbol } from '@suite-common/wallet-config'; +import { isNetworkSymbol, NetworkSymbol } from '@suite-common/wallet-config'; import { Text } from './Text'; import { HStack } from './Stack'; @@ -14,11 +14,12 @@ import { BoxProps } from './Box'; export type BadgeVariant = 'neutral' | 'green' | 'greenSubtle' | 'yellow' | 'red' | 'bold'; export type BadgeSize = 'small' | 'medium'; +type IconType = IconName | NetworkSymbol; type BadgeProps = { label: ReactNode; variant?: BadgeVariant; size?: BadgeSize; - icon?: IconName | NetworkSymbol; + icon?: IconType; iconSize?: IconSize; elevation?: SurfaceElevation; isDisabled?: boolean; @@ -136,14 +137,16 @@ export const Badge = ({ const backgroundColor = elevation === '0' ? backgroundColorElevation0 : backgroundColorElevation1; - const badgeIcon = - icon && icon in icons ? ( + const getCryptoIcon = (iconInput: IconType) => + isNetworkSymbol(iconInput) ? ( + + ) : null; + + const getBadgeIcon = (iconInput: IconType) => + iconInput in icons ? ( ) : ( - + getCryptoIcon(iconInput) ); return ( @@ -159,7 +162,7 @@ export const Badge = ({ ]} spacing={utils.spacings.sp4} > - {icon && badgeIcon} + {icon && getBadgeIcon(icon)} {label} diff --git a/suite-native/blockchain/src/blockchainMiddleware.ts b/suite-native/blockchain/src/blockchainMiddleware.ts index 4d3ea39553ed..b48a50e48ee2 100644 --- a/suite-native/blockchain/src/blockchainMiddleware.ts +++ b/suite-native/blockchain/src/blockchainMiddleware.ts @@ -5,7 +5,7 @@ import { selectAllPendingTransactions, } from '@suite-common/wallet-core'; import { BlockchainEvent, BLOCKCHAIN as TREZOR_CONNECT_BLOCKCHAIN_ACTIONS } from '@trezor/connect'; -import { NetworkSymbol } from '@suite-common/wallet-config'; +import { isNetworkSymbol } from '@suite-common/wallet-config'; import { onBlockchainConnectThunk, @@ -32,9 +32,9 @@ export const blockchainMiddleware = createMiddleware( case TREZOR_CONNECT_BLOCKCHAIN_ACTIONS.BLOCK: { const networksWithPendingTransactions = selectNetworksWithPendingTransactions(getState()); - const symbol = action.payload.coin.shortcut.toLowerCase() as NetworkSymbol; + const symbol = action.payload.coin.shortcut.toLowerCase(); - if (networksWithPendingTransactions.includes(symbol)) { + if (isNetworkSymbol(symbol) && networksWithPendingTransactions.includes(symbol)) { dispatch(syncAccountsWithBlockchainThunk({ symbol })); } diff --git a/suite-native/config/src/supportedNetworks.ts b/suite-native/config/src/supportedNetworks.ts index 89e77a9f24e1..0d8c3325a3d4 100644 --- a/suite-native/config/src/supportedNetworks.ts +++ b/suite-native/config/src/supportedNetworks.ts @@ -2,12 +2,12 @@ import { A } from '@mobily/ts-belt'; import { isTestnet } from '@suite-common/wallet-utils'; import { - networks, - AccountType, - Network, - NetworkSymbol, + type AccountType, + type Network, + type NetworkSymbol, getMainnets, getTestnets, + networkSymbolCollection, } from '@suite-common/wallet-config'; export const orderedAccountTypes: AccountType[] = [ @@ -21,7 +21,7 @@ export const orderedAccountTypes: AccountType[] = [ const discoveryBlacklist: NetworkSymbol[] = ['sol', 'dsol', 'op', 'base']; // All supported coins for device discovery -export const networkSymbolsWhitelistMap = { +export const networkSymbolsWhitelistMap: Record<'mainnet' | 'testnet', readonly NetworkSymbol[]> = { mainnet: [ 'btc', 'eth', @@ -39,24 +39,22 @@ export const networkSymbolsWhitelistMap = { 'nmc', 'vtc', 'zec', - ] as NetworkSymbol[], - testnet: ['test', 'regtest', 'tsep', 'thol', 'tada', 'txrp'] as NetworkSymbol[], -} as const satisfies Record; + ], + testnet: ['test', 'regtest', 'tsep', 'thol', 'tada', 'txrp'], +}; // Blacklisting coins that are allowed inside `networkSymbolsWhitelistMap` so that we don't have to configs and just filter these out -const portfolioTrackerBlacklist = ['btg', 'dash', 'dgb', 'nmc', 'vtc']; +const portfolioTrackerBlacklist: readonly NetworkSymbol[] = ['btg', 'dash', 'dgb', 'nmc', 'vtc']; export const discoverySupportedNetworks = [ ...networkSymbolsWhitelistMap.mainnet, ...networkSymbolsWhitelistMap.testnet, ]; -export const orderedNetworkSymbols = Object.keys(networks) as NetworkSymbol[]; - export const sortNetworks = (networksToSort: Network[]) => A.sort(networksToSort, (a, b) => { - const aOrder = orderedNetworkSymbols.indexOf(a.symbol); - const bOrder = orderedNetworkSymbols.indexOf(b.symbol); + const aOrder = networkSymbolCollection.indexOf(a.symbol); + const bOrder = networkSymbolCollection.indexOf(b.symbol); return aOrder - bOrder; }); diff --git a/suite-native/discovery/src/discoveryConfigSlice.ts b/suite-native/discovery/src/discoveryConfigSlice.ts index cdbd9cc220fa..bd98e45807e5 100644 --- a/suite-native/discovery/src/discoveryConfigSlice.ts +++ b/suite-native/discovery/src/discoveryConfigSlice.ts @@ -157,7 +157,7 @@ export const selectPortfolioTrackerTestnetNetworkSymbols = createMemoizedSelecto isRegtestEnabled => returnStableArrayIfEmpty( isRegtestEnabled - ? [...portfolioTrackerTestnets, 'regtest' as NetworkSymbol] + ? [...portfolioTrackerTestnets, 'regtest' as const] : portfolioTrackerTestnets, ), ); diff --git a/suite-native/discovery/src/discoverySelectors.ts b/suite-native/discovery/src/discoverySelectors.ts index 856ec87067fa..ec7c69dc75a9 100644 --- a/suite-native/discovery/src/discoverySelectors.ts +++ b/suite-native/discovery/src/discoverySelectors.ts @@ -39,17 +39,17 @@ import { getNetworksWithUnfinishedDiscovery } from './utils'; export const selectValidTokensByDeviceStateAndNetworkSymbol = ( state: TokenDefinitionsRootState & DeviceRootState & AccountsRootState, deviceState: StaticSessionId, - networkSymbol: NetworkSymbol, + symbol: NetworkSymbol, ) => { const accountsByDeviceStateAndNetworkSymbol = selectAccountsByNetworkAndDeviceState( state, deviceState, - networkSymbol, + symbol, ); return pipe( accountsByDeviceStateAndNetworkSymbol, - A.filter(account => account.symbol === networkSymbol), + A.filter(account => account.symbol === symbol), A.map(account => account.tokens), A.flat, @@ -61,7 +61,7 @@ export const selectValidTokensByDeviceStateAndNetworkSymbol = ( const tokenContract = token.contract as TokenAddress; const tokenSymbol = token.symbol as TokenSymbol; - if (selectIsSpecificCoinDefinitionKnown(state, networkSymbol, tokenContract)) { + if (selectIsSpecificCoinDefinitionKnown(state, symbol, tokenContract)) { return O.Some(`${tokenContract}:${tokenSymbol}`); } }), @@ -79,13 +79,13 @@ export const selectDiscoveryAccountsAnalytics = ( pipe( selectDeviceAccounts(state), A.groupBy(account => account.symbol), - D.mapWithKey((networkSymbol, accounts) => { + D.mapWithKey((symbol, accounts) => { const numberOfAccounts = accounts?.length ?? 0; const validTokens = selectValidTokensByDeviceStateAndNetworkSymbol( state, deviceState, - networkSymbol as NetworkSymbol, + symbol, ); if (A.isNotEmpty(validTokens)) { diff --git a/suite-native/discovery/src/discoveryThunks.ts b/suite-native/discovery/src/discoveryThunks.ts index 321249e7a452..1579a5967387 100644 --- a/suite-native/discovery/src/discoveryThunks.ts +++ b/suite-native/discovery/src/discoveryThunks.ts @@ -37,6 +37,7 @@ import { getNetworkType, NetworkAccount, normalizeNetworkAccounts, + isNetworkSymbol, } from '@suite-common/wallet-config'; import { DiscoveryStatus } from '@suite-common/wallet-constants'; import { requestDeviceAccess } from '@suite-native/device-mutex'; @@ -148,15 +149,17 @@ const finishNetworkTypeDiscoveryThunk = createThunk( // Keboola analytics data backend is unable to parse nested objects, so each network has to be reported separately. Object.entries(discoveryAccountsAnalytics).forEach( - ([networkSymbol, networkAnalyticsPayload]) => { - analytics.report({ - type: EventType.CoinDiscovery, - payload: { - discoveryId, - symbol: networkSymbol as NetworkSymbol, - ...networkAnalyticsPayload, - }, - }); + ([symbol, networkAnalyticsPayload]) => { + if (isNetworkSymbol(symbol)) { + analytics.report({ + type: EventType.CoinDiscovery, + payload: { + discoveryId, + symbol, + ...networkAnalyticsPayload, + }, + }); + } }, ); diff --git a/suite-native/module-add-accounts/src/hooks/useAddCoinAccount.ts b/suite-native/module-add-accounts/src/hooks/useAddCoinAccount.ts index 34aaf24d5f65..0c3a6f7f1b7e 100644 --- a/suite-native/module-add-accounts/src/hooks/useAddCoinAccount.ts +++ b/suite-native/module-add-accounts/src/hooks/useAddCoinAccount.ts @@ -10,6 +10,7 @@ import { NetworkSymbol, networks, NORMAL_ACCOUNT_TYPE, + networkSymbolCollection, } from '@suite-common/wallet-config'; import { Account } from '@suite-common/wallet-types'; import { @@ -102,13 +103,13 @@ export const useAddCoinAccount = () => { // first account type for every network is set to normal and represents default type const availableTypes: Map = new Map(); - Object.keys(networks).forEach(symbol => { + networkSymbolCollection.forEach(symbol => { // for Cardano and Ethereum only allow latest account type and coinjoin and ledger are not supported const types = Object.keys(networks[symbol].accountTypes).filter( t => !['coinjoin', 'imported', 'ledger'].includes(t), ) as AccountType[]; - availableTypes.set(symbol as NetworkSymbol, [ + availableTypes.set(symbol, [ NORMAL_ACCOUNT_TYPE, // For Cardano and EVMs allow only normal account type ...(['ada', 'eth', 'pol', 'bnb', 'sol', 'op', 'base'].includes(symbol) diff --git a/yarn.lock b/yarn.lock index fe1374c7e929..bc444166e52c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9975,7 +9975,6 @@ __metadata: "@suite-common/wallet-utils": "workspace:*" "@suite-native/accounts": "workspace:*" "@suite-native/atoms": "workspace:*" - "@suite-native/config": "workspace:*" "@suite-native/formatters": "workspace:*" "@suite-native/icons": "workspace:*" "@suite-native/intl": "workspace:*"