Merge pull request #167 from gnosis/bug/balances-not-updated-automatically
BUG: Ether balance is not updated automatically
This commit is contained in:
commit
ea253e8055
|
@ -1,6 +1,7 @@
|
||||||
// @flow
|
// @flow
|
||||||
import fetchSafe from '~/routes/safe/store/actions/fetchSafe'
|
import fetchSafe from '~/routes/safe/store/actions/fetchSafe'
|
||||||
import fetchTokenBalances from '~/routes/safe/store/actions/fetchTokenBalances'
|
import fetchTokenBalances from '~/routes/safe/store/actions/fetchTokenBalances'
|
||||||
|
import fetchEtherBalance from '~/routes/safe/store/actions/fetchEtherBalance'
|
||||||
import createTransaction from '~/routes/safe/store/actions/createTransaction'
|
import createTransaction from '~/routes/safe/store/actions/createTransaction'
|
||||||
import processTransaction from '~/routes/safe/store/actions/processTransaction'
|
import processTransaction from '~/routes/safe/store/actions/processTransaction'
|
||||||
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
|
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
|
||||||
|
@ -15,6 +16,7 @@ export type Actions = {
|
||||||
updateSafe: typeof updateSafe,
|
updateSafe: typeof updateSafe,
|
||||||
fetchTokens: typeof fetchTokens,
|
fetchTokens: typeof fetchTokens,
|
||||||
processTransaction: typeof processTransaction,
|
processTransaction: typeof processTransaction,
|
||||||
|
fetchEtherBalance: typeof fetchEtherBalance,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -25,4 +27,5 @@ export default {
|
||||||
fetchTokens,
|
fetchTokens,
|
||||||
fetchTransactions,
|
fetchTransactions,
|
||||||
updateSafe,
|
updateSafe,
|
||||||
|
fetchEtherBalance,
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ class SafeView extends React.Component<Props> {
|
||||||
|
|
||||||
fetchSafe(safeUrl)
|
fetchSafe(safeUrl)
|
||||||
fetchTokenBalances(safeUrl, activeTokens)
|
fetchTokenBalances(safeUrl, activeTokens)
|
||||||
|
|
||||||
// fetch tokens there to get symbols for tokens in TXs list
|
// fetch tokens there to get symbols for tokens in TXs list
|
||||||
fetchTokens()
|
fetchTokens()
|
||||||
|
|
||||||
|
@ -46,10 +47,11 @@ class SafeView extends React.Component<Props> {
|
||||||
|
|
||||||
checkForUpdates() {
|
checkForUpdates() {
|
||||||
const {
|
const {
|
||||||
safeUrl, activeTokens, fetchTokenBalances,
|
safeUrl, activeTokens, fetchTokenBalances, fetchEtherBalance,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
fetchTokenBalances(safeUrl, activeTokens)
|
fetchTokenBalances(safeUrl, activeTokens)
|
||||||
|
fetchEtherBalance(safeUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
// @flow
|
||||||
|
import type { Dispatch as ReduxDispatch } from 'redux'
|
||||||
|
import { type GlobalState } from '~/store/index'
|
||||||
|
import updateSafe from '~/routes/safe/store/actions/updateSafe'
|
||||||
|
import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
|
||||||
|
|
||||||
|
const fetchEtherBalance = (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => {
|
||||||
|
try {
|
||||||
|
const ethBalance = await getBalanceInEtherOf(safeAddress)
|
||||||
|
|
||||||
|
dispatch(updateSafe({ address: safeAddress, ethBalance }))
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.error('Error when fetching Ether balance:', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default fetchEtherBalance
|
|
@ -45,7 +45,7 @@ const fetchTokenBalances = (safeAddress: string, tokens: List<Token>) => async (
|
||||||
dispatch(updateSafe({ address: safeAddress, balances: List(withBalances) }))
|
dispatch(updateSafe({ address: safeAddress, balances: List(withBalances) }))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.error('Error while loading active tokens from storage:', err)
|
console.error('Error when fetching token balances:', err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue