Skip to content

Commit

Permalink
chore(suite-native): refactor slightly native supported networks
Browse files Browse the repository at this point in the history
  • Loading branch information
vytick committed Feb 11, 2025
1 parent 246db18 commit f42129c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 38 deletions.
28 changes: 10 additions & 18 deletions suite-native/config/src/supportedNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ export const networkSymbolsWhitelistMap: Record<'mainnet' | 'testnet', readonly
testnet: ['test', 'regtest', 'tsep', 'thol', 'dsol', 'tada', 'txrp'],
};

export const discoverySupportedNetworks = [
...networkSymbolsWhitelistMap.mainnet,
...networkSymbolsWhitelistMap.testnet,
];

export const sortNetworks = (networksToSort: Network[]) =>
A.sort(networksToSort, (a, b) => {
const aOrder = networkSymbolCollection.indexOf(a.symbol);
Expand All @@ -62,20 +57,17 @@ export const filterTestnetNetworks = (
return networkSymbols.filter(networkSymbol => !isTestnet(networkSymbol));
};

export const portfolioTrackerMainnets = sortNetworks(
getMainnets().filter(network => networkSymbolsWhitelistMap.mainnet.includes(network.symbol)),
).map(network => network.symbol);

const getPortfolioTrackerTestnets = () =>
export const getNativeMainnetSymbols = () =>
sortNetworks(
getTestnets().filter(network =>
networkSymbolsWhitelistMap.testnet.includes(network.symbol),
),
).map(network => network.symbol);
getMainnets().filter(({ symbol }) => networkSymbolsWhitelistMap.mainnet.includes(symbol)),
).map(n => n.symbol);

export const portfolioTrackerTestnets = getPortfolioTrackerTestnets();
export const getNativeTestnetSymbols = () =>
sortNetworks(
getTestnets().filter(({ symbol }) => networkSymbolsWhitelistMap.testnet.includes(symbol)),
).map(n => n.symbol);

export const portfolioTrackerSupportedNetworks = [
...portfolioTrackerMainnets,
...portfolioTrackerTestnets,
export const discoverySupportedNetworks = [
...getNativeMainnetSymbols(),
...getNativeTestnetSymbols(),
];
16 changes: 8 additions & 8 deletions suite-native/discovery/src/discoveryConfigSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
} from '@suite-common/wallet-core';
import {
filterTestnetNetworks,
getNativeMainnetSymbols,
getNativeTestnetSymbols,
isDetoxTestBuild,
portfolioTrackerMainnets,
portfolioTrackerTestnets,
sortNetworks,
} from '@suite-native/config';
import {
Expand Down Expand Up @@ -132,19 +132,19 @@ export const selectDiscoveryNetworkSymbols = createMemoizedSelector(
supportedNetworks => returnStableArrayIfEmpty(supportedNetworks.map(n => n.symbol)),
);

export const selectPortfolioTrackerTestnetNetworkSymbols = createMemoizedSelector(
export const selectSupportedTestnetNetworkSymbols = createMemoizedSelector(
[state => selectIsFeatureFlagEnabled(state, FeatureFlag.IsRegtestEnabled)],
isRegtestEnabled =>
returnStableArrayIfEmpty(
isRegtestEnabled
? [...portfolioTrackerTestnets, 'regtest' as const]
: portfolioTrackerTestnets,
? [...getNativeTestnetSymbols(), 'regtest' as const]
: getNativeTestnetSymbols(),
),
);

export const selectPortfolioTrackerNetworkSymbols = createMemoizedSelector(
[selectPortfolioTrackerTestnetNetworkSymbols],
testnets => returnStableArrayIfEmpty([...portfolioTrackerMainnets, ...testnets]),
export const selectSupportedNetworkSymbols = createMemoizedSelector(
[selectSupportedTestnetNetworkSymbols],
testnets => returnStableArrayIfEmpty([...getNativeMainnetSymbols(), ...testnets]),
);

export const selectIsCoinEnablingInitFinished = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useSelector } from 'react-redux';
import { type NetworkSymbol } from '@suite-common/wallet-config';
import { SelectableNetworkItem } from '@suite-native/accounts';
import { HeaderedCard, VStack } from '@suite-native/atoms';
import { portfolioTrackerMainnets } from '@suite-native/config';
import { selectPortfolioTrackerTestnetNetworkSymbols } from '@suite-native/discovery';
import { getNativeMainnetSymbols } from '@suite-native/config';
import { selectSupportedTestnetNetworkSymbols } from '@suite-native/discovery';
import { Translation } from '@suite-native/intl';

type SelectableAssetListProps = {
Expand All @@ -31,20 +31,20 @@ const NetworkItemSection = ({
);

export const SelectableNetworkList = ({ onSelectItem }: SelectableAssetListProps) => {
const portfolioTestnetsNetworkSymbols = useSelector(
selectPortfolioTrackerTestnetNetworkSymbols,
);
const testnetsSymbols = useSelector(selectSupportedTestnetNetworkSymbols);

const mainnetSymbols = getNativeMainnetSymbols();

return (
<VStack spacing="sp24">
<NetworkItemSection
title={<Translation id="moduleAccountImport.coinList.mainnets" />}
symbols={portfolioTrackerMainnets}
symbols={mainnetSymbols}
onSelectItem={onSelectItem}
/>
<NetworkItemSection
title={<Translation id="moduleAccountImport.coinList.testnets" />}
symbols={portfolioTestnetsNetworkSymbols}
symbols={testnetsSymbols}
onSelectItem={onSelectItem}
/>
</VStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
selectDeviceAccountByDescriptorAndNetworkSymbol,
} from '@suite-common/wallet-core';
import { ErrorMessage } from '@suite-native/atoms';
import { selectPortfolioTrackerNetworkSymbols } from '@suite-native/discovery';
import { selectSupportedNetworkSymbols } from '@suite-native/discovery';
import { FeatureFlag, useFeatureFlag } from '@suite-native/feature-flags';
import { Translation } from '@suite-native/intl';
import {
Expand Down Expand Up @@ -39,12 +39,10 @@ export const AccountImportSummaryScreen = ({
networkSymbol,
),
);
const portfolioTrackerSupportedNetworks = useSelector(selectPortfolioTrackerNetworkSymbols);
const supportedNetworks = useSelector(selectSupportedNetworkSymbols);

const isAccountImportSupported =
portfolioTrackerSupportedNetworks.some(
supportedSymbol => supportedSymbol === networkSymbol,
) ||
supportedNetworks.some(supportedSymbol => supportedSymbol === networkSymbol) ||
(networkSymbol === 'regtest' && isRegtestEnabled);

if (!isAccountImportSupported) {
Expand Down

0 comments on commit f42129c

Please sign in to comment.