From 6433ddd78221b8de1bfee88c55c7d7d1e56d0bc2 Mon Sep 17 00:00:00 2001 From: jimmay5469 Date: Mon, 15 Oct 2018 15:08:22 -0400 Subject: [PATCH] Stop channel batching in most places unless absolutely necessary --- .../assets/__tests__/pages/address.js | 362 +++--------------- .../assets/__tests__/pages/chain.js | 102 +---- .../assets/js/pages/address.js | 111 ++---- apps/block_scout_web/assets/js/pages/chain.js | 40 +- .../address_transaction/index.html.eex | 10 - .../templates/chain/show.html.eex | 5 - 6 files changed, 97 insertions(+), 533 deletions(-) diff --git a/apps/block_scout_web/assets/__tests__/pages/address.js b/apps/block_scout_web/assets/__tests__/pages/address.js index eff9da2fc0..cf1a24e1f7 100644 --- a/apps/block_scout_web/assets/__tests__/pages/address.js +++ b/apps/block_scout_web/assets/__tests__/pages/address.js @@ -69,7 +69,6 @@ test('CHANNEL_DISCONNECTED', () => { const output = reducer(state, action) expect(output.channelDisconnected).toBe(true) - expect(output.batchCountAccumulator).toBe(0) }) test('RECEIVED_UPDATED_BALANCE', () => { @@ -85,68 +84,19 @@ test('RECEIVED_UPDATED_BALANCE', () => { expect(output.balance).toBe('hello world') }) -describe('RECEIVED_NEW_PENDING_TRANSACTION_BATCH', () => { +describe('RECEIVED_NEW_PENDING_TRANSACTION', () => { test('single transaction', () => { const state = initialState const action = { - type: 'RECEIVED_NEW_PENDING_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_PENDING_TRANSACTION', + msg: { transactionHash: '0x00', transactionHtml: 'test' - }] + } } const output = reducer(state, action) expect(output.newPendingTransactions).toEqual(['test']) - expect(output.batchCountAccumulator).toEqual(0) - expect(output.transactionCount).toEqual(null) - }) - test('large batch of transactions', () => { - const state = initialState - const action = { - type: 'RECEIVED_NEW_PENDING_TRANSACTION_BATCH', - msgs: [{ - transactionHash: '0x01', - transactionHtml: 'test 1' - },{ - transactionHash: '0x02', - transactionHtml: 'test 2' - },{ - transactionHash: '0x03', - transactionHtml: 'test 3' - },{ - transactionHash: '0x04', - transactionHtml: 'test 4' - },{ - transactionHash: '0x05', - transactionHtml: 'test 5' - },{ - transactionHash: '0x06', - transactionHtml: 'test 6' - },{ - transactionHash: '0x07', - transactionHtml: 'test 7' - },{ - transactionHash: '0x08', - transactionHtml: 'test 8' - },{ - transactionHash: '0x09', - transactionHtml: 'test 9' - },{ - transactionHash: '0x10', - transactionHtml: 'test 10' - },{ - transactionHash: '0x11', - transactionHtml: 'test 11' - }] - } - const output = reducer(state, action) - - expect(output.newPendingTransactions).toEqual([]) - expect(output.pendingTransactionHashes).toEqual([ - "0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08", "0x09", "0x10", "0x11" - ]) - expect(output.batchCountAccumulator).toEqual(0) expect(output.transactionCount).toEqual(null) }) test('single transaction after single transaction', () => { @@ -154,94 +104,27 @@ describe('RECEIVED_NEW_PENDING_TRANSACTION_BATCH', () => { newPendingTransactions: ['test 1'] }) const action = { - type: 'RECEIVED_NEW_PENDING_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_PENDING_TRANSACTION', + msg: { transactionHash: '0x02', transactionHtml: 'test 2' - }] + } } const output = reducer(state, action) expect(output.newPendingTransactions).toEqual(['test 1', 'test 2']) expect(output.pendingTransactionHashes.length).toEqual(0) }) - test('single transaction after large batch of transactions', () => { - const state = Object.assign({}, initialState, { - pendingTransactionHashes: [ - "0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08", "0x09", "0x10", "0x11" - ] - }) - const action = { - type: 'RECEIVED_NEW_PENDING_TRANSACTION_BATCH', - msgs: [{ - transactionHash: '0x12', - transactionHtml: 'test 12' - }] - } - const output = reducer(state, action) - - expect(output.newPendingTransactions).toEqual([]) - expect(output.pendingTransactionHashes.length).toEqual(12) - expect(output.pendingTransactionHashes).toContain('0x12') - }) - test('large batch of transactions after large batch of transactions', () => { - const state = Object.assign({}, initialState, { - pendingTransactionHashes: [ - "0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08", "0x09", "0x10", "0x11" - ] - }) - const action = { - type: 'RECEIVED_NEW_PENDING_TRANSACTION_BATCH', - msgs: [{ - transactionHash: '0x12', - transactionHtml: 'test 12' - },{ - transactionHash: '0x13', - transactionHtml: 'test 13' - },{ - transactionHash: '0x14', - transactionHtml: 'test 14' - },{ - transactionHash: '0x15', - transactionHtml: 'test 15' - },{ - transactionHash: '0x16', - transactionHtml: 'test 16' - },{ - transactionHash: '0x17', - transactionHtml: 'test 17' - },{ - transactionHash: '0x18', - transactionHtml: 'test 18' - },{ - transactionHash: '0x19', - transactionHtml: 'test 19' - },{ - transactionHash: '0x20', - transactionHtml: 'test 20' - },{ - transactionHash: '0x21', - transactionHtml: 'test 21' - },{ - transactionHash: '0x22', - transactionHtml: 'test 22' - }] - } - const output = reducer(state, action) - - expect(output.newPendingTransactions).toEqual([]) - expect(output.pendingTransactionHashes.length).toEqual(22) - }) test('after disconnection', () => { const state = Object.assign({}, initialState, { channelDisconnected: true }) const action = { - type: 'RECEIVED_NEW_PENDING_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_PENDING_TRANSACTION', + msg: { transactionHash: '0x00', transactionHtml: 'test' - }] + } } const output = reducer(state, action) @@ -253,174 +136,62 @@ describe('RECEIVED_NEW_PENDING_TRANSACTION_BATCH', () => { beyondPageOne: true }) const action = { - type: 'RECEIVED_NEW_PENDING_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_PENDING_TRANSACTION', + msg: { transactionHash: '0x00', transactionHtml: 'test' - }] + } } const output = reducer(state, action) expect(output.newPendingTransactions).toEqual([]) expect(output.pendingTransactionHashes).toEqual([]) - expect(output.batchCountAccumulator).toEqual(0) }) }) -describe('RECEIVED_NEW_TRANSACTION_BATCH', () => { +describe('RECEIVED_NEW_TRANSACTION', () => { test('single transaction', () => { const state = Object.assign({}, initialState, { addressHash: '0x111' }) const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ - transactionHtml: 'test', - fromAddressHash: '0x111' - }] + type: 'RECEIVED_NEW_TRANSACTION', + msg: { + transactionHtml: 'test' + } } const output = reducer(state, action) expect(output.newTransactions).toEqual(['test']) - expect(output.batchCountAccumulator).toEqual(0) expect(output.transactionCount).toEqual(1) }) - test('large batch of transactions', () => { - const state = initialState - const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ - transactionHtml: 'test 1' - },{ - transactionHtml: 'test 2' - },{ - transactionHtml: 'test 3' - },{ - transactionHtml: 'test 4' - },{ - transactionHtml: 'test 5' - },{ - transactionHtml: 'test 6' - },{ - transactionHtml: 'test 7' - },{ - transactionHtml: 'test 8' - },{ - transactionHtml: 'test 9' - },{ - transactionHtml: 'test 10' - },{ - transactionHtml: 'test 11' - }] - } - const output = reducer(state, action) - - expect(output.newTransactions).toEqual([]) - expect(output.batchCountAccumulator).toEqual(11) - }) test('single transaction after single transaction', () => { const state = Object.assign({}, initialState, { newTransactions: ['test 1'] }) const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_TRANSACTION', + msg: { transactionHtml: 'test 2' - }] + } } const output = reducer(state, action) expect(output.newTransactions).toEqual(['test 1', 'test 2']) - expect(output.batchCountAccumulator).toEqual(0) - }) - test('single transaction after large batch of transactions', () => { - const state = Object.assign({}, initialState, { - newTransactions: [], - batchCountAccumulator: 11 - }) - const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ - transactionHtml: 'test 12' - }] - } - const output = reducer(state, action) - - expect(output.newTransactions).toEqual([]) - expect(output.batchCountAccumulator).toEqual(12) - }) - test('large batch of transactions after large batch of transactions', () => { - const state = Object.assign({}, initialState, { - newTransactions: [], - batchCountAccumulator: 11 - }) - const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ - transactionHtml: 'test 12' - },{ - transactionHtml: 'test 13' - },{ - transactionHtml: 'test 14' - },{ - transactionHtml: 'test 15' - },{ - transactionHtml: 'test 16' - },{ - transactionHtml: 'test 17' - },{ - transactionHtml: 'test 18' - },{ - transactionHtml: 'test 19' - },{ - transactionHtml: 'test 20' - },{ - transactionHtml: 'test 21' - },{ - transactionHtml: 'test 22' - }] - } - const output = reducer(state, action) - - 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 }) const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_TRANSACTION', + msg: { transactionHtml: 'test' - }] + } } const output = reducer(state, action) expect(output.newTransactions).toEqual([]) - expect(output.batchCountAccumulator).toEqual(0) }) test('on page 2', () => { const state = Object.assign({}, initialState, { @@ -429,16 +200,14 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => { addressHash: '0x111' }) const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ - transactionHtml: 'test', - fromAddressHash: '0x111' - }] + type: 'RECEIVED_NEW_TRANSACTION', + msg: { + transactionHtml: 'test' + } } const output = reducer(state, action) expect(output.newTransactions).toEqual([]) - expect(output.batchCountAccumulator).toEqual(0) expect(output.transactionCount).toEqual(2) }) test('transaction from current address with "from" filter', () => { @@ -447,11 +216,11 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => { filter: 'from' }) const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_TRANSACTION', + msg: { fromAddressHash: '1234', transactionHtml: 'test' - }] + } } const output = reducer(state, action) @@ -463,11 +232,11 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => { filter: 'to' }) const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_TRANSACTION', + msg: { fromAddressHash: '1234', transactionHtml: 'test' - }] + } } const output = reducer(state, action) @@ -479,11 +248,11 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => { filter: 'to' }) const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_TRANSACTION', + msg: { toAddressHash: '1234', transactionHtml: 'test' - }] + } } const output = reducer(state, action) @@ -495,11 +264,11 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => { filter: 'from' }) const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_TRANSACTION', + msg: { toAddressHash: '1234', transactionHtml: 'test' - }] + } } const output = reducer(state, action) @@ -508,58 +277,15 @@ describe('RECEIVED_NEW_TRANSACTION_BATCH', () => { test('single transaction collated from pending', () => { const state = initialState const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_TRANSACTION', + msg: { transactionHash: '0x00', transactionHtml: 'test' - }] + } } const output = reducer(state, action) expect(output.newTransactions).toEqual(['test']) - expect(output.batchCountAccumulator).toEqual(0) - }) - test('large batch of transactions', () => { - const state = initialState - const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ - transactionHash: '0x01', - transactionHtml: 'test 1' - },{ - transactionHash: '0x02', - transactionHtml: 'test 2' - },{ - transactionHash: '0x03', - transactionHtml: 'test 3' - },{ - transactionHash: '0x04', - transactionHtml: 'test 4' - },{ - transactionHash: '0x05', - transactionHtml: 'test 5' - },{ - transactionHash: '0x06', - transactionHtml: 'test 6' - },{ - transactionHash: '0x07', - transactionHtml: 'test 7' - },{ - transactionHash: '0x08', - transactionHtml: 'test 8' - },{ - transactionHash: '0x09', - transactionHtml: 'test 9' - },{ - transactionHash: '0x10', - transactionHtml: 'test 10' - },{ - transactionHash: '0x11', - transactionHtml: 'test 11' - }] - } - const output = reducer(state, action) - - expect(output.newTransactions).toEqual([]) + expect(output.transactionCount).toEqual(1) }) }) diff --git a/apps/block_scout_web/assets/__tests__/pages/chain.js b/apps/block_scout_web/assets/__tests__/pages/chain.js index 4f0cde7106..9ff632f2d4 100644 --- a/apps/block_scout_web/assets/__tests__/pages/chain.js +++ b/apps/block_scout_web/assets/__tests__/pages/chain.js @@ -195,120 +195,32 @@ test('RECEIVED_NEW_EXCHANGE_RATE', () => { expect(output.usdMarketCap).toEqual(1230000) }) -describe('RECEIVED_NEW_TRANSACTION_BATCH', () => { +describe('RECEIVED_NEW_TRANSACTION', () => { test('single transaction', () => { const state = initialState const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_TRANSACTION', + msg: { transactionHtml: 'test' - }] + } } const output = reducer(state, action) expect(output.newTransactions).toEqual(['test']) - expect(output.batchCountAccumulator).toEqual(0) expect(output.transactionCount).toEqual(1) }) - test('large batch of transactions', () => { - const state = initialState - const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ - transactionHtml: 'test 1' - },{ - transactionHtml: 'test 2' - },{ - transactionHtml: 'test 3' - },{ - transactionHtml: 'test 4' - },{ - transactionHtml: 'test 5' - },{ - transactionHtml: 'test 6' - },{ - transactionHtml: 'test 7' - },{ - transactionHtml: 'test 8' - },{ - transactionHtml: 'test 9' - },{ - transactionHtml: 'test 10' - },{ - transactionHtml: 'test 11' - }] - } - const output = reducer(state, action) - - 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, { newTransactions: ['test 1'] }) const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ + type: 'RECEIVED_NEW_TRANSACTION', + msg: { transactionHtml: 'test 2' - }] + } } const output = reducer(state, action) expect(output.newTransactions).toEqual(['test 1', 'test 2']) - expect(output.batchCountAccumulator).toEqual(0) - }) - test('single transaction after large batch of transactions', () => { - const state = Object.assign({}, initialState, { - newTransactions: [], - batchCountAccumulator: 11 - }) - const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ - transactionHtml: 'test 12' - }] - } - const output = reducer(state, action) - - expect(output.newTransactions).toEqual([]) - expect(output.batchCountAccumulator).toEqual(12) - }) - test('large batch of transactions after large batch of transactions', () => { - const state = Object.assign({}, initialState, { - newTransactions: [], - batchCountAccumulator: 11 - }) - const action = { - type: 'RECEIVED_NEW_TRANSACTION_BATCH', - msgs: [{ - transactionHtml: 'test 12' - },{ - transactionHtml: 'test 13' - },{ - transactionHtml: 'test 14' - },{ - transactionHtml: 'test 15' - },{ - transactionHtml: 'test 16' - },{ - transactionHtml: 'test 17' - },{ - transactionHtml: 'test 18' - },{ - transactionHtml: 'test 19' - },{ - transactionHtml: 'test 20' - },{ - transactionHtml: 'test 21' - },{ - transactionHtml: 'test 22' - }] - } - const output = reducer(state, action) - - expect(output.newTransactions).toEqual([]) - expect(output.batchCountAccumulator).toEqual(22) }) }) diff --git a/apps/block_scout_web/assets/js/pages/address.js b/apps/block_scout_web/assets/js/pages/address.js index e9ba5f2533..5be64da4a4 100644 --- a/apps/block_scout_web/assets/js/pages/address.js +++ b/apps/block_scout_web/assets/js/pages/address.js @@ -34,7 +34,7 @@ export const initialState = { newInternalTransactions: [], newPendingTransactions: [], newTransactions: [], - newTransactionHashes: [], + newTransactionHash: null, pendingTransactionHashes: [], transactionCount: null, validationCount: null @@ -94,66 +94,44 @@ export function reducer (state = initialState, action) { }) } } - case 'RECEIVED_NEW_PENDING_TRANSACTION_BATCH': { + case 'RECEIVED_NEW_PENDING_TRANSACTION': { if (state.channelDisconnected || state.beyondPageOne) return state - const incomingPendingTransactions = action.msgs - .filter(({toAddressHash, fromAddressHash}) => ( - !state.filter || - (state.filter === 'to' && toAddressHash === state.addressHash) || - (state.filter === 'from' && fromAddressHash === state.addressHash) - )) - if (!state.pendingTransactionHashes.length && incomingPendingTransactions.length < BATCH_THRESHOLD) { - return Object.assign({}, state, { - newPendingTransactions: [ - ...state.newPendingTransactions, - ..._.map(incomingPendingTransactions, 'transactionHtml') - ] - }) - } else { - return Object.assign({}, state, { - pendingTransactionHashes: [ - ...state.pendingTransactionHashes, - ..._.map(incomingPendingTransactions, 'transactionHash') - ] - }) + if ((state.filter === 'to' && action.msg.toAddressHash !== state.addressHash) || + (state.filter === 'from' && action.msg.fromAddressHash !== state.addressHash)) { + return state } + + return Object.assign({}, state, { + newPendingTransactions: [ + ...state.newPendingTransactions, + action.msg.transactionHtml + ] + }) } - case 'RECEIVED_NEW_TRANSACTION_BATCH': { + case 'RECEIVED_NEW_TRANSACTION': { if (state.channelDisconnected) return state - const transactionCount = incrementTransactionsCount(action.msgs, state.addressHash, state.transactionCount) - - if (state.beyondPageOne) return Object.assign({}, state, { transactionCount }) + const transactionCount = state.transactionCount + 1 - const incomingTransactions = action.msgs - .filter(({toAddressHash, fromAddressHash}) => ( - !state.filter || - (state.filter === 'to' && toAddressHash === state.addressHash) || - (state.filter === 'from' && fromAddressHash === state.addressHash) - )) + if (state.beyondPageOne || + (state.filter === 'to' && action.msg.toAddressHash !== state.addressHash) || + (state.filter === 'from' && action.msg.fromAddressHash !== state.addressHash)) { + return Object.assign({}, state, { transactionCount }) + } const updatedPendingTransactionHashes = - _.difference(state.pendingTransactionHashes, _.map(incomingTransactions, 'transactionHash')) + _.without(state.pendingTransactionHashes, action.msg.transactionHash) - if (!state.batchCountAccumulator && incomingTransactions.length < BATCH_THRESHOLD) { - return Object.assign({}, state, { - newTransactions: [ - ...state.newTransactions, - ..._.map(incomingTransactions, 'transactionHtml') - ], - newTransactionHashes: _.map(incomingTransactions, 'transactionHash'), - pendingTransactionHashes: updatedPendingTransactionHashes, - transactionCount: transactionCount - }) - } else { - return Object.assign({}, state, { - batchCountAccumulator: state.batchCountAccumulator + incomingTransactions.length, - newTransactionHashes: _.map(incomingTransactions, 'transactionHash'), - pendingTransactionHashes: updatedPendingTransactionHashes, - transactionCount: transactionCount - }) - } + return Object.assign({}, state, { + newTransactions: [ + ...state.newTransactions, + action.msg.transactionHtml + ], + newTransactionHash: action.msg.transactionHash, + pendingTransactionHashes: updatedPendingTransactionHashes, + transactionCount: transactionCount + }) } case 'RECEIVED_UPDATED_BALANCE': { return Object.assign({}, state, { @@ -190,25 +168,17 @@ if ($addressDetailsPage.length) { addressChannel.on('internal_transaction', batchChannel((msgs) => store.dispatch({ type: 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH', msgs: humps.camelizeKeys(msgs) }) )) - addressChannel.on('pending_transaction', batchChannel((msgs) => - store.dispatch({ type: 'RECEIVED_NEW_PENDING_TRANSACTION_BATCH', msgs: humps.camelizeKeys(msgs) }) - )) - addressChannel.on('transaction', batchChannel((msgs) => - store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs: humps.camelizeKeys(msgs) }) - )) + addressChannel.on('pending_transaction', (msg) => store.dispatch({ type: 'RECEIVED_NEW_PENDING_TRANSACTION', msg: humps.camelizeKeys(msg) })) + addressChannel.on('transaction', (msg) => store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION', msg: humps.camelizeKeys(msg) })) const blocksChannel = socket.channel(`blocks:${addressHash}`, {}) blocksChannel.join() blocksChannel.onError(() => store.dispatch({ type: 'CHANNEL_DISCONNECTED' })) - blocksChannel.on('new_block', (msg) => { - store.dispatch({ type: 'RECEIVED_NEW_BLOCK', msg: humps.camelizeKeys(msg) }) - }) + blocksChannel.on('new_block', (msg) => store.dispatch({ type: 'RECEIVED_NEW_BLOCK', msg: humps.camelizeKeys(msg) })) }, render (state, oldState) { const $balance = $('[data-selector="balance-card"]') const $channelBatching = $('[data-selector="channel-batching-message"]') const $channelBatchingCount = $('[data-selector="channel-batching-count"]') - const $channelPendingBatching = $('[data-selector="channel-pending-batching-message"]') - const $channelPendingBatchingCount = $('[data-selector="channel-pending-batching-count"]') const $channelDisconnected = $('[data-selector="channel-disconnected-message"]') const $emptyInternalTransactionsList = $('[data-selector="empty-internal-transactions-list"]') const $emptyTransactionsList = $('[data-selector="empty-transactions-list"]') @@ -235,19 +205,10 @@ if ($addressDetailsPage.length) { } else { $channelBatching.hide() } - if (oldState.newPendingTransactionHashesBatch !== state.newPendingTransactionHashesBatch && state.newPendingTransactionHashesBatch.length > 0) { - $channelPendingBatching.show() - $channelPendingBatchingCount[0].innerHTML = numeral(state.newPendingTransactionHashesBatch.length).format() - } else { - $channelPendingBatching.hide() - } - if (oldState.newTransactionHashes !== state.newTransactionHashes && state.newTransactionHashes.length > 0) { - let $transaction - _.each(state.newTransactionHashes, (hash) => { - $transaction = $(`[data-selector="pending-transactions-list"] [data-transaction-hash="${hash}"]`) - $transaction.addClass('shrink-out') - setTimeout(() => $transaction.slideUp({ complete: () => $transaction.remove() }), 400) - }) + if (oldState.newTransactionHash !== state.newTransactionHash && state.newTransactionHash) { + let $transaction = $(`[data-selector="pending-transactions-list"] [data-transaction-hash="${state.newTransactionHash}"]`) + $transaction.addClass('shrink-out') + setTimeout(() => $transaction.slideUp({ complete: () => $transaction.remove() }), 400) } if (oldState.newInternalTransactions !== state.newInternalTransactions && $internalTransactionsList.length) { prependWithClingBottom($internalTransactionsList, state.newInternalTransactions.slice(oldState.newInternalTransactions.length).reverse().join('')) diff --git a/apps/block_scout_web/assets/js/pages/chain.js b/apps/block_scout_web/assets/js/pages/chain.js index c9755da39e..4586fff98f 100644 --- a/apps/block_scout_web/assets/js/pages/chain.js +++ b/apps/block_scout_web/assets/js/pages/chain.js @@ -5,16 +5,13 @@ import numeral from 'numeral' import socket from '../socket' import { updateAllAges } from '../lib/from_now' import { exchangeRateChannel, formatUsdValue } from '../lib/currency' -import { batchChannel, buildFullBlockList, initRedux, skippedBlockListBuilder, slideDownPrepend } from '../utils' +import { buildFullBlockList, initRedux, skippedBlockListBuilder, slideDownPrepend } from '../utils' import { createMarketHistoryChart } from '../lib/market_history_chart' -const BATCH_THRESHOLD = 10 - export const initialState = { addressCount: null, availableSupply: null, averageBlockTime: null, - batchCountAccumulator: 0, blockNumbers: [], marketHistoryData: null, newBlock: null, @@ -85,21 +82,14 @@ export function reducer (state = initialState, action) { usdMarketCap: action.msg.exchangeRate.marketCapUsd }) } - case 'RECEIVED_NEW_TRANSACTION_BATCH': { - if (!state.batchCountAccumulator && action.msgs.length < BATCH_THRESHOLD) { - return Object.assign({}, state, { - newTransactions: [ - ...state.newTransactions, - ...action.msgs.map(({transactionHtml}) => transactionHtml) - ], - transactionCount: state.transactionCount + action.msgs.length - }) - } else { - return Object.assign({}, state, { - batchCountAccumulator: state.batchCountAccumulator + action.msgs.length, - transactionCount: state.transactionCount + action.msgs.length - }) - } + case 'RECEIVED_NEW_TRANSACTION': { + return Object.assign({}, state, { + newTransactions: [ + ...state.newTransactions, + action.msg.transactionHtml + ], + transactionCount: state.transactionCount + 1 + }) } default: return state @@ -128,9 +118,7 @@ if ($chainDetailsPage.length) { const transactionsChannel = socket.channel(`transactions:new_transaction`) transactionsChannel.join() - transactionsChannel.on('transaction', batchChannel((msgs) => - store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs: humps.camelizeKeys(msgs) })) - ) + transactionsChannel.on('transaction', (msg) => store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION', msg: humps.camelizeKeys(msg) })) chart = createMarketHistoryChart($('[data-chart="marketHistoryChart"]')[0]) }, @@ -138,8 +126,6 @@ if ($chainDetailsPage.length) { const $addressCount = $('[data-selector="address-count"]') const $averageBlockTime = $('[data-selector="average-block-time"]') const $blockList = $('[data-selector="chain-block-list"]') - const $channelBatching = $('[data-selector="channel-batching-message"]') - const $channelBatchingCount = $('[data-selector="channel-batching-count"]') const $marketCap = $('[data-selector="market-cap"]') const $transactionsList = $('[data-selector="transactions-list"]') const $transactionCount = $('[data-selector="transaction-count"]') @@ -176,12 +162,6 @@ if ($chainDetailsPage.length) { updateAllAges() } if (oldState.transactionCount !== state.transactionCount) $transactionCount.empty().append(numeral(state.transactionCount).format()) - if (state.batchCountAccumulator) { - $channelBatching.show() - $channelBatchingCount[0].innerHTML = numeral(state.batchCountAccumulator).format() - } else { - $channelBatching.hide() - } if (newTransactions.length) { const newTransactionsToInsert = state.newTransactions.slice(oldState.newTransactions.length) $transactionsList diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_transaction/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_transaction/index.html.eex index 13524c15a1..d313d84cab 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_transaction/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_transaction/index.html.eex @@ -9,16 +9,6 @@
- -
<%= gettext "Connection Lost, click to load newer transactions" %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex index bc8b546e58..ff0c15f50e 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex @@ -67,11 +67,6 @@
- <%= link(gettext("View All Transactions →"), to: transaction_path(BlockScoutWeb.Endpoint, :index), class: "button button-secondary button-xsmall float-right") %>

<%= gettext "Transactions" %>