Skip to content

Commit

Permalink
feat(suite-native): allow enabled pol and bnb for portfolio tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
vytick committed Oct 19, 2024
1 parent 36ce065 commit bdac1d3
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 48 deletions.
57 changes: 45 additions & 12 deletions suite-native/discovery/src/discoveryConfigSlice.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -11,6 +11,8 @@ import {
filterBlacklistedNetworks,
filterTestnetNetworks,
isDetoxTestBuild,
portfolioTrackerMainnets,
portfolioTrackerTestnets,
sortNetworks,
} from '@suite-native/config';
import { NetworkSymbol } from '@suite-common/wallet-config';
Expand Down Expand Up @@ -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),
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions suite-native/intl/src/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions suite-native/module-accounts-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +28,7 @@ export const AccountImportSummary = ({ networkSymbol, accountInfo }: AccountImpo
networkSymbol,
),
);
const portfolioTrackerSupportedNetworks = useSelector(selectPortfolioTrackerNetworkSymbols);

const isAccountImportSupported =
portfolioTrackerSupportedNetworks.some(symbol => symbol === networkSymbol) ||
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,42 +19,37 @@ const NetworkItemSection = ({
networks,
onSelectItem,
}: {
title: string;
title: ReactNode;
networks: NetworkSymbol[];
onSelectItem: SelectableAssetListProps['onSelectItem'];
}) => (
<HeaderedCard title={title}>
<VStack spacing="sp24">
{networks.map(symbol => (
<SelectableNetworkItem key={symbol} symbol={symbol} onPress={onSelectItem} />
))}
</VStack>
</HeaderedCard>
);

const TestnetNetworkItemSection = ({ onSelectItem }: SelectableAssetListProps) => {
const [isRegtestEnabled] = useFeatureFlag(FeatureFlag.IsRegtestEnabled);
const regtestAdjustedTestnets = isRegtestEnabled
? [...portfolioTrackerTestnets, 'regtest' as NetworkSymbol]
: portfolioTrackerTestnets;

}) => {
return (
<NetworkItemSection
title="Testnet coins (have no value – for testing purposes only)"
networks={regtestAdjustedTestnets}
onSelectItem={onSelectItem}
/>
<HeaderedCard title={title}>
<VStack spacing="sp24">
{networks.map(symbol => (
<SelectableNetworkItem key={symbol} symbol={symbol} onPress={onSelectItem} />
))}
</VStack>
</HeaderedCard>
);
};

export const SelectableNetworkList = ({ onSelectItem }: SelectableAssetListProps) => (
<VStack spacing="sp24">
<NetworkItemSection
title="Select a coin to sync"
networks={portfolioTrackerMainnets}
onSelectItem={onSelectItem}
/>
export const SelectableNetworkList = ({ onSelectItem }: SelectableAssetListProps) => {
const portfolioMainnets = useSelector(selectPortfolioTrackerMainnetNetworkSymbols);
const portfolioTestnets = useSelector(selectPortfolioTrackerTestnetNetworkSymbols);

<TestnetNetworkItemSection onSelectItem={onSelectItem} />
</VStack>
);
return (
<VStack spacing="sp24">
<NetworkItemSection
title={<Translation id="moduleAccountImport.coinList.mainnets" />}
networks={portfolioMainnets}
onSelectItem={onSelectItem}
/>
<NetworkItemSection
title={<Translation id="moduleAccountImport.coinList.testnets" />}
networks={portfolioTestnets}
onSelectItem={onSelectItem}
/>
</VStack>
);
};
1 change: 1 addition & 0 deletions suite-native/module-accounts-import/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
{ "path": "../analytics" },
{ "path": "../atoms" },
{ "path": "../config" },
{ "path": "../discovery" },
{ "path": "../feature-flags" },
{ "path": "../formatters" },
{ "path": "../forms" },
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:*"
Expand Down

0 comments on commit bdac1d3

Please sign in to comment.