Blocks and Transactions are navigated by height and hash

pull/2/head
Doc Ritezel 7 years ago
parent 06f580a0cf
commit d863f78b88
  1. 2
      lib/explorer_web/controllers/block_controller.ex
  2. 2
      lib/explorer_web/controllers/transaction_controller.ex
  3. 4
      lib/explorer_web/templates/page/index.html.eex
  4. 4
      test/explorer_web/controllers/block_controller_test.exs
  5. 6
      test/explorer_web/controllers/transaction_controller_test.exs

@ -7,7 +7,7 @@ defmodule ExplorerWeb.BlockController do
def show(conn, params) do
block = Block
|> where(id: ^params["id"])
|> where(number: ^params["id"])
|> first |> Repo.one
|> BlockForm.build
render(conn, "show.html", block: block)

@ -7,7 +7,7 @@ defmodule ExplorerWeb.TransactionController do
def show(conn, params) do
transaction = Transaction
|> where(id: ^params["id"])
|> where(hash: ^params["id"])
|> first
|> Repo.one
|> Repo.preload(:block)

@ -16,7 +16,7 @@
<tbody>
<%= for block <- @blocks do %>
<tr class="blocks__row">
<td class="blocks__column blocks__column--height"><%= link(block.number, to: block_path(@conn, :show, @conn.assigns.locale, block.id)) %></td>
<td class="blocks__column blocks__column--height"><%= link(block.number, to: block_path(@conn, :show, @conn.assigns.locale, block.number)) %></td>
<td class="blocks__column blocks__column--age"><%= block.age %></td>
<td class="blocks__column blocks__column--transactions-count"><%= block.transactions_count %></td>
<td class="blocks__column blocks__column--gas-used"><%= block.gas_used %></td>
@ -45,7 +45,7 @@
<tr class="transactions__row">
<td class="transactions__column transactions__column--hash">
<div class="transactions__hash" title="<%= transaction.hash %>">
<%= link(transaction.hash, to: transaction_path(@conn, :show, @conn.assigns.locale, transaction.id)) %>
<%= link(transaction.hash, to: transaction_path(@conn, :show, @conn.assigns.locale, transaction.hash)) %>
</div>
</td>
<td class="transactions__column transactions__column--block"><%= transaction.block_number %></td>

@ -3,9 +3,9 @@ defmodule ExplorerWeb.BlockControllerTest do
describe "GET show/3" do
test "returns a block", %{conn: conn} do
insert(:block, id: 3)
block = insert(:block, number: 3)
conn = get(conn, "/en/blocks/3")
assert conn.assigns.block.id == 3
assert conn.assigns.block.id == block.id
end
end
end

@ -3,9 +3,9 @@ defmodule ExplorerWeb.TransactionControllerTest do
describe "GET show/3" do
test "returns a transaction", %{conn: conn} do
insert(:transaction, id: 8)
conn = get(conn, "/en/transactions/8")
assert conn.assigns.transaction.id == 8
transaction = insert(:transaction, hash: "0x8")
conn = get(conn, "/en/transactions/0x8")
assert conn.assigns.transaction.id == transaction.id
end
end
end

Loading…
Cancel
Save