Add uncle links to block detail page

pull/870/head
Stamates 6 years ago committed by Ryan Arthur
parent 32212135ef
commit 5007f24fcb
  1. 5
      apps/block_scout_web/lib/block_scout_web/controllers/block_transaction_controller.ex
  2. 25
      apps/block_scout_web/lib/block_scout_web/templates/block/overview.html.eex
  3. 4
      apps/block_scout_web/test/block_scout_web/features/pages/block_page.ex
  4. 13
      apps/block_scout_web/test/block_scout_web/features/viewing_blocks_test.exs

@ -9,7 +9,10 @@ defmodule BlockScoutWeb.BlockTransactionController do
def index(conn, %{"block_hash_or_number" => formatted_block_hash_or_number} = params) do
with {:ok, block} <-
param_block_hash_or_number_to_block(formatted_block_hash_or_number,
necessity_by_association: %{[miner: :names] => :required}
necessity_by_association: %{
[miner: :names] => :required,
:uncles => :optional
}
) do
block_transaction_count = Chain.block_to_transaction_count(block)

@ -9,7 +9,12 @@
</h1>
<!-- Block Height -->
<h3 data-test="block_detail_number">
<%= gettext "%{type} Height #%{height}", type: (if uncle?(@block), do: "Uncle", else: "Block"), height: @block.number %>
<%= if uncle?(@block) do %>
<%= gettext("Uncle Height:") %>
<%= link(@block, to: block_path(BlockScoutWeb.Endpoint, :show, @block.number)) %>
<% else %>
<%= gettext("Block Height: %{height}", height: @block.number) %>
<% end %>
</h3>
<div class="d-flex flex-row justify-content-start text-muted">
<!-- # of Transactions -->
@ -59,6 +64,24 @@
<dd class="col-sm-9"> <%= @block.total_difficulty |> Cldr.Number.to_string! %> </dd>
</dl>
<%= if length(@block.uncle_relations) do %>
<!-- Uncles -->
<dl class="row">
<dt class="col-sm-3 text-muted"> <%= gettext "Uncles" %> </dt>
<dd class="col-sm-9">
<%= for {relation, index} <- Enum.with_index(@block.uncle_relations) do %>
<%= link(
gettext("Position %{index}", index: index),
class: "block__link",
"data-test": "uncle_link",
"data-uncle-hash": to_string(relation.uncle_hash),
to: block_path(@conn, :show, relation.uncle_hash)
) %><%= if index < length(@block.uncle_relations) - 1 do %>,<% end %>
<% end %>
</dd>
</dl>
<% end %>
<!-- Nonce -->
<dl class="row mb-0">
<dt class="col-sm-3 text-muted"> <%= gettext "Nonce" %> </dt>

@ -37,6 +37,10 @@ defmodule BlockScoutWeb.BlockPage do
css("[data-transaction-hash='#{transaction_hash}'] [data-test='transaction_status']")
end
def uncle_link(%Block{hash: hash}) do
css("[data-test='uncle_link'][data-uncle-hash='#{hash}']")
end
def visit_page(session, %Block{} = block) do
visit(session, block_path(build_conn(), :show, block))
end

@ -129,11 +129,24 @@ defmodule BlockScoutWeb.ViewingBlocksTest do
test "show uncle detail page", %{session: session} do
uncle = insert(:block, consensus: false)
insert(:block_second_degree_relation, uncle_hash: uncle.hash)
session
|> BlockPage.visit_page(uncle)
|> assert_has(BlockPage.detail_number(uncle))
|> assert_has(BlockPage.page_type("Uncle Details"))
end
test "show link to uncle on block detail page", %{session: session} do
block = insert(:block)
uncle = insert(:block, consensus: false)
insert(:block_second_degree_relation, uncle_hash: uncle.hash, nephew: block)
session
|> BlockPage.visit_page(block)
|> assert_has(BlockPage.detail_number(block))
|> assert_has(BlockPage.page_type("Block Details"))
|> assert_has(BlockPage.uncle_link(uncle))
end
end
end

Loading…
Cancel
Save