-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbalance-slice.ts
46 lines (38 loc) · 1.27 KB
/
balance-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
39
40
41
42
43
44
45
46
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import type { RootState } from '@/store';
import { Token } from '@psychedelic/sonic-js';
// Define a type for the slice state
interface BalanceState {
balanceList?: Token.BalanceList;
balanceOf?: string;
isLoading: boolean;
}
// Define the initial state using that type
const initialState: BalanceState = {
balanceOf: undefined,
balanceList: undefined,
isLoading: false,
};
export const balanceSlice = createSlice({
name: 'balance',
// `createSlice` will infer the state type from the `initialState` argument
initialState,
reducers: {
setBalanceList: (
state,
action: PayloadAction<Token.BalanceList | undefined>
) => {
state.balanceList = action.payload;
},
setIsLoading: (state, action: PayloadAction<boolean>) => {
state.isLoading = action.payload;
},
setBalanceOf: (state, action: PayloadAction<string | undefined>) => {
state.balanceOf = action.payload;
},
},
});
export const balanceActions = balanceSlice.actions;
// Other code such as selectors can use the imported `RootState` type
export const selectBalanceState = (state: RootState) => state.balance;
export default balanceSlice.reducer;