import type { PayloadAction } from "@reduxjs/toolkit"; import { createSlice } from "@reduxjs/toolkit"; import type { AppNotification } from "../../types"; export interface NotificationsState { wallet: Record; web3: Record; } const initialState: NotificationsState = { wallet: {}, web3: {} }; const notificationsSlice = createSlice({ name: 'notifications', initialState, reducers: { addNotification: (state, action: PayloadAction) => { if (action.payload.type == 'wallet') { state.wallet[action.payload.id] = action.payload; } else if (action.payload.type == 'web3') { state.web3[action.payload.id] = action.payload; } }, removeNotification: (state, action: PayloadAction) => { delete state.wallet[action.payload]; delete state.web3[action.payload]; }, clearAll: (state, action: PayloadAction<'wallet' | 'web3' | 'all'>) => { if (action.payload === 'wallet') { state.wallet = {}; } else if (action.payload === 'web3') { state.web3 = {}; } else if (action.payload === 'all') { state.wallet = {}; state.web3 = {}; } } } }); export const notificationsActions = notificationsSlice.actions; export const notificationsReducer = notificationsSlice.reducer;