Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(IT Wallet): [SIW-2016] Remove remote feature flag from linking options #6706

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
33 changes: 29 additions & 4 deletions ts/features/itwallet/navigation/ItwStackNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
TransitionPresets
} from "@react-navigation/stack";
import { Platform } from "react-native";
import { ComponentType } from "react";
import { isGestureEnabled } from "../../../utils/navigation";
import { ItwAlreadyActiveScreen } from "../discovery/screens/ItwAlreadyActiveScreen";
import { ItwDiscoveryInfoScreen } from "../discovery/screens/ItwDiscoveryInfoScreen";
Expand Down Expand Up @@ -41,6 +42,9 @@ import { ItwPresentationCredentialFiscalCodeModal } from "../presentation/detail
import { ItwPresentationEidVerificationExpiredScreen } from "../presentation/details/screens/ItwPresentationEidVerificationExpiredScreen";
import { ItwCredentialTrustmarkScreen } from "../trustmark/screens/ItwCredentialTrustmarkScreen";
import { ItwOfflineWalletScreen } from "../wallet/screens/ItwOfflineWalletScreen";
import { isItwEnabledSelector } from "../common/store/selectors/remoteConfig";
import { ItwGenericErrorContent } from "../common/components/ItwGenericErrorContent";
import { useIOSelector } from "../../../store/hooks";
import { ItwParamsList } from "./ItwParamsList";
import { ITW_ROUTES } from "./routes";

Expand Down Expand Up @@ -87,15 +91,16 @@ const InnerNavigator = () => {
{/* DISCOVERY */}
<Stack.Screen
name={ITW_ROUTES.DISCOVERY.INFO}
component={ItwDiscoveryInfoScreen}
component={withItwEnabled(ItwDiscoveryInfoScreen)}
options={hiddenHeader}
/>
<Stack.Screen
name={ITW_ROUTES.DISCOVERY.IPZS_PRIVACY}
component={ItwIpzsPrivacyScreen}
/>
<Stack.Screen
name={ITW_ROUTES.DISCOVERY.ALREADY_ACTIVE_SCREEN}
component={ItwAlreadyActiveScreen}
component={withItwEnabled(ItwAlreadyActiveScreen)}
options={hiddenHeader}
/>
{/* IDENTIFICATION */}
Expand Down Expand Up @@ -192,13 +197,14 @@ const InnerNavigator = () => {
/>
<Stack.Screen
name={ITW_ROUTES.ISSUANCE.CREDENTIAL_ASYNC_FLOW_CONTINUATION}
component={ItwIssuanceCredentialAsyncContinuationScreen}
component={withItwEnabled(ItwIssuanceCredentialAsyncContinuationScreen)}
options={hiddenHeader}
/>
{/* CREDENTIAL PRESENTATION */}
<Stack.Screen
name={ITW_ROUTES.PRESENTATION.CREDENTIAL_DETAIL}
component={ItwPresentationCredentialDetailScreen}
component={withItwEnabled(ItwPresentationCredentialDetailScreen)}
options={hiddenHeader}
/>
<Stack.Screen
name={ITW_ROUTES.PRESENTATION.CREDENTIAL_ATTACHMENT}
Expand Down Expand Up @@ -241,3 +247,22 @@ const InnerNavigator = () => {
</Stack.Navigator>
);
};

/**
* A higher-order component which renders the screen only if IT Wallet is enabled.
* In case IT Wallet is not enabled, it renders an error screen.
* @param Screen - The screen to render
* @returns The component or the error screen
*/
const withItwEnabled =
<P extends Record<string, unknown>>(Screen: ComponentType<P>) =>
(props: P) => {
const isItwEnabled = useIOSelector(isItwEnabledSelector);

if (!isItwEnabled) {
// In case the user lands in this screen and IT Wallet is not enabled,
// we should render an error screen.
return <ItwGenericErrorContent />;
}
return <Screen {...props} />;
};
24 changes: 10 additions & 14 deletions ts/features/itwallet/navigation/useItwLinkingOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PathConfigMap } from "@react-navigation/native";
import { AppParamsList } from "../../../navigation/params/AppParamsList";
import { useIOSelector } from "../../../store/hooks";
import { isItwEnabledSelector } from "../common/store/selectors/remoteConfig";
import { itwLifecycleIsValidSelector } from "../lifecycle/store/selectors";
import { ITW_REMOTE_ROUTES } from "../presentation/remote/navigation/routes.ts";
import { ITW_ROUTES } from "./routes";
Expand All @@ -12,24 +11,21 @@ import { ITW_ROUTES } from "./routes";
*/
export const useItwLinkingOptions = (): PathConfigMap<AppParamsList> => {
const isItwValid = useIOSelector(itwLifecycleIsValidSelector);
const isItwEnabled = useIOSelector(isItwEnabledSelector);

return {
[ITW_ROUTES.MAIN]: {
path: "itw",
screens: {
...(isItwEnabled && {
[ITW_ROUTES.ISSUANCE.CREDENTIAL_ASYNC_FLOW_CONTINUATION]:
"credential/issuance",
[isItwValid
? ITW_ROUTES.DISCOVERY.ALREADY_ACTIVE_SCREEN
: ITW_ROUTES.DISCOVERY.INFO]: "discovery/info",
[isItwValid
? ITW_ROUTES.PRESENTATION.CREDENTIAL_DETAIL
: ITW_ROUTES.ISSUANCE.CREDENTIAL_ASYNC_FLOW_CONTINUATION]: {
path: "presentation/credential-detail/:credentialType"
}
})
[ITW_ROUTES.ISSUANCE.CREDENTIAL_ASYNC_FLOW_CONTINUATION]:
"credential/issuance",
[isItwValid
? ITW_ROUTES.DISCOVERY.ALREADY_ACTIVE_SCREEN
: ITW_ROUTES.DISCOVERY.INFO]: "discovery/info",
[isItwValid
? ITW_ROUTES.PRESENTATION.CREDENTIAL_DETAIL
: ITW_ROUTES.ISSUANCE.CREDENTIAL_ASYNC_FLOW_CONTINUATION]: {
path: "presentation/credential-detail/:credentialType"
}
}
},
[ITW_REMOTE_ROUTES.MAIN]: {
Expand Down
Loading