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,
}
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<TransactionType>) => 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 (
<Box flow={1}>
<Box horizontal pt={4}>

10
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

6
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

10
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,
},
}),
)
}
}
},

Loading…
Cancel
Save