Don’t show paging button on last page for transactions list

pull/306/head
Stamates 7 years ago
parent bac4b9b57f
commit e60fdc9b57
  1. 14
      apps/explorer_web/lib/explorer_web/controllers/transaction_controller.ex
  2. 4
      apps/explorer_web/lib/explorer_web/templates/transaction/index.html.eex
  3. 24
      apps/explorer_web/test/explorer_web/controllers/transaction_controller_test.exs

@ -3,7 +3,8 @@ defmodule ExplorerWeb.TransactionController do
alias Explorer.{Chain, PagingOptions}
@default_paging_options %PagingOptions{page_size: 50}
@page_size 50
@default_paging_options %PagingOptions{page_size: @page_size + 1}
def index(conn, %{"block_number" => block_number_string, "index" => index_string}) do
with {block_number, ""} <- Integer.parse(block_number_string),
@ -37,21 +38,24 @@ defmodule ExplorerWeb.TransactionController do
options
)
transactions = Chain.recent_collated_transactions(full_options)
transactions_plus_one = Chain.recent_collated_transactions(full_options)
{next_page, transactions} = List.pop_at(transactions_plus_one, @page_size)
transaction_estimated_count = Chain.transaction_estimated_count()
render(
conn,
"index.html",
earliest: earliest(transactions),
next_page_params: next_page_params(next_page, transactions),
transaction_estimated_count: transaction_estimated_count,
transactions: transactions
)
end
defp earliest([]), do: nil
defp next_page_params(nil, _transactions), do: nil
defp earliest(transactions) do
defp next_page_params(_, transactions) do
last = List.last(transactions)
%{block_number: last.block_number, index: last.index}
end

@ -85,7 +85,7 @@
</table>
</div>
</div>
<%= if @earliest do %>
<%= if @next_page_params do %>
<%= link(
gettext("Older"),
class: "button button--secondary button--sm u-float-right mt-3",
@ -93,7 +93,7 @@
@conn,
:index,
@conn.assigns.locale,
%{"block_number" => @earliest.block_number, "index" => @earliest.index}
@next_page_params
)
) %>
<% end %>

@ -65,6 +65,30 @@ defmodule ExplorerWeb.TransactionControllerTest do
assert second_page_hashes == actual_hashes
end
test "next_page_params exist if not on last page", %{conn: conn} do
address = insert(:address)
60
|> insert_list(:transaction, from_address_hash: address.hash)
|> with_block()
conn = get(conn, "/en/transactions")
assert conn.assigns.next_page_params
end
test "next_page_params are empty if on last page", %{conn: conn} do
address = insert(:address)
:transaction
|> insert(from_address_hash: address.hash)
|> with_block()
conn = get(conn, "/en/transactions")
refute conn.assigns.next_page_params
end
test "guards against bad block_number input", %{conn: conn} do
conn = get(conn, "/en/transactions", %{"block_number" => "foo", "index" => "2"})
assert html_response(conn, 422)

Loading…
Cancel
Save