-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplug-slice.ts
38 lines (30 loc) · 1.03 KB
/
plug-slice.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import type { RootState } from '@/store';
import { Principal } from '@dfinity/principal';
// Define a type for the slice state
interface PlugState {
principal?: Principal;
isLoading: boolean;
}
// Define the initial state using that type
const initialState: PlugState = {
principal: undefined,
isLoading: false,
};
export const plugSlice = createSlice({
name: 'plug',
// `createSlice` will infer the state type from the `initialState` argument
initialState,
reducers: {
setPrincipal: (state, action: PayloadAction<Principal | undefined>) => {
state.principal = action.payload;
},
setIsLoading: (state, action: PayloadAction<boolean>) => {
state.isLoading = action.payload;
},
},
});
export const plugActions = plugSlice.actions;
// Other code such as selectors can use the imported `RootState` type
export const selectPlugState = (state: RootState) => state.plug;
export default plugSlice.reducer;