From f8db1e1e9acec327dbc9a6a6804d8aea1af3c466 Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Tue, 10 Sep 2019 15:25:07 +0400 Subject: [PATCH] create an action to fetch ether balance, add it to checkForUpdates func in safe container --- src/routes/safe/container/actions.js | 3 +++ src/routes/safe/container/index.jsx | 4 +++- .../safe/store/actions/fetchEtherBalance.js | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/routes/safe/store/actions/fetchEtherBalance.js diff --git a/src/routes/safe/container/actions.js b/src/routes/safe/container/actions.js index a51fb28e..2dc0c895 100644 --- a/src/routes/safe/container/actions.js +++ b/src/routes/safe/container/actions.js @@ -1,6 +1,7 @@ // @flow import fetchSafe from '~/routes/safe/store/actions/fetchSafe' 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 processTransaction from '~/routes/safe/store/actions/processTransaction' import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions' @@ -15,6 +16,7 @@ export type Actions = { updateSafe: typeof updateSafe, fetchTokens: typeof fetchTokens, processTransaction: typeof processTransaction, + fetchEtherBalance: typeof fetchEtherBalance, } export default { @@ -25,4 +27,5 @@ export default { fetchTokens, fetchTransactions, updateSafe, + fetchEtherBalance, } diff --git a/src/routes/safe/container/index.jsx b/src/routes/safe/container/index.jsx index 322c1e1b..e6d0f2d3 100644 --- a/src/routes/safe/container/index.jsx +++ b/src/routes/safe/container/index.jsx @@ -23,6 +23,7 @@ class SafeView extends React.Component { fetchSafe(safeUrl) fetchTokenBalances(safeUrl, activeTokens) + // fetch tokens there to get symbols for tokens in TXs list fetchTokens() @@ -46,10 +47,11 @@ class SafeView extends React.Component { checkForUpdates() { const { - safeUrl, activeTokens, fetchTokenBalances, + safeUrl, activeTokens, fetchTokenBalances, fetchEtherBalance, } = this.props fetchTokenBalances(safeUrl, activeTokens) + fetchEtherBalance(safeUrl) } render() { diff --git a/src/routes/safe/store/actions/fetchEtherBalance.js b/src/routes/safe/store/actions/fetchEtherBalance.js new file mode 100644 index 00000000..23f32b44 --- /dev/null +++ b/src/routes/safe/store/actions/fetchEtherBalance.js @@ -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) => { + try { + const ethBalance = await getBalanceInEtherOf(safeAddress) + + dispatch(updateSafe({ address: safeAddress, ethBalance })) + } catch (err) { + // eslint-disable-next-line + console.error('Error while loading active tokens from storage:', err) + } +} + +export default fetchEtherBalance