diff --git a/suite-native/discovery/src/discoveryConfigSlice.ts b/suite-native/discovery/src/discoveryConfigSlice.ts index 55a8cb32ce8..e7ab871b47f 100644 --- a/suite-native/discovery/src/discoveryConfigSlice.ts +++ b/suite-native/discovery/src/discoveryConfigSlice.ts @@ -1,6 +1,6 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import { pipe } from '@mobily/ts-belt'; -import { memoizeWithArgs } from 'proxy-memoize'; +import { memoize, memoizeWithArgs } from 'proxy-memoize'; import { DeviceRootState, @@ -11,6 +11,8 @@ import { filterBlacklistedNetworks, filterTestnetNetworks, isDetoxTestBuild, + portfolioTrackerMainnets, + portfolioTrackerTestnets, sortNetworks, } from '@suite-native/config'; import { NetworkSymbol } from '@suite-common/wallet-config'; @@ -86,23 +88,29 @@ export const selectAreTestnetsEnabled = (state: DiscoveryConfigSliceRootState) = export const selectDiscoveryInfo = (state: DiscoveryConfigSliceRootState) => state.discoveryConfig.discoveryInfo; +export const selectFeatureFlagEnabledNetworkSymbols = memoize((state: FeatureFlagsRootState) => { + const isPolygonEnabled = selectIsFeatureFlagEnabled(state, FeatureFlag.IsPolygonEnabled); + const isBscEnabled = selectIsFeatureFlagEnabled(state, FeatureFlag.IsBscEnabled); + + const allowlist: NetworkSymbol[] = []; + + if (isPolygonEnabled) { + allowlist.push('pol'); + } + if (isBscEnabled) { + allowlist.push('bnb'); + } + + return allowlist; +}); + export const selectDiscoverySupportedNetworks = memoizeWithArgs( ( state: DeviceRootState & DiscoveryConfigSliceRootState & FeatureFlagsRootState, forcedAreTestnetsEnabled?: boolean, ) => { const areTestnetsEnabled = forcedAreTestnetsEnabled ?? selectAreTestnetsEnabled(state); - const isPolygonEnabled = selectIsFeatureFlagEnabled(state, FeatureFlag.IsPolygonEnabled); - const isBscEnabled = selectIsFeatureFlagEnabled(state, FeatureFlag.IsBscEnabled); - - const allowlist: NetworkSymbol[] = []; - - if (isPolygonEnabled) { - allowlist.push('pol'); - } - if (isBscEnabled) { - allowlist.push('bnb'); - } + const allowlist = selectFeatureFlagEnabledNetworkSymbols(state); return pipe( selectDeviceSupportedNetworks(state), @@ -128,6 +136,31 @@ export const selectDiscoveryNetworkSymbols = memoizeWithArgs( { size: 2 }, ); +export const selectPortfolioTrackerMainnetNetworkSymbols = memoize( + (state: FeatureFlagsRootState) => { + const allowlist = selectFeatureFlagEnabledNetworkSymbols(state); + + return [...portfolioTrackerMainnets, ...allowlist]; + }, +); + +export const selectPortfolioTrackerTestnetNetworkSymbols = memoize( + (state: FeatureFlagsRootState) => { + const isRegtestEnabled = selectIsFeatureFlagEnabled(state, FeatureFlag.IsRegtestEnabled); + + return isRegtestEnabled + ? [...portfolioTrackerTestnets, 'regtest' as NetworkSymbol] + : portfolioTrackerTestnets; + }, +); + +export const selectPortfolioTrackerNetworkSymbols = memoize((state: FeatureFlagsRootState) => { + const mainnets = selectPortfolioTrackerMainnetNetworkSymbols(state); + const testnets = selectPortfolioTrackerTestnetNetworkSymbols(state); + + return [...mainnets, ...testnets]; +}); + export const selectIsCoinEnablingInitFinished = ( state: DiscoveryConfigSliceRootState & FeatureFlagsRootState, ) => state.discoveryConfig.isCoinEnablingInitFinished; diff --git a/suite-native/intl/src/en.ts b/suite-native/intl/src/en.ts index 2ec3ecf8ee5..55d4e9d51ee 100644 --- a/suite-native/intl/src/en.ts +++ b/suite-native/intl/src/en.ts @@ -106,6 +106,10 @@ export const en = { }, subtitle: "Here's what you have in your account.", }, + coinList: { + mainnets: 'Select a coin to sync', + testnets: 'Testnet coins (have no value – for testing purposes only)', + }, xpubScanScreen: { alert: { address: { diff --git a/suite-native/module-accounts-import/package.json b/suite-native/module-accounts-import/package.json index dd7b9298bc2..0ea43f05990 100644 --- a/suite-native/module-accounts-import/package.json +++ b/suite-native/module-accounts-import/package.json @@ -33,6 +33,7 @@ "@suite-native/analytics": "workspace:*", "@suite-native/atoms": "workspace:*", "@suite-native/config": "workspace:*", + "@suite-native/discovery": "workspace:*", "@suite-native/feature-flags": "workspace:*", "@suite-native/formatters": "workspace:*", "@suite-native/forms": "workspace:*", diff --git a/suite-native/module-accounts-import/src/components/AccountImportSummary.tsx b/suite-native/module-accounts-import/src/components/AccountImportSummary.tsx index c6cf94dceb1..48f20e0c6b8 100644 --- a/suite-native/module-accounts-import/src/components/AccountImportSummary.tsx +++ b/suite-native/module-accounts-import/src/components/AccountImportSummary.tsx @@ -8,13 +8,12 @@ import { } from '@suite-common/wallet-core'; import { NetworkSymbol } from '@suite-common/wallet-config'; import { AccountInfo } from '@trezor/connect'; -import { portfolioTrackerSupportedNetworks } from '@suite-native/config'; import { Translation } from '@suite-native/intl'; import { FeatureFlag, useFeatureFlag } from '@suite-native/feature-flags'; +import { selectPortfolioTrackerNetworkSymbols } from '@suite-native/discovery'; import { AccountImportSummaryForm } from './AccountImportSummaryForm'; import { AccountAlreadyImported } from './AccountAlreadyImported'; - type AccountImportDetailProps = { networkSymbol: NetworkSymbol; accountInfo: AccountInfo; @@ -29,6 +28,7 @@ export const AccountImportSummary = ({ networkSymbol, accountInfo }: AccountImpo networkSymbol, ), ); + const portfolioTrackerSupportedNetworks = useSelector(selectPortfolioTrackerNetworkSymbols); const isAccountImportSupported = portfolioTrackerSupportedNetworks.some(symbol => symbol === networkSymbol) || diff --git a/suite-native/module-accounts-import/src/components/SelectableNetworkList.tsx b/suite-native/module-accounts-import/src/components/SelectableNetworkList.tsx index ba1794360aa..452aa4033c0 100644 --- a/suite-native/module-accounts-import/src/components/SelectableNetworkList.tsx +++ b/suite-native/module-accounts-import/src/components/SelectableNetworkList.tsx @@ -1,8 +1,14 @@ +import { useSelector } from 'react-redux'; +import { ReactNode } from 'react'; + import { SelectableNetworkItem } from '@suite-native/accounts'; import { HeaderedCard, VStack } from '@suite-native/atoms'; import { NetworkSymbol } from '@suite-common/wallet-config'; -import { portfolioTrackerMainnets, portfolioTrackerTestnets } from '@suite-native/config'; -import { FeatureFlag, useFeatureFlag } from '@suite-native/feature-flags'; +import { + selectPortfolioTrackerMainnetNetworkSymbols, + selectPortfolioTrackerTestnetNetworkSymbols, +} from '@suite-native/discovery'; +import { Translation } from '@suite-native/intl'; type SelectableAssetListProps = { onSelectItem: (networkSymbol: NetworkSymbol) => void; @@ -13,42 +19,37 @@ const NetworkItemSection = ({ networks, onSelectItem, }: { - title: string; + title: ReactNode; networks: NetworkSymbol[]; onSelectItem: SelectableAssetListProps['onSelectItem']; -}) => ( - - - {networks.map(symbol => ( - - ))} - - -); - -const TestnetNetworkItemSection = ({ onSelectItem }: SelectableAssetListProps) => { - const [isRegtestEnabled] = useFeatureFlag(FeatureFlag.IsRegtestEnabled); - const regtestAdjustedTestnets = isRegtestEnabled - ? [...portfolioTrackerTestnets, 'regtest' as NetworkSymbol] - : portfolioTrackerTestnets; - +}) => { return ( - + + + {networks.map(symbol => ( + + ))} + + ); }; -export const SelectableNetworkList = ({ onSelectItem }: SelectableAssetListProps) => ( - - +export const SelectableNetworkList = ({ onSelectItem }: SelectableAssetListProps) => { + const portfolioMainnets = useSelector(selectPortfolioTrackerMainnetNetworkSymbols); + const portfolioTestnets = useSelector(selectPortfolioTrackerTestnetNetworkSymbols); - - -); + return ( + + } + networks={portfolioMainnets} + onSelectItem={onSelectItem} + /> + } + networks={portfolioTestnets} + onSelectItem={onSelectItem} + /> + + ); +}; diff --git a/suite-native/module-accounts-import/tsconfig.json b/suite-native/module-accounts-import/tsconfig.json index 760423fdcb2..8de3d08dfe1 100644 --- a/suite-native/module-accounts-import/tsconfig.json +++ b/suite-native/module-accounts-import/tsconfig.json @@ -34,6 +34,7 @@ { "path": "../analytics" }, { "path": "../atoms" }, { "path": "../config" }, + { "path": "../discovery" }, { "path": "../feature-flags" }, { "path": "../formatters" }, { "path": "../forms" }, diff --git a/yarn.lock b/yarn.lock index 2cf68ef5b15..73061d2121d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10130,6 +10130,7 @@ __metadata: "@suite-native/analytics": "workspace:*" "@suite-native/atoms": "workspace:*" "@suite-native/config": "workspace:*" + "@suite-native/discovery": "workspace:*" "@suite-native/feature-flags": "workspace:*" "@suite-native/formatters": "workspace:*" "@suite-native/forms": "workspace:*"