Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(suite-native): refactor slightly native supported networks #16938

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading