import { PayloadAction, createSlice } from '@reduxjs/toolkit'; export enum Onboarding { /** starting screen */ Start, /** uses AccountCreation internally */ CreateAccount, /** uses AccountRestoration internally */ RestoreAccount, } export enum AccountCreation { /** TODO to be removed - current starting screen */ Start, /** TODO to be removed */ SessionIDShown, /** starting screen */ DisplayName, /** show conversation screen */ Complete, } export enum AccountRestoration { /** TODO to be removed - current starting screen */ Start, /** starting screen */ RecoveryPassword, /** fetching account details */ Loading, /** we failed to fetch a display name in time so we choose a new one */ DisplayName, /** show conversation screen */ Complete, /** TODO to be removed */ LinkDevice, } export type OnboardingState = { generatedRecoveryPhrase: string; hexGeneratedPubKey: string; step: Onboarding; accountCreationStep: AccountCreation; accountRestorationStep: AccountRestoration; }; const initialState: OnboardingState = { generatedRecoveryPhrase: '', hexGeneratedPubKey: '', step: Onboarding.Start, accountRestorationStep: AccountRestoration.Start, accountCreationStep: AccountCreation.Start, }; export const registrationSlice = createSlice({ name: 'registration', initialState, reducers: { setGeneratedRecoveryPhrase(state, action: PayloadAction) { return { ...state, generatedRecoveryPhrase: action.payload }; }, setHexGeneratedPubKey(state, action: PayloadAction) { return { ...state, hexGeneratedPubKey: action.payload }; }, setOnboardingStep(state, action: PayloadAction) { return { ...state, step: action.payload }; }, setAccountCreationStep(state, action: PayloadAction) { return { ...state, accountCreationStep: action.payload }; }, setAccountRestorationStep(state, action: PayloadAction) { return { ...state, accountRestorationStep: action.payload }; }, }, }); export const { setGeneratedRecoveryPhrase, setHexGeneratedPubKey, setOnboardingStep, setAccountCreationStep, setAccountRestorationStep, } = registrationSlice.actions; export default registrationSlice.reducer;