action for fetching active token balances wip
This commit is contained in:
parent
8108b6bd01
commit
8a8b29744a
|
@ -1,10 +1,11 @@
|
||||||
// @flow
|
// @flow
|
||||||
import type { Dispatch as ReduxDispatch } from 'redux'
|
import type { Dispatch as ReduxDispatch, GetState } from 'redux'
|
||||||
import { Map, List } from 'immutable'
|
import { Map, List } from 'immutable'
|
||||||
import { type Token } from '~/logic/tokens/store/model/token'
|
import { type Token } from '~/logic/tokens/store/model/token'
|
||||||
import { type GlobalState } from '~/store/index'
|
import { type GlobalState } from '~/store/index'
|
||||||
import { calculateBalanceOf } from './fetchTokens'
|
import { calculateBalanceOf } from './fetchTokens'
|
||||||
import { addTokens } from './saveTokens'
|
import { addTokens } from './saveTokens'
|
||||||
|
import { activeTokensSelector } from '~/logic/tokens/store/selectors'
|
||||||
|
|
||||||
const fetchTokenBalances = (safeAddress: string, tokens: List<Token>) => async (
|
const fetchTokenBalances = (safeAddress: string, tokens: List<Token>) => async (
|
||||||
dispatch: ReduxDispatch<GlobalState>,
|
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
|
export default fetchTokenBalances
|
||||||
|
|
|
@ -35,18 +35,17 @@ class SafeView extends React.PureComponent<Props> {
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
const {
|
const {
|
||||||
safe, fetchTokenBalances, loadActiveTokens, activeTokens,
|
fetchTokenBalances, loadActiveTokens, activeTokens, safeUrl,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
if (prevProps.safe) {
|
if (prevProps.safe) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (safe) {
|
if (safeUrl) {
|
||||||
const safeAddress = safe.get('address')
|
loadActiveTokens(safeUrl)
|
||||||
loadActiveTokens(safeAddress)
|
|
||||||
if (activeTokens.size) {
|
if (activeTokens.size) {
|
||||||
fetchTokenBalances(safeAddress, activeTokens)
|
fetchTokenBalances(safeUrl, activeTokens)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue