Skip to content

Commit

Permalink
fixup! 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 26, 2024
1 parent 1b1854c commit d7ea06e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
29 changes: 21 additions & 8 deletions suite-native/accounts/src/components/AddAccountsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,37 @@ import {
StackNavigationProps,
} from '@suite-native/navigation';
import { IconButton } from '@suite-native/atoms';
import { selectIsPortfolioTrackerDevice } from '@suite-common/wallet-core';
import { FeatureFlag, useFeatureFlag } from '@suite-native/feature-flags';
import {
selectAreAllDevicesDisconnectedOrAccountless,
selectDeviceDiscovery,
selectIsPortfolioTrackerDevice,
} from '@suite-common/wallet-core';

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

export const AddAccountButton = () => {
const isSelectedDevicePortfolioTracker = useSelector(selectIsPortfolioTrackerDevice);
const [isAddCoinAccountEnabled] = useFeatureFlag(FeatureFlag.IsAddCoinAccountEnabled);
const [isDeviceConnectEnabled] = useFeatureFlag(FeatureFlag.IsDeviceConnectEnabled);
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 = () => {
if (isDeviceConnectEnabled && isAddCoinAccountEnabled) {
if (isAddCoinAccountEnabled) {
navigation.navigate(RootStackRoutes.AddCoinAccountStack, {
screen: AddCoinAccountStackRoutes.AddCoinAccount,
params: {
Expand All @@ -37,7 +50,7 @@ export const AddAccountButton = () => {
}
};

return (
return shouldShowAddAccountButton ? (
<IconButton
iconName="plus"
onPress={
Expand All @@ -46,5 +59,5 @@ export const AddAccountButton = () => {
colorScheme="tertiaryElevation0"
size="medium"
/>
);
) : null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +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,
selectIsPortfolioTrackerDevice,
} from '@suite-common/wallet-core';
import { FeatureFlag, useFeatureFlag } from '@suite-native/feature-flags';

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

const discovery = useSelector(selectDeviceDiscovery);
const areAllDevicesDisconnectedOrAccountless = useSelector(
selectAreAllDevicesDisconnectedOrAccountless,
);
const isSelectedDevicePortfolioTracker = useSelector(selectIsPortfolioTrackerDevice);
const [isAddCoinAccountEnabled] = useFeatureFlag(FeatureFlag.IsAddCoinAccountEnabled);
const [isDeviceConnectEnabled] = useFeatureFlag(FeatureFlag.IsDeviceConnectEnabled);
const [isSearchActive, setIsSearchActive] = useState(false);

const handleHideFilter = () => {
Expand Down Expand Up @@ -77,13 +63,6 @@ export const SearchableAccountsListScreenHeader = ({
};
};

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

return (
<Box style={applyStyle(searchFormContainerStyle)}>
{isSearchActive ? (
Expand All @@ -98,7 +77,7 @@ export const SearchableAccountsListScreenHeader = ({
>
<ScreenSubHeader
content={title}
rightIcon={shouldShowAddAccountButton && <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 };
};

0 comments on commit d7ea06e

Please sign in to comment.