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

View File

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

View File

@ -7,16 +7,15 @@ import { removeFromActiveTokens } from '~/logic/tokens/utils/tokensStorage'
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,
tokenAddress,
token,
}))
const hideToken = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => {
const { address } = token
dispatch(disableToken(safeAddress, address))
dispatch(disableToken(safeAddress, token))
await removeFromActiveTokens(safeAddress, address)
await removeFromActiveTokens(safeAddress, token)
}
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 enableToken = createAction(ENABLE_TOKEN, (safeAddress: string, tokenAddress: string) => ({
export const enableToken = createAction<string, *, *>(ENABLE_TOKEN, (safeAddress: string, token: Token) => ({
safeAddress,
tokenAddress,
token,
}))
const setTokenEnabled = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => {
const { address } = token
dispatch(enableToken(safeAddress, address))
dispatch(enableToken(safeAddress, token))
const activeTokens = await getActiveTokens(safeAddress)
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 { makeToken, type Token, type TokenProps } from '~/logic/tokens/store/model/token'
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 addTokens from './addTokens'
import { getRelayUrl } from '~/config/index'

View File

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