27 lines
663 B
TypeScript

import { createReducer } from '@reduxjs/toolkit';
import { WalletResponse } from '@interfaces';
import { getWalletBalanceThunk } from './thunk';
export interface WalletState {
wallet: WalletResponse;
error: string | null;
}
const initialState: WalletState = {
wallet: {
walletId: '',
currency: '',
balance: 0,
},
error: null,
};
export const accountReducer = createReducer(initialState, builder => {
builder.addCase(getWalletBalanceThunk.fulfilled, (state, action) => {
state.wallet = action.payload;
});
builder.addCase(getWalletBalanceThunk.rejected, (state, action) => {
state.error = action.payload as string;
});
});