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

fix(IT Wallet): [SIW-1986] Persist ITW store after logout #6619

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
itwFlagCredentialAsRequested,
itwUnflagCredentialAsRequested
} from "../../actions/preferences";
import reducer, { ItwPreferencesState } from "../preferences";
import reducer, {
ItwPreferencesState,
itwPreferencesInitialState
} from "../preferences";
import { itwLifecycleStoresReset } from "../../../../lifecycle/store/actions";

describe("IT Wallet preferences reducer", () => {
const INITIAL_STATE: ItwPreferencesState = {
Expand Down Expand Up @@ -87,4 +91,11 @@ describe("IT Wallet preferences reducer", () => {
});
MockDate.reset();
});

it("should handle itwLifecycleStoresReset action", () => {
const action = itwLifecycleStoresReset();
const newState = reducer(INITIAL_STATE, action);

expect(newState).toEqual(itwPreferencesInitialState);
});
});
8 changes: 6 additions & 2 deletions ts/features/itwallet/common/store/reducers/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
itwFlagCredentialAsRequested,
itwUnflagCredentialAsRequested
} from "../actions/preferences";
import { itwLifecycleStoresReset } from "../../../lifecycle/store/actions";

export type ItwPreferencesState = {
// Date until which the feedback banner should be hidden
Expand All @@ -19,12 +20,12 @@ export type ItwPreferencesState = {
requestedCredentials: { [credentialType: string]: string };
};

const INITIAL_STATE: ItwPreferencesState = {
export const itwPreferencesInitialState: ItwPreferencesState = {
requestedCredentials: {}
};

const reducer = (
state: ItwPreferencesState = INITIAL_STATE,
state: ItwPreferencesState = itwPreferencesInitialState,
action: Action
): ItwPreferencesState => {
switch (action.type) {
Expand Down Expand Up @@ -65,6 +66,9 @@ const reducer = (
return state;
}

case getType(itwLifecycleStoresReset):
return { ...itwPreferencesInitialState };

default:
return state;
}
Expand Down
17 changes: 9 additions & 8 deletions ts/store/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,16 @@ export function createRootReducer(
.hasUserAcknowledgedSettingsBanner,
_persist: state.features.profileSettings._persist
},
_persist: state.features._persist,
// IT Wallet must be kept
/**
* IT Wallet state persists across sessions and is explicitly reset on session changes
* via the itwLifecycleStoresReset action to ensure proper cleanup.
* We can avoid to replicate the _persist property because itWallet already is a persisted
* reducer.
*/
itWallet: {
issuance: state.features.itWallet.issuance,
lifecycle: state.features.itWallet.lifecycle,
credentials: state.features.itWallet.credentials,

_persist: state.features.itWallet._persist
}
...state.features.itWallet
},
_persist: state.features._persist
},
identification: {
...identificationInitialState,
Expand Down
Loading