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-1089] Add NFC enable state check saga #5745

Merged
merged 25 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5b96fc1
feat: add auth mode selection screen
mastro993 Apr 29, 2024
c01284c
chore: add locales
mastro993 Apr 29, 2024
ed8fba1
chore: add CIE support check
mastro993 Apr 30, 2024
0dc21ee
chore: add NFC enabled check
mastro993 Apr 30, 2024
b311859
chore: rename folder
mastro993 Apr 30, 2024
737fedb
chore: update DS
mastro993 May 2, 2024
e212a97
Merge branch 'master' into SIW-979-add-issuing-authentication-mode-se…
mastro993 May 2, 2024
af15d93
fix: locales
mastro993 May 3, 2024
1af220d
Merge branch 'master' into SIW-979-add-issuing-authentication-mode-se…
mastro993 May 3, 2024
7d2d460
feat: add itw and itwAuthentication reducers
mastro993 May 6, 2024
07d9a02
chore: add sagas and selector
mastro993 May 6, 2024
80ee820
chore: add foce app reload on itw enable
mastro993 May 6, 2024
bb2a046
chore: add tests
mastro993 May 6, 2024
3dbf9f0
Merge branch 'master' into SIW-1089-add-nfc-enabled-state-check
mastro993 May 6, 2024
b4b4bd4
Merge branch 'master' into SIW-979-add-issuing-authentication-mode-se…
mastro993 May 7, 2024
4b9032d
chore: rename feature
mastro993 May 7, 2024
81ae2b4
chore: rename function
mastro993 May 7, 2024
4b8ca02
chore: rename comment
mastro993 May 7, 2024
fb29583
Merge branch 'master' into SIW-979-add-issuing-authentication-mode-se…
mastro993 May 7, 2024
7bad573
Merge branch 'SIW-979-add-issuing-authentication-mode-selection-scree…
mastro993 May 7, 2024
84842e9
chore: rename feature
mastro993 May 7, 2024
c3e7f38
Merge branch 'master' into SIW-1089-add-nfc-enabled-state-check
mastro993 May 7, 2024
a04a7f8
Merge branch 'master' into SIW-1089-add-nfc-enabled-state-check
mastro993 May 7, 2024
094a208
Merge branch 'master' into SIW-1089-add-nfc-enabled-state-check
mastro993 May 8, 2024
e1b7fb5
Merge branch 'master' into SIW-1089-add-nfc-enabled-state-check
mastro993 May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions ts/features/common/store/reducers/index.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
import AsyncStorage from "@react-native-async-storage/async-storage";
import { combineReducers } from "redux";
import { PersistConfig, PersistPartial, persistReducer } from "redux-persist";

import { Action } from "../../../../store/actions/types";
import {
euCovidCertReducer,
EuCovidCertState
TestLoginState,
testLoginReducer
} from "../../../../store/reducers/testLogin";
import {
CieLoginState,
cieLoginReducer
} from "../../../cieLogin/store/reducers";
import {
EuCovidCertState,
euCovidCertReducer
} from "../../../euCovidCert/store/reducers";
import { PnState, pnReducer } from "../../../pn/store/reducers";
import {
FastLoginState,
fastLoginReducer
} from "../../../fastLogin/store/reducers";
import fciReducer, { FciState } from "../../../fci/store/reducers";
import idPayReducer, { IDPayState } from "../../../idpay/common/store/reducers";
import itwReducer, { ItwState } from "../../../itwallet/common/store/reducers";
import {
testLoginReducer,
TestLoginState
} from "../../../../store/reducers/testLogin";
import {
nativeLoginReducer,
NativeLoginState
NativeLoginState,
nativeLoginReducer
} from "../../../nativeLogin/store/reducers";
import {
whatsNewPersistor,
WhatsNewState
} from "../../../whatsnew/store/reducers";

import {
cieLoginReducer,
CieLoginState
} from "../../../cieLogin/store/reducers";

import walletReducer, { WalletState } from "../../../newWallet/store/reducers";
import paymentsReducer, {
PaymentsState
} from "../../../payments/common/store/reducers";
import {
fastLoginReducer,
FastLoginState
} from "../../../fastLogin/store/reducers";
import walletReducer, { WalletState } from "../../../newWallet/store/reducers";
import { PnState, pnReducer } from "../../../pn/store/reducers";
import servicesReducer, {
ServicesState
} from "../../../services/common/store/reducers";
import {
WhatsNewState,
whatsNewPersistor
} from "../../../whatsnew/store/reducers";

type LoginFeaturesState = {
testLogin: TestLoginState;
Expand All @@ -57,6 +55,7 @@ export type FeaturesState = {
payments: PaymentsState;
services: ServicesState;
wallet: WalletState;
itw: ItwState;
};

export type PersistedFeaturesState = FeaturesState & PersistPartial;
Expand All @@ -75,7 +74,8 @@ const rootReducer = combineReducers<FeaturesState, Action>({
fastLogin: fastLoginReducer,
cieLogin: cieLoginReducer
}),
wallet: walletReducer
wallet: walletReducer,
itw: itwReducer
});

const CURRENT_REDUX_FEATURES_STORE_VERSION = 1;
Expand Down
17 changes: 17 additions & 0 deletions ts/features/itwallet/common/saga/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { SagaIterator } from "redux-saga";
import { fork, select } from "typed-redux-saga/macro";
import { isItWalletTestEnabledSelector } from "../../../../store/reducers/persistedPreferences";
import { watchItwIdentificationSaga } from "../../identification/saga";

export function* watchItwSaga(): SagaIterator {
const isItWalletTestEnabled: ReturnType<
typeof isItWalletTestEnabledSelector
> = yield* select(isItWalletTestEnabledSelector);

if (!isItWalletTestEnabled) {
// If itw test is not enabled do not initialize itw sagas
return;
}

yield* fork(watchItwIdentificationSaga);
}
3 changes: 3 additions & 0 deletions ts/features/itwallet/common/store/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ItwIdentificationActions } from "../../../identification/store/actions";

export type ItwActions = ItwIdentificationActions;
14 changes: 14 additions & 0 deletions ts/features/itwallet/common/store/reducers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { combineReducers } from "redux";
import identificationReducer, {
ItwIdentificationState
} from "../../../identification/store/reducers";

export type ItwState = {
identification: ItwIdentificationState;
};

const itwReducer = combineReducers({
identification: identificationReducer
});

export default itwReducer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { testSaga } from "redux-saga-test-plan";
import cieManager from "@pagopa/react-native-cie";
import { handleNfcEnabledSaga } from "../handleNfcEnabledSaga";
import { itwNfcIsEnabled } from "../../store/actions";

describe("handleNfcEnabledSaga", () => {
test.each([true, false])(
"If isNFCEnabled returns %p, should update the state accordingly",
arg => {
testSaga(handleNfcEnabledSaga)
.next()
.call(cieManager.isNFCEnabled)
.next(arg)
.put(itwNfcIsEnabled.success(arg))
.next()
.isDone();
}
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import cieManager from "@pagopa/react-native-cie";
import { call, put } from "typed-redux-saga/macro";
import { SagaCallReturnType } from "../../../../types/utils";
import { convertUnknownToError } from "../../../../utils/errors";
import { itwNfcIsEnabled } from "../store/actions";

export function* handleNfcEnabledSaga() {
try {
const isNfcEnabled: SagaCallReturnType<typeof cieManager.isNFCEnabled> =
yield* call(cieManager.isNFCEnabled);
yield* put(itwNfcIsEnabled.success(isNfcEnabled));
} catch (e) {
yield* put(itwNfcIsEnabled.failure(convertUnknownToError(e)));
}
}
8 changes: 8 additions & 0 deletions ts/features/itwallet/identification/saga/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SagaIterator } from "redux-saga";
import { takeLatest } from "typed-redux-saga/macro";
import { itwNfcIsEnabled } from "../store/actions";
import { handleNfcEnabledSaga } from "./handleNfcEnabledSaga";

export function* watchItwIdentificationSaga(): SagaIterator {
yield* takeLatest(itwNfcIsEnabled.request, handleNfcEnabledSaga);
}
9 changes: 9 additions & 0 deletions ts/features/itwallet/identification/store/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ActionType, createAsyncAction } from "typesafe-actions";

export const itwNfcIsEnabled = createAsyncAction(
"ITW_NFC_IS_ENABLED_REQUEST",
"ITW_NFC_IS_ENABLED_SUCCESS",
"ITW_NFC_IS_ENABLED_FAILURE"
)<void, boolean, Error>();

export type ItwIdentificationActions = ActionType<typeof itwNfcIsEnabled>;
38 changes: 38 additions & 0 deletions ts/features/itwallet/identification/store/reducers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as pot from "@pagopa/ts-commons/lib/pot";
import { getType } from "typesafe-actions";
import { Action } from "../../../../../store/actions/types";
import { itwNfcIsEnabled } from "../actions";

export type ItwIdentificationState = {
isNfcEnabled: pot.Pot<boolean, Error>;
};

const INITIAL_STATE: ItwIdentificationState = {
isNfcEnabled: pot.none
};

const reducer = (
state: ItwIdentificationState = INITIAL_STATE,
action: Action
): ItwIdentificationState => {
switch (action.type) {
case getType(itwNfcIsEnabled.request):
return {
...state,
isNfcEnabled: pot.toLoading(state.isNfcEnabled)
};
case getType(itwNfcIsEnabled.success):
return {
...state,
isNfcEnabled: pot.some(action.payload)
};
case getType(itwNfcIsEnabled.failure):
return {
...state,
isNfcEnabled: pot.toError(state.isNfcEnabled, action.payload)
};
}
return state;
};

export default reducer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { GlobalState } from "../../../../../store/reducers/types";

export const itwIsNfcEnabledSelector = (state: GlobalState) =>
state.features.itw.identification.isNfcEnabled;
4 changes: 4 additions & 0 deletions ts/sagas/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import { watchEmailValidationSaga } from "../store/sagas/emailValidationPollingS
import { handleIsKeyStrongboxBacked } from "../features/lollipop/utils/crypto";
import { watchWalletSaga as watchNewWalletSaga } from "../features/newWallet/saga";
import { watchServicesSaga } from "../features/services/common/saga";
import { watchItwSaga } from "../features/itwallet/common/saga";
import {
clearKeychainError,
keychainError
Expand Down Expand Up @@ -550,6 +551,9 @@ export function* initializeApplicationSaga(
yield* fork(watchIDPaySaga, maybeSessionInformation.value.bpdToken);
}

// Start watching for itw saga
yield* fork(watchItwSaga);

// Start watching for Wallet V3 actions
yield* fork(watchPaymentsSaga, maybeSessionInformation.value.walletToken);

Expand Down
1 change: 1 addition & 0 deletions ts/screens/profile/DeveloperModeSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ const DeveloperTestEnvironmentSection = ({
dispatch(
preferencesItWalletTestSetEnabled({ isItWalletTestEnabled: enabled })
);
handleShowModal();
};
return (
<ContentWrapper>
Expand Down
4 changes: 3 additions & 1 deletion ts/store/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ServicesActions as NewServicesActions } from "../../features/services/c
import { WhatsNewActions } from "../../features/whatsnew/store/actions";
import { ZendeskSupportActions } from "../../features/zendesk/store/actions";
import { GlobalState } from "../reducers/types";
import { ItwActions } from "../../features/itwallet/common/store/actions";
import { AnalyticsActions } from "./analytics";
import { ApplicationActions } from "./application";
import { AuthenticationActions } from "./authentication";
Expand Down Expand Up @@ -102,7 +103,8 @@ export type Action =
| WhatsNewActions
| PaymentsFeatureActions
| NewWalletActions
| NewServicesActions;
| NewServicesActions
| ItwActions;

export type Dispatch = DispatchAPI<Action>;

Expand Down
Loading