From 26c472903b8a8c2175975eb32bb68ea9fe404821 Mon Sep 17 00:00:00 2001 From: Felipe Renan Date: Thu, 29 Nov 2018 18:48:31 -0200 Subject: [PATCH] Remove references from pending transactions feature This code should be removed with the code removed in this PR: https://github.com/poanetwork/blockscout/pull/1063/files --- .../assets/__tests__/pages/address.js | 69 ------------------- .../assets/js/pages/address.js | 67 ++---------------- .../channels/address_channel.ex | 3 +- 3 files changed, 5 insertions(+), 134 deletions(-) diff --git a/apps/block_scout_web/assets/__tests__/pages/address.js b/apps/block_scout_web/assets/__tests__/pages/address.js index ca6f188bef..fe6506e22b 100644 --- a/apps/block_scout_web/assets/__tests__/pages/address.js +++ b/apps/block_scout_web/assets/__tests__/pages/address.js @@ -172,70 +172,9 @@ describe('RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH', () => { }) }) -describe('RECEIVED_NEW_PENDING_TRANSACTION', () => { - test('with new pending transaction', () => { - const state = Object.assign({}, initialState, { - pendingTransactions: [{ transactionHash: 1, transactionHtml: 'test 1' }] - }) - const action = { - type: 'RECEIVED_NEW_PENDING_TRANSACTION', - msg: { transactionHash: 2, transactionHtml: 'test 2' } - } - const output = reducer(state, action) - - expect(output.pendingTransactions).toEqual([ - { transactionHash: 2, transactionHtml: 'test 2' }, - { transactionHash: 1, transactionHtml: 'test 1' } - ]) - }) - test('when channel has been disconnected', () => { - const state = Object.assign({}, initialState, { - channelDisconnected: true, - pendingTransactions: [{ transactionHash: 1, transactionHtml: 'test 1' }] - }) - const action = { - type: 'RECEIVED_NEW_PENDING_TRANSACTION', - msg: { transactionHash: 2, transactionHtml: 'test 2' } - } - const output = reducer(state, action) - - expect(output.pendingTransactions).toEqual([ - { transactionHash: 1, transactionHtml: 'test 1' } - ]) - }) - test('beyond page one', () => { - const state = Object.assign({}, initialState, { - beyondPageOne: true, - pendingTransactions: [{ transactionHash: 1, transactionHtml: 'test 1' }] - }) - const action = { - type: 'RECEIVED_NEW_PENDING_TRANSACTION', - msg: { transactionHash: 2, transactionHtml: 'test 2' } - } - const output = reducer(state, action) - - expect(output.pendingTransactions).toEqual([ - { transactionHash: 1, transactionHtml: 'test 1' } - ]) - }) - test('with filtered out pending transaction', () => { - const state = Object.assign({}, initialState, { - filter: 'to' - }) - const action = { - type: 'RECEIVED_NEW_PENDING_TRANSACTION', - msg: { transactionHash: 2, transactionHtml: 'test 2' } - } - const output = reducer(state, action) - - expect(output.pendingTransactions).toEqual([]) - }) -}) - describe('RECEIVED_NEW_TRANSACTION', () => { test('with new transaction', () => { const state = Object.assign({}, initialState, { - pendingTransactions: [{ transactionHash: 2, transactionHtml: 'test' }], transactions: [{ transactionHash: 1, transactionHtml: 'test 1' }] }) const action = { @@ -244,9 +183,6 @@ describe('RECEIVED_NEW_TRANSACTION', () => { } const output = reducer(state, action) - expect(output.pendingTransactions).toEqual([ - { transactionHash: 2, transactionHtml: 'test 2', validated: true } - ]) expect(output.transactions).toEqual([ { transactionHash: 2, transactionHtml: 'test 2' }, { transactionHash: 1, transactionHtml: 'test 1' } @@ -255,7 +191,6 @@ describe('RECEIVED_NEW_TRANSACTION', () => { test('when channel has been disconnected', () => { const state = Object.assign({}, initialState, { channelDisconnected: true, - pendingTransactions: [{ transactionHash: 2, transactionHtml: 'test' }], transactions: [{ transactionHash: 1, transactionHtml: 'test 1' }] }) const action = { @@ -264,9 +199,6 @@ describe('RECEIVED_NEW_TRANSACTION', () => { } const output = reducer(state, action) - expect(output.pendingTransactions).toEqual([ - { transactionHash: 2, transactionHtml: 'test' } - ]) expect(output.transactions).toEqual([ { transactionHash: 1, transactionHtml: 'test 1' } ]) @@ -282,7 +214,6 @@ describe('RECEIVED_NEW_TRANSACTION', () => { } const output = reducer(state, action) - expect(output.pendingTransactions).toEqual([]) expect(output.transactions).toEqual([ { transactionHash: 1, transactionHtml: 'test 1' } ]) diff --git a/apps/block_scout_web/assets/js/pages/address.js b/apps/block_scout_web/assets/js/pages/address.js index 8472a2130e..683fc66a57 100644 --- a/apps/block_scout_web/assets/js/pages/address.js +++ b/apps/block_scout_web/assets/js/pages/address.js @@ -12,7 +12,6 @@ import { updateAllCalculatedUsdValues } from '../lib/currency.js' import { loadTokenBalanceDropdown } from '../lib/token_balance_dropdown' const BATCH_THRESHOLD = 10 -const TRANSACTION_VALIDATED_MOVE_DELAY = 1000 export const initialState = { channelDisconnected: false, @@ -24,7 +23,6 @@ export const initialState = { transactionCount: null, validationCount: null, - pendingTransactions: [], transactions: [], internalTransactions: [], internalTransactionsBatch: [], @@ -91,26 +89,6 @@ function baseReducer (state = initialState, action) { }) } } - case 'RECEIVED_NEW_PENDING_TRANSACTION': { - if (state.channelDisconnected || state.beyondPageOne) return state - - if ((state.filter === 'to' && action.msg.toAddressHash !== state.addressHash) || - (state.filter === 'from' && action.msg.fromAddressHash !== state.addressHash)) { - return state - } - - return Object.assign({}, state, { - pendingTransactions: [ - action.msg, - ...state.pendingTransactions - ] - }) - } - case 'REMOVE_PENDING_TRANSACTION': { - return Object.assign({}, state, { - pendingTransactions: state.pendingTransactions.filter((transaction) => action.msg.transactionHash !== transaction.transactionHash) - }) - } case 'RECEIVED_NEW_TRANSACTION': { if (state.channelDisconnected) return state @@ -123,7 +101,6 @@ function baseReducer (state = initialState, action) { } return Object.assign({}, state, { - pendingTransactions: state.pendingTransactions.map((transaction) => action.msg.transactionHash === transaction.transactionHash ? Object.assign({}, action.msg, { validated: true }) : transaction), transactions: [ action.msg, ...state.transactions @@ -184,28 +161,6 @@ const elements = { $el.empty().append(numeral(state.validationCount).format()) } }, - '[data-selector="pending-transactions-list"]': { - load ($el) { - return { - pendingTransactions: $el.children().map((index, el) => ({ - transactionHash: el.dataset.transactionHash, - transactionHtml: el.outerHTML - })).toArray() - } - }, - render ($el, state, oldState) { - if (oldState.pendingTransactions === state.pendingTransactions) return - const container = $el[0] - const newElements = _.map(state.pendingTransactions, ({ transactionHtml }) => $(transactionHtml)[0]) - listMorph(container, newElements, { key: 'dataset.transactionHash' }) - } - }, - '[data-selector="pending-transactions-count"]': { - render ($el, state, oldState) { - if (oldState.pendingTransactions === state.pendingTransactions) return - $el[0].innerHTML = numeral(state.pendingTransactions.filter(({ validated }) => !validated).length).format() - } - }, '[data-selector="empty-transactions-list"]': { render ($el, state) { if (state.transactions.length || state.loadingNextPage || state.pagingError) { @@ -226,16 +181,10 @@ const elements = { }, render ($el, state, oldState) { if (oldState.transactions === state.transactions) return - function updateTransactions () { - const container = $el[0] - const newElements = _.map(state.transactions, ({ transactionHtml }) => $(transactionHtml)[0]) - listMorph(container, newElements, { key: 'dataset.transactionHash' }) - } - if ($('[data-selector="pending-transactions-list"]').is(':visible')) { - setTimeout(updateTransactions, TRANSACTION_VALIDATED_MOVE_DELAY + 400) - } else { - updateTransactions() - } + + const container = $el[0] + const newElements = _.map(state.transactions, ({ transactionHtml }) => $(transactionHtml)[0]) + return listMorph(container, newElements, { key: 'dataset.transactionHash' }) } }, '[data-selector="internal-transactions-list"]': { @@ -306,19 +255,11 @@ if ($addressDetailsPage.length) { type: 'RECEIVED_NEW_INTERNAL_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) }) - setTimeout(() => store.dispatch({ - type: 'REMOVE_PENDING_TRANSACTION', - msg: humps.camelizeKeys(msg) - }), TRANSACTION_VALIDATED_MOVE_DELAY) }) const blocksChannel = socket.channel(`blocks:${addressHash}`, {}) diff --git a/apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex b/apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex index 6213b6aaf5..3e09fa7541 100644 --- a/apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex +++ b/apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex @@ -8,7 +8,7 @@ defmodule BlockScoutWeb.AddressChannel do alias Explorer.Chain.Hash alias Phoenix.View - intercept(["balance_update", "count", "internal_transaction", "pending_transaction", "transaction"]) + intercept(["balance_update", "count", "internal_transaction", "transaction"]) def join("addresses:" <> _address_hash, _params, socket) do {:ok, %{}, socket} @@ -62,7 +62,6 @@ defmodule BlockScoutWeb.AddressChannel do end def handle_out("transaction", data, socket), do: handle_transaction(data, socket, "transaction") - def handle_out("pending_transaction", data, socket), do: handle_transaction(data, socket, "pending_transaction") def handle_transaction(%{address: address, transaction: transaction}, socket, event) do Gettext.put_locale(BlockScoutWeb.Gettext, socket.assigns.locale)