From b9f233fd85f503fd69f35562e861bd0ec1f6772e Mon Sep 17 00:00:00 2001 From: Stamates Date: Wed, 26 Sep 2018 15:41:39 -0400 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20render=20pending=20transaction?= =?UTF-8?q?=20beyond=20page=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../address_transaction_controller.ex | 8 ++++- .../address_transaction_controller_test.exs | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex index 7233d7eab6..3a797d2974 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex @@ -31,6 +31,12 @@ defmodule BlockScoutWeb.AddressTransactionController do transactions_plus_one = Chain.address_to_transactions(address, full_options) {transactions, next_page} = split_list_by_page(transactions_plus_one) + pending_transactions = + case Map.has_key?(params, "block_number") do + true -> [] + false -> Chain.address_to_pending_transactions(address, pending_options) + end + render( conn, "index.html", @@ -38,7 +44,7 @@ defmodule BlockScoutWeb.AddressTransactionController do next_page_params: next_page_params(next_page, transactions, params), exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), filter: params["filter"], - pending_transactions: Chain.address_to_pending_transactions(address, pending_options), + pending_transactions: pending_transactions, transactions: transactions, transaction_count: transaction_count(address), validation_count: validation_count(address) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs index e5ae7c5b6e..0c71e32503 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs @@ -97,6 +97,35 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do assert second_page_hashes == actual_hashes end + test "does not return pending transactions if beyond page one", %{conn: conn} do + address = insert(:address) + + 50 + |> insert_list(:transaction, from_address: address) + |> with_block() + |> Enum.map(& &1.hash) + + %Transaction{block_number: block_number, index: index} = + :transaction + |> insert(from_address: address) + |> with_block() + + pending = insert(:transaction, from_address: address, to_address: address) + + conn = + get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash), %{ + "block_number" => Integer.to_string(block_number), + "index" => Integer.to_string(index) + }) + + actual_pending_hashes = + conn.assigns.pending_transactions + |> Enum.map(& &1.hash) + |> Enum.reverse() + + refute Enum.member?(actual_pending_hashes, pending.hash) + end + test "next_page_params exist if not on last page", %{conn: conn} do address = insert(:address) block = %Block{number: number} = insert(:block)