From 667fae279d9de3717b74c3ad7a3d4889c053a2e2 Mon Sep 17 00:00:00 2001 From: apanizo Date: Fri, 29 Jun 2018 15:41:29 +0200 Subject: [PATCH] WA-232 Avoid re-renderings when updating safe balances --- src/routes/safe/component/Safe/BalanceInfo.jsx | 6 +----- src/routes/safe/store/reducer/balances.js | 8 +++++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/routes/safe/component/Safe/BalanceInfo.jsx b/src/routes/safe/component/Safe/BalanceInfo.jsx index 94d7087e..db679d89 100644 --- a/src/routes/safe/component/Safe/BalanceInfo.jsx +++ b/src/routes/safe/component/Safe/BalanceInfo.jsx @@ -54,11 +54,7 @@ const BalanceComponent = openHoc(({ {name} - + ) })} diff --git a/src/routes/safe/store/reducer/balances.js b/src/routes/safe/store/reducer/balances.js index a70f1fd2..2bad95d0 100644 --- a/src/routes/safe/store/reducer/balances.js +++ b/src/routes/safe/store/reducer/balances.js @@ -10,5 +10,11 @@ export type State = Map> export default handleActions({ [ADD_BALANCES]: (state: State, action: ActionType): State => - state.set(action.payload.safeAddress, action.payload.balances), + state.update(action.payload.safeAddress, (prevSafe: Map) => { + if (!prevSafe) { + return action.payload.balances + } + + return prevSafe.equals(action.payload.balances) ? prevSafe : action.payload.balances + }), }, Map())