create `TokenState`

This commit is contained in:
fernandomg 2020-07-14 12:57:10 -03:00
parent f96eb3b8da
commit 4e18a416ee
2 changed files with 9 additions and 11 deletions

View File

@ -3,24 +3,24 @@ import { handleActions } from 'redux-actions'
import { ADD_TOKEN } from 'src/logic/tokens/store/actions/addToken'
import { ADD_TOKENS } from 'src/logic/tokens/store/actions/saveTokens'
import { makeToken } from 'src/logic/tokens/store/model/token'
import { makeToken, Token } from 'src/logic/tokens/store/model/token'
export const TOKEN_REDUCER_ID = 'tokens'
export type TokenState = Map<string, Token>
export default handleActions(
{
[ADD_TOKENS]: (state, action) => {
[ADD_TOKENS]: (state: TokenState, action) => {
const { tokens } = action.payload
const newState = state.withMutations((map) => {
tokens.forEach((token) => {
return state.withMutations((map) => {
tokens.forEach((token: Token) => {
map.set(token.address, token)
})
})
return newState
},
[ADD_TOKEN]: (state, action) => {
[ADD_TOKEN]: (state: TokenState, action) => {
const { token } = action.payload
const { address: tokenAddress } = token

View File

@ -1,11 +1,9 @@
import { Map } from 'immutable'
import { createSelector } from 'reselect'
import { TOKEN_REDUCER_ID } from 'src/logic/tokens/store/reducer/tokens'
import { Token } from 'src/logic/tokens/store/model/token'
import { TOKEN_REDUCER_ID, TokenState } from 'src/logic/tokens/store/reducer/tokens'
import { AppReduxState } from 'src/store'
export const tokensSelector = (state: AppReduxState): Map<string, Token> => state[TOKEN_REDUCER_ID]
export const tokensSelector = (state: AppReduxState): TokenState => state[TOKEN_REDUCER_ID]
export const tokenListSelector = createSelector(tokensSelector, (tokens) => tokens.toList())