Skip to content

Commit

Permalink
Merge branch 'master' into IOPAE-1795-service-details-screen-IOScroll…
Browse files Browse the repository at this point in the history
…View
  • Loading branch information
CrisTofani authored Feb 24, 2025
2 parents 9bb866d + 82033be commit e5a2d34
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
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 @@ -88,15 +92,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 @@ -193,13 +198,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 @@ -242,3 +248,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

0 comments on commit e5a2d34

Please sign in to comment.