1 import { createAction, createSlice } from '@reduxjs/toolkit';
3 import { type ModelState, getInitialModelState } from '@proton/account';
4 import { getItem, setItem } from '@proton/shared/lib/helpers/storage';
6 const name = 'hide_amounts' as const;
8 export interface HideAmountsState {
9 [name]: ModelState<boolean>;
12 type SliceState = HideAmountsState[typeof name];
13 type Model = NonNullable<SliceState['value']>;
15 export const selectHideAmounts = (state: HideAmountsState) => state[name];
17 const HIDE_AMOUNTS_STORAGE_KEY = 'pw-hide-amounts';
18 const initStorageItem = getItem(HIDE_AMOUNTS_STORAGE_KEY);
20 const initialState = getInitialModelState<Model>(initStorageItem === 'hidden');
22 export const toggleHideAmounts = createAction('toggle-hide-amount');
24 const slice = createSlice({
28 extraReducers: (builder) => {
29 builder.addCase(toggleHideAmounts, (state) => {
31 state.value = !state.value;
32 setItem(HIDE_AMOUNTS_STORAGE_KEY, state.value ? 'hidden' : 'visible');
38 export const hideAmountsReducer = { [name]: slice.reducer };