Skip to content

Commit

Permalink
chore: [IOBP-659] Add remote feature flag to the new payment section (#…
Browse files Browse the repository at this point in the history
…5798)

## ⚠️ This PR depends on
pagopa/io-services-metadata#782 ⚠️

## Short description
This PR adds the remote feature flag to the new payment section. It will
be visible only when the remote or local FF is enabled. (The local
feature flag is considered only if the remote one is disabled)

## List of changes proposed in this pull request
- Added a new `isNewPaymentSectionEnabledSelector` selector that takes
into account remote configuration
- Replaced the previous `isNewWalletSectionEnabledSelector` with this
new one but the previous one is still available in order to show the
local feature flag.

## How to test
- Checkout this PR: pagopa/io-dev-api-server#383
- Try to change the `enabled` attribute from the `newPaymentSection`
into the `backend.ts` file on the dev-server
  • Loading branch information
Hantex9 authored May 29, 2024
1 parent 15086be commit a3854c1
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.61.0-rc.0",
"io_backend_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.32.1-RELEASE/api_backend.yaml",
"io_public_api": "https://raw.githubusercontent.com/pagopa/io-backend/v13.32.1-RELEASE/api_public.yaml",
"io_content_specs": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.31/definitions.yml",
"io_content_specs": "https://raw.githubusercontent.com/pagopa/io-services-metadata/1.0.32/definitions.yml",
"io_cgn_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.32.1-RELEASE/api_cgn.yaml",
"io_cgn_merchants_specs": "https://raw.githubusercontent.com/pagopa/io-backend/v13.29.2-RELEASE/api_cgn_operator_search.yaml",
"api_fci": "https://raw.githubusercontent.com/pagopa/io-backend/v13.32.1-RELEASE/api_io_sign.yaml",
Expand Down
4 changes: 2 additions & 2 deletions ts/features/payments/checkout/hooks/usePagoPaPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
PaymentInitStateParams,
initPaymentStateAction
} from "../store/actions/orchestration";
import { isNewWalletSectionEnabledSelector } from "../../../../store/reducers/persistedPreferences";
import { isNewPaymentSectionEnabledSelector } from "../../../../store/reducers/backendStatus";

type PagoPaPaymentParams = Omit<PaymentInitStateParams, "startRoute">;

Expand Down Expand Up @@ -53,7 +53,7 @@ const usePagoPaPayment = (): UsePagoPaPayment => {

// Checks if the new wallet section is enabled
const isNewWalletSectionEnabled = useIOSelector(
isNewWalletSectionEnabledSelector
isNewPaymentSectionEnabledSelector
);

/**
Expand Down
6 changes: 3 additions & 3 deletions ts/navigation/AppStackNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import { useIODispatch, useIOSelector } from "../store/hooks";
import { trackScreen } from "../store/middlewares/navigation";
import {
isCGNEnabledSelector,
isFIMSEnabledSelector
isFIMSEnabledSelector,
isNewPaymentSectionEnabledSelector
} from "../store/reducers/backendStatus";
import { isNewWalletSectionEnabledSelector } from "../store/reducers/persistedPreferences";
import { StartupStatusEnum, isStartupLoaded } from "../store/reducers/startup";
import {
IONavigationDarkTheme,
Expand Down Expand Up @@ -87,7 +87,7 @@ const InnerNavigationContainer = (props: { children: React.ReactElement }) => {
const cgnEnabled = useIOSelector(isCGNEnabledSelector);
const isFimsEnabled = useIOSelector(isFIMSEnabledSelector) && fimsEnabled;
const isNewWalletSectionEnabled = useIOSelector(
isNewWalletSectionEnabledSelector
isNewPaymentSectionEnabledSelector
);

// Dark/Light Mode
Expand Down
10 changes: 4 additions & 6 deletions ts/navigation/AuthenticatedStackNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ import {
isCGNEnabledSelector,
isFciEnabledSelector,
isFIMSEnabledSelector,
isIdPayEnabledSelector
isIdPayEnabledSelector,
isNewPaymentSectionEnabledSelector
} from "../store/reducers/backendStatus";
import {
isItWalletTestEnabledSelector,
isNewWalletSectionEnabledSelector
} from "../store/reducers/persistedPreferences";
import { isItWalletTestEnabledSelector } from "../store/reducers/persistedPreferences";
import { isGestureEnabled } from "../utils/navigation";
import { ItwStackNavigator } from "../features/itwallet/navigation/ItwStackNavigator";
import { ITW_ROUTES } from "../features/itwallet/navigation/routes";
Expand All @@ -102,7 +100,7 @@ const AuthenticatedStackNavigator = () => {
const isFciEnabled = useIOSelector(isFciEnabledSelector);
const isIdPayEnabled = useIOSelector(isIdPayEnabledSelector);
const isNewWalletSectionEnabled = useIOSelector(
isNewWalletSectionEnabledSelector
isNewPaymentSectionEnabledSelector
);
const isItWalletEnabled = useIOSelector(isItWalletTestEnabledSelector);

Expand Down
6 changes: 3 additions & 3 deletions ts/navigation/TabNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import WalletHomeScreen from "../screens/wallet/WalletHomeScreen";
import { useIOSelector } from "../store/hooks";
import {
isDesignSystemEnabledSelector,
isNewHomeSectionEnabledSelector,
isNewWalletSectionEnabledSelector
isNewHomeSectionEnabledSelector
} from "../store/reducers/persistedPreferences";
import { isNewPaymentSectionEnabledSelector } from "../store/reducers/backendStatus";
import { StartupStatusEnum, isStartupLoaded } from "../store/reducers/startup";
import variables from "../theme/variables";
import { MESSAGES_ROUTES } from "../features/messages/navigation/routes";
Expand Down Expand Up @@ -61,7 +61,7 @@ export const MainTabNavigator = () => {
const startupLoaded = useIOSelector(isStartupLoaded);
const isDesignSystemEnabled = useIOSelector(isDesignSystemEnabledSelector);
const isNewWalletSectionEnabled = useIOSelector(
isNewWalletSectionEnabledSelector
isNewPaymentSectionEnabledSelector
);
const isNewHomeSectionEnabled = useIOSelector(
isNewHomeSectionEnabledSelector
Expand Down
4 changes: 2 additions & 2 deletions ts/navigation/components/HeaderFirstLevelHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import I18n from "../../i18n";
import { navigateToServicePreferenceScreen } from "../../store/actions/navigation";
import { searchMessagesEnabled } from "../../store/actions/search";
import { useIODispatch, useIOSelector } from "../../store/hooks";
import { isNewWalletSectionEnabledSelector } from "../../store/reducers/persistedPreferences";
import { SERVICES_ROUTES } from "../../features/services/common/navigation/routes";
import { MainTabParamsList } from "../params/MainTabParamsList";
import ROUTES from "../routes";
import { isNewPaymentSectionEnabledSelector } from "../../store/reducers/backendStatus";

type HeaderFirstLevelProps = ComponentProps<typeof HeaderFirstLevel>;
type TabRoutes = keyof MainTabParamsList;
Expand Down Expand Up @@ -72,7 +72,7 @@ export const HeaderFirstLevelHandler = ({ currentRouteName }: Props) => {
const dispatch = useIODispatch();

const isNewWalletSectionEnabled = useIOSelector(
isNewWalletSectionEnabledSelector
isNewPaymentSectionEnabledSelector
);

const requestParams = useMemo(
Expand Down
14 changes: 14 additions & 0 deletions ts/store/reducers/__mock__/backendStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ export const baseRawBackendStatus: BackendStatus = {
ios: "0.0.0.0"
}
},
newPaymentSection: {
enabled: false,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
},
lollipop: {
enabled: false,
min_app_version: {
Expand Down Expand Up @@ -373,6 +380,13 @@ export const baseBackendConfig: Config = {
ios: "0.0.0.0"
}
},
newPaymentSection: {
enabled: false,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
},
lollipop: {
enabled: false,
min_app_version: {
Expand Down
21 changes: 20 additions & 1 deletion ts/store/reducers/backendStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import { isStringNullyOrEmpty } from "../../utils/strings";
import { backendStatusLoadSuccess } from "../actions/backendStatus";
import { Action } from "../actions/types";

import { isIdPayTestEnabledSelector } from "./persistedPreferences";
import {
isIdPayTestEnabledSelector,
isNewWalletSectionEnabledSelector
} from "./persistedPreferences";
import { GlobalState } from "./types";

export type SectionStatusKey = keyof Sections;
Expand Down Expand Up @@ -407,6 +410,22 @@ export const isIdPayEnabledSelector = createSelector(
)
);

/**
* Return the remote config about the new payment section enabled/disabled
* If the local feature flag is enabled, the remote config is ignored
*/
export const isNewPaymentSectionEnabledSelector = createSelector(
backendStatusSelector,
isNewWalletSectionEnabledSelector,
(backendStatus, isNeWalletSectionEnabled): boolean =>
isNeWalletSectionEnabled ||
pipe(
backendStatus,
O.map(bs => bs.config.newPaymentSection?.enabled),
O.getOrElse(() => false)
)
);

// systems could be consider dead when we have no updates for at least DEAD_COUNTER_THRESHOLD times
export const DEAD_COUNTER_THRESHOLD = 2;

Expand Down

0 comments on commit a3854c1

Please sign in to comment.