import { Toast } from '@pancakeswap-libs/uikit' ; import { createSlice , PayloadAction } from '@reduxjs/toolkit' ; const initialState = { data : [ ] , } ; export interface ToastsState { data : Toast [ ] ; } export const toastsSlice = createSlice ( { name : 'toasts' , initialState , reducers : { push : ( state , action ) => { const { payload } = action ; const toastIndex = state . data . findIndex ( ( toast ) => toast . id === action . payload . id ) ; if ( toastIndex >= 0 ) { state . data . splice ( toastIndex , 1 ) ; } state . data . unshift ( payload ) ; } , remove : ( state , action ) => { const toastIndex = state . data . findIndex ( ( toast ) => toast . id === action . payload ) ; if ( toastIndex >= 0 ) { state . data . splice ( toastIndex , 1 ) ; } } , clear : ( state ) => { state . data = [ ] ; } , } , } ) ; export const { clear , remove , push } = toastsSlice . actions ; export default toastsSlice . reducer ;