Skip to content

Commit

Permalink
feat(suite-native): isRegtestEnabled feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
PeKne committed Apr 25, 2024
1 parent dc6d738 commit c376a54
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 15 deletions.
5 changes: 4 additions & 1 deletion suite-native/feature-flags/src/featureFlagsSlice.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';

import { isAndroid } from '@trezor/env-utils';
import { isDebugEnv, isDevelopOrDebugEnv } from '@suite-native/config';
import { isDebugEnv, isDetoxTestBuild, isDevelopOrDebugEnv } from '@suite-native/config';

export const FeatureFlag = {
IsDeviceConnectEnabled: 'isDeviceConnectEnabled',
IsPassphraseEnabled: 'isPassphraseEnabled',
IsViewOnlyEnabled: 'isViewOnlyEnabled',
IsSendEnabled: 'isSendEnabled',
IsRegtestEnabled: 'isRegtestEnabled',
} as const;
export type FeatureFlag = (typeof FeatureFlag)[keyof typeof FeatureFlag];

Expand All @@ -22,13 +23,15 @@ export const featureFlagsInitialState: FeatureFlagsState = {
[FeatureFlag.IsPassphraseEnabled]: isDebugEnv(),
[FeatureFlag.IsViewOnlyEnabled]: isDebugEnv(),
[FeatureFlag.IsSendEnabled]: isAndroid() && isDevelopOrDebugEnv(),
[FeatureFlag.IsRegtestEnabled]: isDebugEnv() || isDetoxTestBuild(),
};

export const featureFlagsPersistedKeys: Array<keyof FeatureFlagsState> = [
FeatureFlag.IsDeviceConnectEnabled,
FeatureFlag.IsPassphraseEnabled,
FeatureFlag.IsViewOnlyEnabled,
FeatureFlag.IsSendEnabled,
FeatureFlag.IsRegtestEnabled,
];

export const featureFlagsSlice = createSlice({
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 @@ -32,6 +32,7 @@
"@suite-native/config": "workspace:*",
"@suite-native/device-manager": "workspace:*",
"@suite-native/ethereum-tokens": "workspace:*",
"@suite-native/feature-flags": "workspace:*",
"@suite-native/formatters": "workspace:*",
"@suite-native/forms": "workspace:*",
"@suite-native/intl": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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 { AccountImportSummaryForm } from './AccountImportSummaryForm';
import { AccountAlreadyImported } from './AccountAlreadyImported';
Expand All @@ -20,6 +21,7 @@ type AccountImportDetailProps = {
};

export const AccountImportSummary = ({ networkSymbol, accountInfo }: AccountImportDetailProps) => {
const [isRegtestEnabled] = useFeatureFlag(FeatureFlag.IsRegtestEnabled);
const account = useSelector((state: AccountsRootState & DeviceRootState) =>
selectDeviceAccountByDescriptorAndNetworkSymbol(
state,
Expand All @@ -28,9 +30,9 @@ export const AccountImportSummary = ({ networkSymbol, accountInfo }: AccountImpo
),
);

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

if (!isAccountImportSupported) {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { SelectableNetworkItem } from '@suite-native/accounts';
import { HeaderedCard, VStack } from '@suite-native/atoms';
import { Network, NetworkSymbol } from '@suite-common/wallet-config';
import { NetworkSymbol } from '@suite-common/wallet-config';
import { portfolioTrackerMainnets, portfolioTrackerTestnets } from '@suite-native/config';
import { FeatureFlag, useFeatureFlag } from '@suite-native/feature-flags';

type SelectableAssetListProps = {
onSelectItem: (networkSymbol: NetworkSymbol) => void;
Expand All @@ -13,18 +14,33 @@ const NetworkItemSection = ({
onSelectItem,
}: {
title: string;
networks: readonly Network[];
networks: NetworkSymbol[];
onSelectItem: SelectableAssetListProps['onSelectItem'];
}) => (
<HeaderedCard title={title}>
<VStack spacing="large">
{networks.map(({ symbol }) => (
{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}
/>
);
};

export const SelectableNetworkList = ({ onSelectItem }: SelectableAssetListProps) => (
<VStack spacing="large">
<NetworkItemSection
Expand All @@ -33,10 +49,6 @@ export const SelectableNetworkList = ({ onSelectItem }: SelectableAssetListProps
onSelectItem={onSelectItem}
/>

<NetworkItemSection
title="Testnet coins (have no value – for testing purposes only)"
networks={portfolioTrackerTestnets}
onSelectItem={onSelectItem}
/>
<TestnetNetworkItemSection 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 @@ -31,6 +31,7 @@
{ "path": "../config" },
{ "path": "../device-manager" },
{ "path": "../ethereum-tokens" },
{ "path": "../feature-flags" },
{ "path": "../formatters" },
{ "path": "../forms" },
{ "path": "../intl" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const featureFlagsTitleMap = {
[FeatureFlagEnum.IsPassphraseEnabled]: 'Passphrase',
[FeatureFlagEnum.IsViewOnlyEnabled]: 'View-only',
[FeatureFlagEnum.IsSendEnabled]: 'Send',
[FeatureFlagEnum.IsRegtestEnabled]: 'Regtest',
} as const satisfies Record<FeatureFlagEnum, string>;

const FeatureFlag = ({ featureFlag }: { featureFlag: FeatureFlagEnum }) => {
Expand Down
6 changes: 3 additions & 3 deletions suite-native/module-dev-utils/src/screens/DevUtilsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Alert } from 'react-native';

import * as Sentry from '@sentry/react-native';

import { getEnv, isDebugEnv, isDevelopOrDebugEnv, isProduction } from '@suite-native/config';
import { getEnv, isDebugEnv, isDevelopOrDebugEnv } from '@suite-native/config';
import { Button, Card, ListItem, VStack } from '@suite-native/atoms';
import {
Screen,
Expand Down Expand Up @@ -38,11 +38,11 @@ export const DevUtilsScreen = ({
See Component Demo
</Button>
)}
{!isProduction() && <RenderingUtils />}
<FeatureFlags />
{isDevelopOrDebugEnv() && (
<>
<RenderingUtils />
<DevicePassphraseSwitch />
<FeatureFlags />
<DiscoveryCoinsFilter />
</>
)}
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9181,6 +9181,7 @@ __metadata:
"@suite-native/config": "workspace:*"
"@suite-native/device-manager": "workspace:*"
"@suite-native/ethereum-tokens": "workspace:*"
"@suite-native/feature-flags": "workspace:*"
"@suite-native/formatters": "workspace:*"
"@suite-native/forms": "workspace:*"
"@suite-native/intl": "workspace:*"
Expand Down

0 comments on commit c376a54

Please sign in to comment.