WA-232 Do not update redux if error is raised fetching balance or safe information

This commit is contained in:
apanizo 2018-07-06 11:06:32 +02:00
parent afe7d4fc2f
commit d7193dcc9a
2 changed files with 22 additions and 7 deletions

View File

@ -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<string, Balance> = 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()
}
}

View File

@ -37,7 +37,14 @@ export const buildSafe = async (storedSafe: Object) => {
}
export default (safe: Safe) => async (dispatch: ReduxDispatch<GlobalState>) => {
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()
}
}