Skip to content

Commit

Permalink
fix(IT Wallet): [SIW-568,SIW-565] Decode PID at startup after PIN (#5057
Browse files Browse the repository at this point in the history
)

## Short description
This PR proposes a refactor to the PID decode process which is now
decoded at startup after the user inserts its PIN.

## List of changes proposed in this pull request
- Adds the PID decode action dispatch in the startup saga. This allows
us to not worry about decoding the PID in each screen it needs to be
decoded;
- Removes the decoding from the `ItwHomeScreen.tsx` screen but keeps it
in the `itwPidPreviewScreen.tsx`. That's necessary because the issuing
happens after the startup saga if the wallet operational.

We might rethink the PID state to be incorporated into the credentials
state down the road.

## How to test
There a are few things that should be tested: 
1. Obtain a PID;
2. Authenticate on the RP demo website;
3. Close the app and open it again. You should still see the decoded PID
in the wallet section;
4. Close the app and open it again. Start the RP flow without opening
the wallet section, it should work as expected.
  • Loading branch information
LazyAfternoons committed Oct 3, 2023
1 parent 18977da commit 29dcff7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
12 changes: 1 addition & 11 deletions ts/features/it-wallet/screens/ItwHomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import { ContextualHelpPropsMarkdown } from "../../../components/screens/BaseScr
import { ItwActionBanner } from "../components/ItwActionBanner";
import { IOStyles } from "../../../components/core/variables/IOStyles";
import BadgeButton from "../components/design/BadgeButton";
import { useIODispatch, useIOSelector } from "../../../store/hooks";
import { useIOSelector } from "../../../store/hooks";
import { ITW_ROUTES } from "../navigation/ItwRoutes";
import { useOnFirstRender } from "../../../utils/hooks/useOnFirstRender";
import PidCredential from "../components/PidCredential";
import { IOStackNavigationProp } from "../../../navigation/params/AppParamsList";
import { ItwParamsList } from "../navigation/ItwParamsList";
Expand All @@ -30,7 +29,6 @@ import { cancelButtonProps } from "../utils/itwButtonsUtils";
import { itwLifecycleIsOperationalSelector } from "../store/reducers/itwLifecycleReducer";
import { ItwCredentialsPidSelector } from "../store/reducers/itwCredentialsReducer";
import { ItwDecodedPidPotSelector } from "../store/reducers/itwPidDecodeReducer";
import { itwDecodePid } from "../store/actions/itwCredentialsActions";
import { useItwResetFlow } from "../hooks/useItwResetFlow";
import { itWalletExperimentalEnabled } from "../../../config";

Expand All @@ -55,7 +53,6 @@ const ItwHomeScreen = () => {
);
const pid = useIOSelector(ItwCredentialsPidSelector);
const decodedPidPot = useIOSelector(ItwDecodedPidPotSelector);
const dispatch = useIODispatch();
const [selectedBadgeIdx, setSelectedBadgeIdx] = useState(0);
const badgesLabels = [
I18n.t("features.itWallet.homeScreen.categories.any"),
Expand All @@ -65,13 +62,6 @@ const ItwHomeScreen = () => {
I18n.t("features.itWallet.homeScreen.categories.bonus")
];

/**
* Decodes the PID on first render since we don't know if the PID has been decoded yet.
*/
useOnFirstRender(() => {
dispatch(itwDecodePid.request(pid));
});

/**
* Condionally navigate to the credentials catalog screen if the experimental feature flag is true.
* Otherwise do nothing.
Expand Down
6 changes: 3 additions & 3 deletions ts/features/it-wallet/screens/issuing/ItwPidPreviewScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ import ScreenContent from "../../../../components/screens/ScreenContent";
import FooterWithButtons from "../../../../components/ui/FooterWithButtons";
import { useItwAbortFlow } from "../../hooks/useItwAbortFlow";
import { ITW_ROUTES } from "../../navigation/ItwRoutes";
import { useOnFirstRender } from "../../../../utils/hooks/useOnFirstRender";
import { ItwParamsList } from "../../navigation/ItwParamsList";
import { IOStackNavigationProp } from "../../../../navigation/params/AppParamsList";
import { useIODispatch, useIOSelector } from "../../../../store/hooks";
import LoadingSpinnerOverlay from "../../../../components/LoadingSpinnerOverlay";
import { itwPidValueSelector } from "../../store/reducers/itwPidReducer";
import { ItwDecodedPidPotSelector } from "../../store/reducers/itwPidDecodeReducer";
import { itwDecodePid } from "../../store/actions/itwCredentialsActions";
import ItwErrorView from "../../components/ItwErrorView";
import { cancelButtonProps } from "../../utils/itwButtonsUtils";
import { H4 } from "../../../../components/core/typography/H4";
import ItwPidClaimsList from "../../components/ItwPidClaimsList";
import { useOnFirstRender } from "../../../../utils/hooks/useOnFirstRender";
import { itwDecodePid } from "../../store/actions/itwCredentialsActions";
import { itwPidValueSelector } from "../../store/reducers/itwPidReducer";

type ContentViewProps = {
decodedPid: PidWithToken;
Expand Down
9 changes: 9 additions & 0 deletions ts/sagas/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ import {
import { refreshSessionToken } from "../features/fastLogin/store/actions";
import { enableWhatsNewCheck } from "../features/whatsnew/store/actions";
import { watchItwSaga } from "../features/it-wallet/saga";
import { itwLifecycleIsValidSelector } from "../features/it-wallet/store/reducers/itwLifecycleReducer";
import { itwDecodePid } from "../features/it-wallet/store/actions/itwCredentialsActions";
import { ItwCredentialsPidSelector } from "../features/it-wallet/store/reducers/itwCredentialsReducer";
import { startAndReturnIdentificationResult } from "./identification";
import { previousInstallationDataDeleteSaga } from "./installation";
import watchLoadMessageDetails from "./messages/watchLoadMessageDetails";
Expand Down Expand Up @@ -591,6 +594,12 @@ export function* initializeApplicationSaga(
if (itWalletEnabled) {
// Start watching for ITWallet actions
yield* fork(watchItwSaga);
// If IT-Wallet is enabled and operational, then dispatch the PID decode request.
const isItWalletValid = yield* select(itwLifecycleIsValidSelector);
if (isItWalletValid) {
const pid = yield* select(ItwCredentialsPidSelector);
yield* put(itwDecodePid.request(pid));
}
}

// Load the user metadata
Expand Down

0 comments on commit 29dcff7

Please sign in to comment.