Skip to content

Commit

Permalink
feat(suite-native): Add coin behind feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
vytick committed Feb 27, 2024
1 parent e43684a commit 96631c5
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 24 deletions.
1 change: 1 addition & 0 deletions suite-native/accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@suite-common/wallet-utils": "workspace:*",
"@suite-native/atoms": "workspace:*",
"@suite-native/ethereum-tokens": "workspace:*",
"@suite-native/feature-flags": "workspace:*",
"@suite-native/fiat-rates": "workspace:*",
"@suite-native/formatters": "workspace:*",
"@suite-native/forms": "workspace:*",
Expand Down
41 changes: 30 additions & 11 deletions suite-native/accounts/src/components/AddAccountsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,47 @@ import {
StackNavigationProps,
} from '@suite-native/navigation';
import { IconButton } from '@suite-native/atoms';
import { selectIsPortfolioTrackerDevice } from '@suite-common/wallet-core';
import {
selectAreAllDevicesDisconnectedOrAccountless,
selectDeviceDiscovery,
selectIsPortfolioTrackerDevice,
} from '@suite-common/wallet-core';

import { useIsAddCoinAccountEnabled } from '../useIsAddCoinAccountEnabled';

export const AddAccountButton = () => {
const isSelectedDevicePortfolioTracker = useSelector(selectIsPortfolioTrackerDevice);
const navigation =
useNavigation<StackNavigationProps<RootStackParamList, RootStackRoutes.AccountsImport>>();

const isSelectedDevicePortfolioTracker = useSelector(selectIsPortfolioTrackerDevice);
const discovery = useSelector(selectDeviceDiscovery);
const areAllDevicesDisconnectedOrAccountless = useSelector(
selectAreAllDevicesDisconnectedOrAccountless,
);
const { isAddCoinAccountEnabled } = useIsAddCoinAccountEnabled();

const shouldShowAddAccountButton =
isSelectedDevicePortfolioTracker ||
(isAddCoinAccountEnabled && !areAllDevicesDisconnectedOrAccountless && !discovery);

const navigateToImportScreen = () => {
navigation.navigate(RootStackRoutes.AccountsImport, {
screen: AccountsImportStackRoutes.SelectNetwork,
});
};

const navigateToAddCoinAccount = () =>
navigation.navigate(RootStackRoutes.AddCoinAccountStack, {
screen: AddCoinAccountStackRoutes.AddCoinAccount,
params: {
flowType: 'accounts',
},
});
const navigateToAddCoinAccount = () => {
if (isAddCoinAccountEnabled) {
navigation.navigate(RootStackRoutes.AddCoinAccountStack, {
screen: AddCoinAccountStackRoutes.AddCoinAccount,
params: {
flowType: 'accounts',
},
});
}
};

return (
return shouldShowAddAccountButton ? (
<IconButton
iconName="plus"
onPress={
Expand All @@ -40,5 +59,5 @@ export const AddAccountButton = () => {
colorScheme="tertiaryElevation0"
size="medium"
/>
);
) : null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import Animated, {
withDelay,
withTiming,
} from 'react-native-reanimated';
import { useSelector } from 'react-redux';

import { ScreenSubHeader } from '@suite-native/navigation';
import { Box, IconButton } from '@suite-native/atoms';
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';
import {
selectAreAllDevicesDisconnectedOrAccountless,
selectDeviceDiscovery,
} from '@suite-common/wallet-core';

import { AccountsSearchForm, SEARCH_INPUT_ANIMATION_DURATION } from './AccountsSearchForm';
import { AddAccountButton } from './AddAccountsButton';
Expand All @@ -39,10 +34,6 @@ export const SearchableAccountsListScreenHeader = ({
const isFirstRender = useSharedValue(true);
const { applyStyle } = useNativeStyles();

const discovery = useSelector(selectDeviceDiscovery);
const areAllDevicesDisconnectedOrAccountless = useSelector(
selectAreAllDevicesDisconnectedOrAccountless,
);
const [isSearchActive, setIsSearchActive] = useState(false);

const handleHideFilter = () => {
Expand Down Expand Up @@ -86,10 +77,7 @@ export const SearchableAccountsListScreenHeader = ({
>
<ScreenSubHeader
content={title}
rightIcon={
!areAllDevicesDisconnectedOrAccountless &&
!discovery && <AddAccountButton />
}
rightIcon={<AddAccountButton />}
leftIcon={
<IconButton
iconName="search"
Expand Down
1 change: 1 addition & 0 deletions suite-native/accounts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './useAccountLabelForm';
export * from './selectors';
export * from './transactionCacheMiddleware';
export * from './useTransactionCache';
export * from './useIsAddCoinAccountEnabled';
8 changes: 8 additions & 0 deletions suite-native/accounts/src/useIsAddCoinAccountEnabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { FeatureFlag, useFeatureFlag } from '@suite-native/feature-flags';

export const useIsAddCoinAccountEnabled = () => {
const [isAddCoinAccountEnabled] = useFeatureFlag(FeatureFlag.IsAddCoinAccountEnabled);
const [isDeviceConnectEnabled] = useFeatureFlag(FeatureFlag.IsDeviceConnectEnabled);

return { isAddCoinAccountEnabled: isDeviceConnectEnabled && isAddCoinAccountEnabled };
};
1 change: 1 addition & 0 deletions suite-native/accounts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
{ "path": "../atoms" },
{ "path": "../ethereum-tokens" },
{ "path": "../feature-flags" },
{ "path": "../fiat-rates" },
{ "path": "../formatters" },
{ "path": "../forms" },
Expand Down
3 changes: 3 additions & 0 deletions suite-native/feature-flags/src/featureFlagsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
export const FeatureFlag = {
IsDeviceConnectEnabled: 'isDeviceConnectEnabled',
IsPassphraseEnabled: 'isPassphraseEnabled',
IsAddCoinAccountEnabled: 'isAddCoinAccountEnabled',
} as const;
export type FeatureFlag = (typeof FeatureFlag)[keyof typeof FeatureFlag];

Expand All @@ -17,11 +18,13 @@ export type FeatureFlagsRootState = {
export const featureFlagsInitialState: FeatureFlagsState = {
[FeatureFlag.IsDeviceConnectEnabled]: Platform.OS === 'android',
[FeatureFlag.IsPassphraseEnabled]: false,
[FeatureFlag.IsAddCoinAccountEnabled]: false,
};

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

export const featureFlagsSlice = createSlice({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FeatureFlag as FeatureFlagEnum, useFeatureFlag } from '@suite-native/fe
const featureFlagsTitleMap = {
[FeatureFlagEnum.IsDeviceConnectEnabled]: 'Connect device',
[FeatureFlagEnum.IsPassphraseEnabled]: 'Passphrase',
[FeatureFlagEnum.IsAddCoinAccountEnabled]: 'Add account',
} as const satisfies Record<FeatureFlagEnum, string>;

const FeatureFlag = ({ featureFlag }: { featureFlag: FeatureFlagEnum }) => {
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7765,6 +7765,7 @@ __metadata:
"@suite-common/wallet-utils": "workspace:*"
"@suite-native/atoms": "workspace:*"
"@suite-native/ethereum-tokens": "workspace:*"
"@suite-native/feature-flags": "workspace:*"
"@suite-native/fiat-rates": "workspace:*"
"@suite-native/formatters": "workspace:*"
"@suite-native/forms": "workspace:*"
Expand Down

0 comments on commit 96631c5

Please sign in to comment.