45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { WalletTopUpPaymentSessionResponse, WalletTransaction } from '@interfaces';
|
|
import { createReducer } from '@reduxjs/toolkit';
|
|
import { getAllWalletTransactions, initializeWalletTopUpThunk } from './thunk';
|
|
|
|
export interface walletState {
|
|
walletTransactions: WalletTransaction[];
|
|
loading: boolean;
|
|
error: string | null;
|
|
walletTopUpPaymentSessionResponse: WalletTopUpPaymentSessionResponse | null;
|
|
}
|
|
|
|
const initialState: walletState = {
|
|
walletTransactions: [],
|
|
loading: false,
|
|
error: null,
|
|
walletTopUpPaymentSessionResponse: null,
|
|
};
|
|
|
|
export const walletReducer = createReducer(initialState, builder => {
|
|
builder.addCase(getAllWalletTransactions.pending, state => {
|
|
state.loading = true;
|
|
state.error = null;
|
|
});
|
|
builder.addCase(getAllWalletTransactions.fulfilled, (state, action) => {
|
|
state.loading = false;
|
|
state.walletTransactions = action.payload;
|
|
});
|
|
builder.addCase(getAllWalletTransactions.rejected, (state, action) => {
|
|
state.loading = false;
|
|
state.error = action.payload as string | null;
|
|
});
|
|
builder.addCase(initializeWalletTopUpThunk.pending, state => {
|
|
state.loading = true;
|
|
state.error = null;
|
|
});
|
|
builder.addCase(initializeWalletTopUpThunk.fulfilled, (state, action) => {
|
|
state.loading = false;
|
|
state.walletTopUpPaymentSessionResponse = action.payload;
|
|
});
|
|
builder.addCase(initializeWalletTopUpThunk.rejected, (state, action) => {
|
|
state.loading = false;
|
|
state.error = action.payload as string | null;
|
|
});
|
|
});
|