Browse Source

Fix hashCache for TransactionsList, fix sync issue

master
Loëck Vézien 7 years ago
parent
commit
cd47c64f9b
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 12
      src/components/TransactionsList/index.js
  2. 10
      src/helpers/btc.js
  3. 6
      src/reducers/accounts.js
  4. 10
      src/renderer/events.js

12
src/components/TransactionsList/index.js

@ -124,23 +124,23 @@ class TransactionsList extends Component<Props> {
withAccounts: false, withAccounts: false,
} }
componentWillReceiveProps(nextProps: Props) { shouldComponentUpdate(nextProps: Props) {
if (nextProps.transactions !== this.props.transactions) { if (this._hashCache === null) {
this._hashCache = this.getHashCache(nextProps.transactions) return true
} }
}
shouldComponentUpdate(nextProps: Props) {
return !isEqual(this._hashCache, this.getHashCache(nextProps.transactions)) return !isEqual(this._hashCache, this.getHashCache(nextProps.transactions))
} }
getHashCache = (transactions: Array<TransactionType>) => transactions.map(t => t.hash) getHashCache = (transactions: Array<TransactionType>) => transactions.map(t => t.hash)
_hashCache = this.getHashCache(this.props.transactions) _hashCache = null
render() { render() {
const { transactions, withAccounts } = this.props const { transactions, withAccounts } = this.props
this._hashCache = this.getHashCache(transactions)
return ( return (
<Box flow={1}> <Box flow={1}>
<Box horizontal pt={4}> <Box horizontal pt={4}>

10
src/helpers/btc.js

@ -130,11 +130,13 @@ export async function getAccount({
return nextPath(index + (gapLimit - 1)) return nextPath(index + (gapLimit - 1))
} }
const balance = transactions.reduce((result, v) => {
result += v.balance
return result
}, 0)
return { return {
balance: transactions.reduce((result, v) => { balance,
result += v.balance
return result
}, 0),
allAddresses, allAddresses,
transactions, transactions,
...(lastAddress !== null ...(lastAddress !== null

6
src/reducers/accounts.js

@ -5,7 +5,6 @@ import { handleActions } from 'redux-actions'
import every from 'lodash/every' import every from 'lodash/every'
import get from 'lodash/get' import get from 'lodash/get'
import reduce from 'lodash/reduce' import reduce from 'lodash/reduce'
import uniqBy from 'lodash/uniqBy'
import type { State } from 'reducers' import type { State } from 'reducers'
import type { Account, Accounts, AccountData } from 'types/common' import type { Account, Accounts, AccountData } from 'types/common'
@ -65,10 +64,7 @@ const handlers: Object = {
const existingData = get(existingAccount, 'data', {}) const existingData = get(existingAccount, 'data', {})
const data = get(account, 'data', {}) const data = get(account, 'data', {})
const transactions = uniqBy( const transactions = get(data, 'transactions', [])
[...get(existingData, 'transactions', []), ...get(data, 'transactions', [])],
tx => tx.hash,
)
const currentIndex = data.currentIndex const currentIndex = data.currentIndex
? data.currentIndex ? data.currentIndex

10
src/renderer/events.js

@ -83,7 +83,15 @@ export default ({ store, locked }: { store: Object, locked: boolean }) => {
) )
if (currentAccountTransactions.length !== transactions.length) { if (currentAccountTransactions.length !== transactions.length) {
store.dispatch(updateAccount(account)) store.dispatch(
updateAccount({
...account,
data: {
...account.data,
transactions,
},
}),
)
} }
} }
}, },

Loading…
Cancel
Save