Fix the Address page to count only transactions sent

pull/929/head
Felipe Renan 6 years ago
parent fa5c92e8d6
commit 54de3f985f
  1. 38
      apps/block_scout_web/assets/__tests__/pages/address.js
  2. 14
      apps/block_scout_web/assets/js/pages/address.js

@ -265,11 +265,14 @@ describe('RECEIVED_NEW_PENDING_TRANSACTION_BATCH', () => {
describe('RECEIVED_NEW_TRANSACTION_BATCH', () => {
test('single transaction', () => {
const state = initialState
const state = Object.assign({}, initialState, {
addressHash: '0x111'
})
const action = {
type: 'RECEIVED_NEW_TRANSACTION_BATCH',
msgs: [{
transactionHtml: 'test'
transactionHtml: 'test',
fromAddressHash: '0x111'
}]
}
const output = reducer(state, action)
@ -310,7 +313,6 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => {
expect(output.newTransactions).toEqual([])
expect(output.batchCountAccumulator).toEqual(11)
expect(output.transactionCount).toEqual(11)
})
test('single transaction after single transaction', () => {
const state = Object.assign({}, initialState, {
@ -379,6 +381,28 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => {
expect(output.newTransactions).toEqual([])
expect(output.batchCountAccumulator).toEqual(22)
})
test('increments the transactions count only when the address sent transactions', () => {
const state = Object.assign({}, initialState, {
newTransactions: [],
addressHash: '0x111',
transactionCount: 1
})
const action = {
type: 'RECEIVED_NEW_TRANSACTION_BATCH',
msgs: [{
transactionHtml: 'test 12',
fromAddressHash: '0x111',
toAddressHash: '0x222'
},{
transactionHtml: 'test 13',
fromAddressHash: '0x222',
toAddressHash: '0x111'
}]
}
const output = reducer(state, action)
expect(output.transactionCount).toEqual(2)
})
test('after disconnection', () => {
const state = Object.assign({}, initialState, {
channelDisconnected: true
@ -397,12 +421,14 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => {
test('on page 2', () => {
const state = Object.assign({}, initialState, {
beyondPageOne: true,
transactionCount: 1
transactionCount: 1,
addressHash: '0x111'
})
const action = {
type: 'RECEIVED_NEW_TRANSACTION_BATCH',
msgs: [{
transactionHtml: 'test'
transactionHtml: 'test',
fromAddressHash: '0x111'
}]
}
const output = reducer(state, action)
@ -488,7 +514,6 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => {
expect(output.newTransactions).toEqual(['test'])
expect(output.batchCountAccumulator).toEqual(0)
expect(output.transactionCount).toEqual(1)
})
test('large batch of transactions', () => {
const state = initialState
@ -532,6 +557,5 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => {
const output = reducer(state, action)
expect(output.newTransactions).toEqual([])
expect(output.transactionCount).toEqual(11)
})
})

@ -11,6 +11,18 @@ import { loadTokenBalanceDropdown } from '../lib/token_balance_dropdown'
const BATCH_THRESHOLD = 10
const incrementTransactionsCount = (transactions, addressHash, currentValue) => {
const reducer = (accumulator, {fromAddressHash}) => {
if (fromAddressHash === addressHash) {
accumulator++
}
return accumulator
}
return transactions.reduce(reducer, currentValue)
}
export const initialState = {
addressHash: null,
balance: null,
@ -109,7 +121,7 @@ export function reducer (state = initialState, action) {
case 'RECEIVED_NEW_TRANSACTION_BATCH': {
if (state.channelDisconnected) return state
const transactionCount = state.transactionCount + action.msgs.length
const transactionCount = incrementTransactionsCount(action.msgs, state.addressHash, state.transactionCount)
if (state.beyondPageOne) return Object.assign({}, state, { transactionCount })

Loading…
Cancel
Save