From d7193dcc9a52e9d172173b15de68160c10973057 Mon Sep 17 00:00:00 2001 From: apanizo Date: Fri, 6 Jul 2018 11:06:32 +0200 Subject: [PATCH] WA-232 Do not update redux if error is raised fetching balance or safe information --- src/routes/safe/store/actions/fetchBalances.js | 18 +++++++++++++----- src/routes/safe/store/actions/fetchSafe.js | 11 +++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/routes/safe/store/actions/fetchBalances.js b/src/routes/safe/store/actions/fetchBalances.js index d833b9c4..764b8eb3 100644 --- a/src/routes/safe/store/actions/fetchBalances.js +++ b/src/routes/safe/store/actions/fetchBalances.js @@ -55,15 +55,23 @@ export const fetchBalances = (safeAddress: string) => async (dispatch: ReduxDisp } const json = await response.json() - return Promise.all(json.map(async (item: BalanceProps) => { - const funds = await calculateBalanceOf(item.address, safeAddress, item.decimals) - return makeBalance({ ...item, funds }) - })).then((balancesRecords) => { + + try { + const balancesRecords = await Promise.all(json.map(async (item: BalanceProps) => { + const funds = await calculateBalanceOf(item.address, safeAddress, item.decimals) + return makeBalance({ ...item, funds }) + })) + const balances: Map = Map().withMutations((map) => { balancesRecords.forEach(record => map.set(record.get('symbol'), record)) map.set('ETH', ethBalance) }) return dispatch(addBalances(safeAddress, balances)) - }) + } catch (err) { + // eslint-disable-next-line + console.log("Error fetching token balances...") + + return Promise.resolve() + } } diff --git a/src/routes/safe/store/actions/fetchSafe.js b/src/routes/safe/store/actions/fetchSafe.js index 9e9a48ff..7f41f8b9 100644 --- a/src/routes/safe/store/actions/fetchSafe.js +++ b/src/routes/safe/store/actions/fetchSafe.js @@ -37,7 +37,14 @@ export const buildSafe = async (storedSafe: Object) => { } export default (safe: Safe) => async (dispatch: ReduxDispatch) => { - const safeRecord = await buildSafe(safe.toJSON()) + try { + const safeRecord = await buildSafe(safe.toJSON()) - return dispatch(updateSafe(safeRecord)) + return dispatch(updateSafe(safeRecord)) + } catch (err) { + // eslint-disable-next-line + console.log("Error while updating safe information") + + return Promise.resolve() + } }