import { createSlice } from "@reduxjs/toolkit";

const initialState: ApprovalParams = {
	isVisible: false,
	approvalType: "permit2",
	isApprovalGiven: false,
};

const approvalSlice = createSlice({
	name: "approval",
	initialState,
	reducers: {
		setApprovalData: (state, action) => {
			if (action.payload.isVisible !== undefined) {
				state.isVisible = action.payload.isVisible;
			}
			if (action.payload.approvalType !== undefined) {
				state.approvalType = action.payload.approvalType;
			}
			if (action.payload.isApprovalGiven !== undefined) {
				state.isApprovalGiven = action.payload.isApprovalGiven;
			}
		},
	},
});

export interface ApprovalParams {
	isVisible: boolean;
	approvalType: "permit2" | "permit" | "erc20";
	isApprovalGiven: boolean;
}

export const { setApprovalData } = approvalSlice.actions;
export default approvalSlice.reducer;
