action for fetching active token balances wip

This commit is contained in:
Mikhail Mikheev 2019-04-09 12:48:17 +04:00
parent 8108b6bd01
commit 8a8b29744a
2 changed files with 20 additions and 6 deletions

View File

@ -1,10 +1,11 @@
// @flow
import type { Dispatch as ReduxDispatch } from 'redux'
import type { Dispatch as ReduxDispatch, GetState } from 'redux'
import { Map, List } from 'immutable'
import { type Token } from '~/logic/tokens/store/model/token'
import { type GlobalState } from '~/store/index'
import { calculateBalanceOf } from './fetchTokens'
import { addTokens } from './saveTokens'
import { activeTokensSelector } from '~/logic/tokens/store/selectors'
const fetchTokenBalances = (safeAddress: string, tokens: List<Token>) => async (
dispatch: ReduxDispatch<GlobalState>,
@ -24,4 +25,18 @@ const fetchTokenBalances = (safeAddress: string, tokens: List<Token>) => async (
}
}
export const fetchActiveTokenBalances = (safeAddress: string) => async (
dispatch: ReduxDispatch<GlobalState>,
getState: GetState<GlobalState>,
) => {
try {
const state = getState()
const activeTokens = activeTokensSelector(state)
dispatch(fetchTokenBalances(safeAddress, activeTokens))
} catch (err) {
// eslint-disable-next-line
console.error('Error while loading active tokens from storage:', err)
}
}
export default fetchTokenBalances

View File

@ -35,18 +35,17 @@ class SafeView extends React.PureComponent<Props> {
componentDidUpdate(prevProps) {
const {
safe, fetchTokenBalances, loadActiveTokens, activeTokens,
fetchTokenBalances, loadActiveTokens, activeTokens, safeUrl,
} = this.props
if (prevProps.safe) {
return
}
if (safe) {
const safeAddress = safe.get('address')
loadActiveTokens(safeAddress)
if (safeUrl) {
loadActiveTokens(safeUrl)
if (activeTokens.size) {
fetchTokenBalances(safeAddress, activeTokens)
fetchTokenBalances(safeUrl, activeTokens)
}
}
}