From c376a54f3952a9f8e2d7b930fb45a0c5e1b1f60b Mon Sep 17 00:00:00 2001 From: Petr Knetl Date: Wed, 24 Apr 2024 13:14:37 +0200 Subject: [PATCH] feat(suite-native): isRegtestEnabled feature flag --- .../feature-flags/src/featureFlagsSlice.ts | 5 +++- .../module-accounts-import/package.json | 1 + .../src/components/AccountImportSummary.tsx | 8 ++++-- .../src/components/SelectableNetworkList.tsx | 28 +++++++++++++------ .../module-accounts-import/tsconfig.json | 1 + .../src/components/FeatureFlags.tsx | 1 + .../src/screens/DevUtilsScreen.tsx | 6 ++-- yarn.lock | 1 + 8 files changed, 36 insertions(+), 15 deletions(-) diff --git a/suite-native/feature-flags/src/featureFlagsSlice.ts b/suite-native/feature-flags/src/featureFlagsSlice.ts index 4882b6f66a0..631f1908a62 100644 --- a/suite-native/feature-flags/src/featureFlagsSlice.ts +++ b/suite-native/feature-flags/src/featureFlagsSlice.ts @@ -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]; @@ -22,6 +23,7 @@ export const featureFlagsInitialState: FeatureFlagsState = { [FeatureFlag.IsPassphraseEnabled]: isDebugEnv(), [FeatureFlag.IsViewOnlyEnabled]: isDebugEnv(), [FeatureFlag.IsSendEnabled]: isAndroid() && isDevelopOrDebugEnv(), + [FeatureFlag.IsRegtestEnabled]: isDebugEnv() || isDetoxTestBuild(), }; export const featureFlagsPersistedKeys: Array = [ @@ -29,6 +31,7 @@ export const featureFlagsPersistedKeys: Array = [ FeatureFlag.IsPassphraseEnabled, FeatureFlag.IsViewOnlyEnabled, FeatureFlag.IsSendEnabled, + FeatureFlag.IsRegtestEnabled, ]; export const featureFlagsSlice = createSlice({ diff --git a/suite-native/module-accounts-import/package.json b/suite-native/module-accounts-import/package.json index 9bc96fdb16c..a1d93114854 100644 --- a/suite-native/module-accounts-import/package.json +++ b/suite-native/module-accounts-import/package.json @@ -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:*", diff --git a/suite-native/module-accounts-import/src/components/AccountImportSummary.tsx b/suite-native/module-accounts-import/src/components/AccountImportSummary.tsx index 05f2c35662f..61ed6a6800a 100644 --- a/suite-native/module-accounts-import/src/components/AccountImportSummary.tsx +++ b/suite-native/module-accounts-import/src/components/AccountImportSummary.tsx @@ -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'; @@ -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, @@ -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 ( diff --git a/suite-native/module-accounts-import/src/components/SelectableNetworkList.tsx b/suite-native/module-accounts-import/src/components/SelectableNetworkList.tsx index ab36918ce79..6472e696695 100644 --- a/suite-native/module-accounts-import/src/components/SelectableNetworkList.tsx +++ b/suite-native/module-accounts-import/src/components/SelectableNetworkList.tsx @@ -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; @@ -13,18 +14,33 @@ const NetworkItemSection = ({ onSelectItem, }: { title: string; - networks: readonly Network[]; + networks: NetworkSymbol[]; onSelectItem: SelectableAssetListProps['onSelectItem']; }) => ( - {networks.map(({ symbol }) => ( + {networks.map(symbol => ( ))} ); +const TestnetNetworkItemSection = ({ onSelectItem }: SelectableAssetListProps) => { + const [isRegtestEnabled] = useFeatureFlag(FeatureFlag.IsRegtestEnabled); + const regtestAdjustedTestnets = isRegtestEnabled + ? [...portfolioTrackerTestnets, 'regtest' as NetworkSymbol] + : portfolioTrackerTestnets; + + return ( + + ); +}; + export const SelectableNetworkList = ({ onSelectItem }: SelectableAssetListProps) => ( - + ); diff --git a/suite-native/module-accounts-import/tsconfig.json b/suite-native/module-accounts-import/tsconfig.json index 40b3373111a..251b312dc4a 100644 --- a/suite-native/module-accounts-import/tsconfig.json +++ b/suite-native/module-accounts-import/tsconfig.json @@ -31,6 +31,7 @@ { "path": "../config" }, { "path": "../device-manager" }, { "path": "../ethereum-tokens" }, + { "path": "../feature-flags" }, { "path": "../formatters" }, { "path": "../forms" }, { "path": "../intl" }, diff --git a/suite-native/module-dev-utils/src/components/FeatureFlags.tsx b/suite-native/module-dev-utils/src/components/FeatureFlags.tsx index f16bacbc67f..880e4b2011d 100644 --- a/suite-native/module-dev-utils/src/components/FeatureFlags.tsx +++ b/suite-native/module-dev-utils/src/components/FeatureFlags.tsx @@ -6,6 +6,7 @@ const featureFlagsTitleMap = { [FeatureFlagEnum.IsPassphraseEnabled]: 'Passphrase', [FeatureFlagEnum.IsViewOnlyEnabled]: 'View-only', [FeatureFlagEnum.IsSendEnabled]: 'Send', + [FeatureFlagEnum.IsRegtestEnabled]: 'Regtest', } as const satisfies Record; const FeatureFlag = ({ featureFlag }: { featureFlag: FeatureFlagEnum }) => { diff --git a/suite-native/module-dev-utils/src/screens/DevUtilsScreen.tsx b/suite-native/module-dev-utils/src/screens/DevUtilsScreen.tsx index 7a36a3c932f..c3a1e47258c 100644 --- a/suite-native/module-dev-utils/src/screens/DevUtilsScreen.tsx +++ b/suite-native/module-dev-utils/src/screens/DevUtilsScreen.tsx @@ -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, @@ -38,11 +38,11 @@ export const DevUtilsScreen = ({ See Component Demo )} - {!isProduction() && } + {isDevelopOrDebugEnv() && ( <> + - )} diff --git a/yarn.lock b/yarn.lock index dd0d33c6956..9ddce36b775 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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:*"