fix flow annotation for createAction for tokens actions

This commit is contained in:
Mikhail Mikheev 2019-03-28 13:10:58 +04:00
parent 718e84aea3
commit 05c6ffbce7
6 changed files with 15 additions and 19 deletions

View File

@ -1,7 +1,7 @@
// @flow // @flow
import { createAction } from 'redux-actions' import { createAction } from 'redux-actions'
import { type Token } from '~/logic/tokens/store/model/token' import { type Token } from '~/logic/tokens/store/model/token'
import { setActiveTokens, getActiveTokenAddresses, setToken } from '~/logic/tokens/utils/tokensStorage' import { setActiveTokens, getActiveTokens, setToken } from '~/logic/tokens/utils/tokensStorage'
import type { Dispatch as ReduxDispatch } from 'redux' import type { Dispatch as ReduxDispatch } from 'redux'
import { type GlobalState } from '~/store/index' import { type GlobalState } from '~/store/index'
@ -12,7 +12,7 @@ type AddTokenProps = {
token: Token, token: Token,
} }
export const addToken = createAction( export const addToken = createAction<string, *, *>(
ADD_TOKEN, ADD_TOKEN,
(safeAddress: string, token: Token): AddTokenProps => ({ (safeAddress: string, token: Token): AddTokenProps => ({
safeAddress, safeAddress,
@ -23,9 +23,8 @@ export const addToken = createAction(
const saveToken = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => { const saveToken = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => {
dispatch(addToken(safeAddress, token)) dispatch(addToken(safeAddress, token))
const tokenAddress = token.get('address') const activeTokens = await getActiveTokens(safeAddress)
const activeTokens = await getActiveTokenAddresses(safeAddress) await setActiveTokens(safeAddress, activeTokens.push(token))
await setActiveTokens(safeAddress, activeTokens.push(tokenAddress))
setToken(safeAddress, token) setToken(safeAddress, token)
} }

View File

@ -17,7 +17,7 @@ type TokenProps = {
tokens: Map<string, Token>, tokens: Map<string, Token>,
} }
export const addTokens = createAction( export const addTokens = createAction<string, *, *>(
ADD_TOKENS, ADD_TOKENS,
(safeAddress: string, tokens: Map<string, Token>): TokenProps => ({ (safeAddress: string, tokens: Map<string, Token>): TokenProps => ({
safeAddress, safeAddress,

View File

@ -7,16 +7,15 @@ import { removeFromActiveTokens } from '~/logic/tokens/utils/tokensStorage'
export const DISABLE_TOKEN = 'DISABLE_TOKEN' export const DISABLE_TOKEN = 'DISABLE_TOKEN'
export const disableToken = createAction(DISABLE_TOKEN, (safeAddress: string, tokenAddress: string) => ({ export const disableToken = createAction<string, *, *>(DISABLE_TOKEN, (safeAddress: string, token: Token) => ({
safeAddress, safeAddress,
tokenAddress, token,
})) }))
const hideToken = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => { const hideToken = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => {
const { address } = token dispatch(disableToken(safeAddress, token))
dispatch(disableToken(safeAddress, address))
await removeFromActiveTokens(safeAddress, address) await removeFromActiveTokens(safeAddress, token)
} }
export default hideToken export default hideToken

View File

@ -7,14 +7,13 @@ import { setActiveTokens, getActiveTokens } from '~/logic/tokens/utils/tokensSto
export const ENABLE_TOKEN = 'ENABLE_TOKEN' export const ENABLE_TOKEN = 'ENABLE_TOKEN'
export const enableToken = createAction(ENABLE_TOKEN, (safeAddress: string, tokenAddress: string) => ({ export const enableToken = createAction<string, *, *>(ENABLE_TOKEN, (safeAddress: string, token: Token) => ({
safeAddress, safeAddress,
tokenAddress, token,
})) }))
const setTokenEnabled = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => { const setTokenEnabled = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => {
const { address } = token dispatch(enableToken(safeAddress, token))
dispatch(enableToken(safeAddress, address))
const activeTokens = await getActiveTokens(safeAddress) const activeTokens = await getActiveTokens(safeAddress)
await setActiveTokens(safeAddress, activeTokens.push(token)) await setActiveTokens(safeAddress, activeTokens.push(token))

View File

@ -10,7 +10,7 @@ import { getWeb3 } from '~/logic/wallets/getWeb3'
import { type GlobalState } from '~/store/index' import { type GlobalState } from '~/store/index'
import { makeToken, type Token, type TokenProps } from '~/logic/tokens/store/model/token' import { makeToken, type Token, type TokenProps } from '~/logic/tokens/store/model/token'
import { ensureOnce } from '~/utils/singleton' import { ensureOnce } from '~/utils/singleton'
import { getActiveTokenAddresses, getTokens } from '~/logic/tokens/utils/tokensStorage' import { getActiveTokens, getTokens } from '~/logic/tokens/utils/tokensStorage'
import { getSafeEthToken } from '~/logic/tokens/utils/tokenHelpers' import { getSafeEthToken } from '~/logic/tokens/utils/tokenHelpers'
import addTokens from './addTokens' import addTokens from './addTokens'
import { getRelayUrl } from '~/config/index' import { getRelayUrl } from '~/config/index'

View File

@ -12,7 +12,7 @@ type RemoveTokenProps = {
token: Token, token: Token,
} }
export const removeToken = createAction( export const removeToken = createAction<string, *, *>(
REMOVE_TOKEN, REMOVE_TOKEN,
(safeAddress: string, token: Token): RemoveTokenProps => ({ (safeAddress: string, token: Token): RemoveTokenProps => ({
safeAddress, safeAddress,
@ -23,8 +23,7 @@ export const removeToken = createAction(
const deleteToken = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => { const deleteToken = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => {
dispatch(removeToken(safeAddress, token)) dispatch(removeToken(safeAddress, token))
const tokenAddress = token.get('address') await removeFromActiveTokens(safeAddress, token)
await removeFromActiveTokens(safeAddress, tokenAddress)
await removeTokenFromStorage(safeAddress, token) await removeTokenFromStorage(safeAddress, token)
} }