From cd47c64f9b49e36493819cef9f1990b111598de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Thu, 15 Feb 2018 09:49:45 +0100 Subject: [PATCH] Fix hashCache for TransactionsList, fix sync issue --- src/components/TransactionsList/index.js | 12 ++++++------ src/helpers/btc.js | 10 ++++++---- src/reducers/accounts.js | 6 +----- src/renderer/events.js | 10 +++++++++- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/components/TransactionsList/index.js b/src/components/TransactionsList/index.js index df1f8057..556bf2bf 100644 --- a/src/components/TransactionsList/index.js +++ b/src/components/TransactionsList/index.js @@ -124,23 +124,23 @@ class TransactionsList extends Component { withAccounts: false, } - componentWillReceiveProps(nextProps: Props) { - if (nextProps.transactions !== this.props.transactions) { - this._hashCache = this.getHashCache(nextProps.transactions) + shouldComponentUpdate(nextProps: Props) { + if (this._hashCache === null) { + return true } - } - shouldComponentUpdate(nextProps: Props) { return !isEqual(this._hashCache, this.getHashCache(nextProps.transactions)) } getHashCache = (transactions: Array) => transactions.map(t => t.hash) - _hashCache = this.getHashCache(this.props.transactions) + _hashCache = null render() { const { transactions, withAccounts } = this.props + this._hashCache = this.getHashCache(transactions) + return ( diff --git a/src/helpers/btc.js b/src/helpers/btc.js index 1c8ef560..e46b3895 100644 --- a/src/helpers/btc.js +++ b/src/helpers/btc.js @@ -130,11 +130,13 @@ export async function getAccount({ return nextPath(index + (gapLimit - 1)) } + const balance = transactions.reduce((result, v) => { + result += v.balance + return result + }, 0) + return { - balance: transactions.reduce((result, v) => { - result += v.balance - return result - }, 0), + balance, allAddresses, transactions, ...(lastAddress !== null diff --git a/src/reducers/accounts.js b/src/reducers/accounts.js index 17465991..7d68daa1 100644 --- a/src/reducers/accounts.js +++ b/src/reducers/accounts.js @@ -5,7 +5,6 @@ import { handleActions } from 'redux-actions' import every from 'lodash/every' import get from 'lodash/get' import reduce from 'lodash/reduce' -import uniqBy from 'lodash/uniqBy' import type { State } from 'reducers' import type { Account, Accounts, AccountData } from 'types/common' @@ -65,10 +64,7 @@ const handlers: Object = { const existingData = get(existingAccount, 'data', {}) const data = get(account, 'data', {}) - const transactions = uniqBy( - [...get(existingData, 'transactions', []), ...get(data, 'transactions', [])], - tx => tx.hash, - ) + const transactions = get(data, 'transactions', []) const currentIndex = data.currentIndex ? data.currentIndex diff --git a/src/renderer/events.js b/src/renderer/events.js index 70e24b4c..fb695bf4 100644 --- a/src/renderer/events.js +++ b/src/renderer/events.js @@ -83,7 +83,15 @@ export default ({ store, locked }: { store: Object, locked: boolean }) => { ) if (currentAccountTransactions.length !== transactions.length) { - store.dispatch(updateAccount(account)) + store.dispatch( + updateAccount({ + ...account, + data: { + ...account.data, + transactions, + }, + }), + ) } } },