first balance
This commit is contained in:
		
							
								
								
									
										36
									
								
								src/features/balance/balanceSlice.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/features/balance/balanceSlice.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
import {BalanceTransaction} from "../../types/balance";
 | 
			
		||||
import {createAsyncThunk, createSlice, PayloadAction} from "@reduxjs/toolkit";
 | 
			
		||||
import {RootState} from "../../redux/store";
 | 
			
		||||
 | 
			
		||||
const name = 'balance';
 | 
			
		||||
 | 
			
		||||
interface BalanceState {
 | 
			
		||||
    transactions: BalanceTransaction[];
 | 
			
		||||
    balance: number;
 | 
			
		||||
    page: number;
 | 
			
		||||
    loading: boolean;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const initialState: BalanceState = {
 | 
			
		||||
    transactions: [],
 | 
			
		||||
    balance: 0,
 | 
			
		||||
    page: 1,
 | 
			
		||||
    loading: false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const balanceSlice = createSlice({
 | 
			
		||||
    name: name,
 | 
			
		||||
    initialState,
 | 
			
		||||
    reducers: {
 | 
			
		||||
        appendTransactions: (state, payload: PayloadAction<BalanceTransaction[]>) => {
 | 
			
		||||
            state.transactions.push(...payload.payload);
 | 
			
		||||
            state.page = state.page + 1;
 | 
			
		||||
            state.loading = false
 | 
			
		||||
        },
 | 
			
		||||
        setIsLoading: (state, action: PayloadAction<boolean>) => {
 | 
			
		||||
            state.loading = action.payload;
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
})
 | 
			
		||||
export const {appendTransactions, setIsLoading} = balanceSlice.actions;
 | 
			
		||||
export default balanceSlice.reducer;
 | 
			
		||||
		Reference in New Issue
	
	Block a user