Skip to content

Commit

Permalink
chore(IT Wallet): [SIW-1404] Move CIE/NFC logic to XState (#6508)
Browse files Browse the repository at this point in the history
  • Loading branch information
mastro993 authored Dec 9, 2024
1 parent 1dbc898 commit 8465717
Show file tree
Hide file tree
Showing 22 changed files with 137 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ exports[`featuresPersistor should match snapshot 1`] = `
"_tag": "None",
},
},
"identification": {
"isCieSupported": {
"kind": "PotNone",
},
"isNfcEnabled": {
"kind": "PotNone",
},
},
"issuance": {
"integrityKeyTag": {
"_tag": "None",
Expand Down
8 changes: 1 addition & 7 deletions ts/features/itwallet/common/saga/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { SagaIterator } from "redux-saga";
import { call, fork, put } from "typed-redux-saga/macro";
import { call, fork } from "typed-redux-saga/macro";
import { watchItwCredentialsSaga } from "../../credentials/saga";
import { checkCredentialsStatusAttestation } from "../../credentials/saga/checkCredentialsStatusAttestation";
import { handleWalletCredentialsRehydration } from "../../credentials/saga/handleWalletCredentialsRehydration";
import { watchItwIdentificationSaga } from "../../identification/saga";
import { itwCieIsSupported } from "../../identification/store/actions";
import { watchItwLifecycleSaga } from "../../lifecycle/saga";
import { checkWalletInstanceStateSaga } from "../../lifecycle/saga/checkWalletInstanceStateSaga";

Expand All @@ -18,10 +16,6 @@ function* checkWalletInstanceAndCredentialsValiditySaga() {
export function* watchItwSaga(): SagaIterator {
yield* fork(checkWalletInstanceAndCredentialsValiditySaga);
yield* fork(handleWalletCredentialsRehydration);
yield* fork(watchItwIdentificationSaga);
yield* fork(watchItwCredentialsSaga);
yield* fork(watchItwLifecycleSaga);

// TODO: [SIW-1404] remove this CIE check and move the logic to xstate
yield* put(itwCieIsSupported.request());
}
2 changes: 0 additions & 2 deletions ts/features/itwallet/common/store/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ItwCredentialsActions } from "../../../credentials/store/actions";
import { ItwIdentificationActions } from "../../../identification/store/actions";
import { ItwIssuanceActions } from "../../../issuance/store/actions";
import { ItwLifecycleActions } from "../../../lifecycle/store/actions";
import { ItwWalletInstanceActions } from "../../../walletInstance/store/actions";
import { ItwPreferencesActions } from "./preferences";

export type ItwActions =
| ItwIdentificationActions
| ItwIssuanceActions
| ItwLifecycleActions
| ItwCredentialsActions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ exports[`itWalletReducer should match snapshot 1`] = `
"_tag": "None",
},
},
"identification": {
"isCieSupported": {
"kind": "PotNone",
},
"isNfcEnabled": {
"kind": "PotNone",
},
},
"issuance": {
"integrityKeyTag": {
"_tag": "None",
Expand Down
5 changes: 0 additions & 5 deletions ts/features/itwallet/common/store/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import { isDevEnv } from "../../../../../utils/environment";
import itwCredentialsReducer, {
ItwCredentialsState
} from "../../../credentials/store/reducers";
import identificationReducer, {
ItwIdentificationState
} from "../../../identification/store/reducers";
import issuanceReducer, {
ItwIssuanceState
} from "../../../issuance/store/reducers";
Expand All @@ -29,7 +26,6 @@ import wiaReducer, {
import preferencesReducer, { ItwPreferencesState } from "./preferences";

export type ItWalletState = {
identification: ItwIdentificationState;
issuance: ItwIssuanceState & PersistPartial;
lifecycle: ItwLifecycleState;
credentials: ItwCredentialsState & PersistPartial;
Expand All @@ -40,7 +36,6 @@ export type ItWalletState = {
export type PersistedItWalletState = ReturnType<typeof persistedReducer>;

const itwReducer = combineReducers({
identification: identificationReducer,
issuance: issuanceReducer,
lifecycle: lifecycleReducer,
credentials: itwCredentialsReducer,
Expand Down

This file was deleted.

13 changes: 0 additions & 13 deletions ts/features/itwallet/identification/saga/handleCieSupportedSaga.ts

This file was deleted.

15 changes: 0 additions & 15 deletions ts/features/itwallet/identification/saga/handleNfcEnabledSaga.ts

This file was deleted.

11 changes: 0 additions & 11 deletions ts/features/itwallet/identification/saga/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ import {
ModuleNavigation,
VStack
} from "@pagopa/io-app-design-system";
import * as pot from "@pagopa/ts-commons/lib/pot";
import React, { useCallback, useMemo } from "react";
import { useFocusEffect } from "@react-navigation/native";
import I18n from "../../../../i18n";
import { useIOSelector } from "../../../../store/hooks";
import { cieFlowForDevServerEnabled } from "../../../cieLogin/utils";
import { ItwEidIssuanceMachineContext } from "../../machine/provider";
import { itwIsCieSupportedSelector } from "../store/selectors";
import {
trackItWalletIDMethod,
trackItWalletIDMethodSelected
} from "../../analytics";
import { itwDisabledIdentificationMethodsSelector } from "../../../../store/reducers/backendStatus/remoteConfig";
import { IOScrollViewWithLargeHeader } from "../../../../components/ui/IOScrollViewWithLargeHeader";
import { isCIEAuthenticationSupportedSelector } from "../../machine/eid/selectors";

export const ItwIdentificationModeSelectionScreen = () => {
const machineRef = ItwEidIssuanceMachineContext.useActorRef();
const isCieSupportedPot = useIOSelector(itwIsCieSupportedSelector);
const isCieAuthenticationSupported = ItwEidIssuanceMachineContext.useSelector(
isCIEAuthenticationSupportedSelector
);
const disabledIdentificationMethods = useIOSelector(
itwDisabledIdentificationMethodsSelector
);
Expand All @@ -40,8 +41,8 @@ export const ItwIdentificationModeSelectionScreen = () => {
);

const isCieSupported = useMemo(
() => cieFlowForDevServerEnabled || pot.getOrElse(isCieSupportedPot, false),
[isCieSupportedPot]
() => cieFlowForDevServerEnabled || isCieAuthenticationSupported,
[isCieAuthenticationSupported]
);

useFocusEffect(trackItWalletIDMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jest.mock("../../../../../config", () => ({
itwEnabled: true
}));

jest.mock("../../../../../store/reducers/cie", () => ({
isCieSupportedSelector: () => true
jest.mock("../../../machine/eid/selectors", () => ({
isCIEAuthenticationSupportedSelector: () => true
}));

describe("ItwIdentificationModeSelectionScreen", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import {
OTPInput,
VSpacer
} from "@pagopa/io-app-design-system";
import * as pot from "@pagopa/ts-commons/lib/pot";
import { Millisecond } from "@pagopa/ts-commons/lib/units";
import { useHeaderHeight } from "@react-navigation/elements";
import { useFocusEffect, useIsFocused } from "@react-navigation/native";
import React, { useCallback, useEffect, useRef, useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import {
Keyboard,
KeyboardAvoidingView,
Expand All @@ -25,7 +24,7 @@ import { pinPukHelpUrl } from "../../../../../config";
import { isCieLoginUatEnabledSelector } from "../../../../../features/cieLogin/store/selectors";
import { useHeaderSecondLevel } from "../../../../../hooks/useHeaderSecondLevel";
import I18n from "../../../../../i18n";
import { useIODispatch, useIOSelector } from "../../../../../store/hooks";
import { useIOSelector } from "../../../../../store/hooks";
import { setAccessibilityFocus } from "../../../../../utils/accessibility";
import { useIOBottomSheetAutoresizableModal } from "../../../../../utils/hooks/bottomSheet";
import { withTrailingPoliceCarLightEmojii } from "../../../../../utils/strings";
Expand All @@ -36,8 +35,6 @@ import {
trackItWalletCiePinInfo
} from "../../../analytics";
import { ItwEidIssuanceMachineContext } from "../../../machine/provider";
import { itwNfcIsEnabled } from "../../store/actions";
import { itwIsNfcEnabledSelector } from "../../store/selectors";

const CIE_PIN_LENGTH = 8;

Expand All @@ -64,11 +61,7 @@ const ForgottenPin = () => (
);

export const ItwCiePinScreen = () => {
const dispatch = useIODispatch();
const useCieUat = useIOSelector(isCieLoginUatEnabledSelector);
const isEnabled = useIOSelector(itwIsNfcEnabledSelector);
const isNfcEnabled = pot.getOrElse(isEnabled, false);

const machineRef = ItwEidIssuanceMachineContext.useActorRef();

const [pin, setPin] = useState("");
Expand All @@ -82,11 +75,6 @@ export const ItwCiePinScreen = () => {
title: I18n.t("bottomSheets.ciePin.title")
});

const requestNfcEnabledCheck = useCallback(
() => dispatch(itwNfcIsEnabled.request()),
[dispatch]
);

useEffect(() => {
// Reset the pin when the user leaves the screen.
if (!isFocused) {
Expand All @@ -98,8 +86,7 @@ export const ItwCiePinScreen = () => {
React.useCallback(() => {
trackItWalletCiePinEnter();
setAccessibilityFocus(pinPadViewRef, 300 as Millisecond);
requestNfcEnabledCheck();
}, [requestNfcEnabledCheck])
}, [])
);

useHeaderSecondLevel({
Expand All @@ -113,7 +100,7 @@ export const ItwCiePinScreen = () => {

if (value.length === CIE_PIN_LENGTH) {
Keyboard.dismiss();
machineRef.send({ type: "cie-pin-entered", pin: value, isNfcEnabled });
machineRef.send({ type: "cie-pin-entered", pin: value });
}
};

Expand Down
18 changes: 0 additions & 18 deletions ts/features/itwallet/identification/store/actions/index.ts

This file was deleted.

56 changes: 0 additions & 56 deletions ts/features/itwallet/identification/store/reducers/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions ts/features/itwallet/identification/store/selectors/index.ts

This file was deleted.

Loading

0 comments on commit 8465717

Please sign in to comment.