token redux-related stuff cleanup after refactor
This commit is contained in:
parent
cdaa6c8223
commit
289f5f6feb
|
@ -1,21 +0,0 @@
|
||||||
// @flow
|
|
||||||
import { createAction } from 'redux-actions'
|
|
||||||
import { type Token } from '~/logic/tokens/store/model/token'
|
|
||||||
import type { Dispatch as ReduxDispatch } from 'redux'
|
|
||||||
import { type GlobalState } from '~/store/index'
|
|
||||||
import { removeFromActiveTokens } from '~/logic/tokens/utils/tokensStorage'
|
|
||||||
|
|
||||||
export const DISABLE_TOKEN = 'DISABLE_TOKEN'
|
|
||||||
|
|
||||||
export const disableToken = createAction<string, *, *>(DISABLE_TOKEN, (safeAddress: string, token: Token) => ({
|
|
||||||
safeAddress,
|
|
||||||
token,
|
|
||||||
}))
|
|
||||||
|
|
||||||
const hideToken = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => {
|
|
||||||
dispatch(disableToken(safeAddress, token))
|
|
||||||
|
|
||||||
await removeFromActiveTokens(safeAddress, token)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default hideToken
|
|
|
@ -1,22 +0,0 @@
|
||||||
// @flow
|
|
||||||
import { createAction } from 'redux-actions'
|
|
||||||
import type { Dispatch as ReduxDispatch } from 'redux'
|
|
||||||
import { type GlobalState } from '~/store/index'
|
|
||||||
import { type Token } from '~/logic/tokens/store/model/token'
|
|
||||||
import { setActiveTokens, getActiveTokens } from '~/logic/tokens/utils/tokensStorage'
|
|
||||||
|
|
||||||
export const ENABLE_TOKEN = 'ENABLE_TOKEN'
|
|
||||||
|
|
||||||
export const enableToken = createAction<string, *, *>(ENABLE_TOKEN, (safeAddress: string, token: Token) => ({
|
|
||||||
safeAddress,
|
|
||||||
token,
|
|
||||||
}))
|
|
||||||
|
|
||||||
const setTokenEnabled = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => {
|
|
||||||
dispatch(enableToken(safeAddress, token))
|
|
||||||
|
|
||||||
const activeTokens = await getActiveTokens(safeAddress)
|
|
||||||
await setActiveTokens(safeAddress, activeTokens.push(token))
|
|
||||||
}
|
|
||||||
|
|
||||||
export default setTokenEnabled
|
|
|
@ -1,5 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { Map } from 'immutable'
|
import { List } from 'immutable'
|
||||||
import contract from 'truffle-contract'
|
import contract from 'truffle-contract'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import type { Dispatch as ReduxDispatch } from 'redux'
|
import type { Dispatch as ReduxDispatch } from 'redux'
|
||||||
|
@ -44,11 +44,9 @@ export const fetchTokens = () => async (dispatch: ReduxDispatch<GlobalState>) =>
|
||||||
data: { results: tokenList },
|
data: { results: tokenList },
|
||||||
} = await fetchTokenList()
|
} = await fetchTokenList()
|
||||||
|
|
||||||
const tokensMap: Map<string, Token> = Map().withMutations((map) => {
|
const tokens = List(tokenList.map((token: TokenProps) => makeToken(token)))
|
||||||
tokenList.forEach((token: TokenProps) => map.set(token.address, makeToken(token)))
|
|
||||||
})
|
|
||||||
|
|
||||||
dispatch(saveTokens(tokensMap))
|
dispatch(saveTokens(tokens))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.log('Error fetching token list ' + err)
|
console.log('Error fetching token list ' + err)
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
// @flow
|
|
||||||
import { createAction } from 'redux-actions'
|
|
||||||
import { type Token } from '~/logic/tokens/store/model/token'
|
|
||||||
import { setActiveTokens, getActiveTokens, setToken } from '~/logic/tokens/utils/tokensStorage'
|
|
||||||
import type { Dispatch as ReduxDispatch } from 'redux'
|
|
||||||
import { type GlobalState } from '~/store/index'
|
|
||||||
|
|
||||||
export const ADD_TOKEN = 'ADD_TOKEN'
|
|
||||||
|
|
||||||
type AddTokenProps = {
|
|
||||||
safeAddress: string,
|
|
||||||
token: Token,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const addToken = createAction<string, *, *>(
|
|
||||||
ADD_TOKEN,
|
|
||||||
(safeAddress: string, token: Token): AddTokenProps => ({
|
|
||||||
safeAddress,
|
|
||||||
token,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
const saveToken = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => {
|
|
||||||
dispatch(addToken(safeAddress, token))
|
|
||||||
|
|
||||||
const activeTokens = await getActiveTokens(safeAddress)
|
|
||||||
await setActiveTokens(safeAddress, activeTokens.push(token.toJS()))
|
|
||||||
setToken(safeAddress, token)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default saveToken
|
|
|
@ -37,7 +37,6 @@ const fetchTokenBalances = (safeAddress: string, tokens: List<Token>) => async (
|
||||||
try {
|
try {
|
||||||
const withBalances = await Promise.all(
|
const withBalances = await Promise.all(
|
||||||
tokens
|
tokens
|
||||||
.filter(token => token.address !== ETH_ADDRESS)
|
|
||||||
.map(async token => TokenBalanceRecord({
|
.map(async token => TokenBalanceRecord({
|
||||||
address: token.address,
|
address: token.address,
|
||||||
balance: await calculateBalanceOf(token.address, safeAddress, token.decimals),
|
balance: await calculateBalanceOf(token.address, safeAddress, token.decimals),
|
||||||
|
|
Loading…
Reference in New Issue