parent
22b86b59de
commit
960eb451a9
@ -0,0 +1,58 @@ |
||||
.transaction-detail { |
||||
&__container { |
||||
@extend %paper; |
||||
padding: explorer-size(-1) explorer-size(0); |
||||
} |
||||
|
||||
&__title { |
||||
@include explorer-typography("title"); |
||||
color: explorer-color("slate", "100"); |
||||
margin: 0; |
||||
} |
||||
|
||||
&__subheader { |
||||
@include explorer-typography("body1"); |
||||
text-overflow: ellipsis; |
||||
white-space: nowrap; |
||||
overflow: hidden; |
||||
} |
||||
|
||||
&__column { |
||||
@include explorer-typography("body1"); |
||||
} |
||||
|
||||
&__item { |
||||
display: flex; |
||||
flex-direction: row; |
||||
justify-content: space-between; |
||||
|
||||
dt { |
||||
color: explorer-color("slate", "100"); |
||||
min-width: explorer-size(3); |
||||
} |
||||
|
||||
dd { |
||||
color: explorer-color("slate", "100"); |
||||
text-overflow: ellipsis; |
||||
white-space: nowrap; |
||||
overflow: hidden; |
||||
} |
||||
} |
||||
} |
||||
|
||||
@media (min-width: $explorer-breakpoint-lg) { |
||||
.transaction-detail { |
||||
&__attributes { |
||||
display: flex; |
||||
align-items: top; |
||||
justify-content: top; |
||||
} |
||||
|
||||
&__column { |
||||
width: explorer-size(1); |
||||
flex: 1; |
||||
margin-right: explorer-size(1); |
||||
& + & { margin-left: explorer-size(1); } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
defmodule Explorer.TransactionForm do |
||||
@moduledoc false |
||||
|
||||
def build(transaction) do |
||||
transaction |
||||
|> Map.merge(%{ |
||||
block_number: transaction |> block_number, |
||||
age: transaction |> block_age, |
||||
formatted_timestamp: transaction |> format_timestamp, |
||||
}) |
||||
end |
||||
|
||||
def block_number(transaction) do |
||||
transaction.block.number |
||||
end |
||||
|
||||
def block_age(transaction) do |
||||
transaction.block.timestamp |> Timex.from_now |
||||
end |
||||
|
||||
def format_timestamp(transaction) do |
||||
transaction.block.timestamp |> Timex.format!("%b-%d-%Y %H:%M:%S %p %Z", :strftime) |
||||
end |
||||
end |
@ -0,0 +1,17 @@ |
||||
defmodule ExplorerWeb.TransactionController do |
||||
use ExplorerWeb, :controller |
||||
import Ecto.Query |
||||
alias Explorer.Transaction |
||||
alias Explorer.Repo |
||||
alias Explorer.TransactionForm |
||||
|
||||
def show(conn, params) do |
||||
transaction = Transaction |
||||
|> where(id: ^params["id"]) |
||||
|> first |
||||
|> Repo.one |
||||
|> Repo.preload(:block) |
||||
|> TransactionForm.build |
||||
render(conn, "show.html", transaction: transaction) |
||||
end |
||||
end |
@ -0,0 +1,40 @@ |
||||
<section class="container__section"> |
||||
<div class="transaction-detail__container"> |
||||
<div class="transaction-detail__header"> |
||||
<h2 class="transaction-detail__title"> |
||||
<%= gettext "Transaction Details" %> |
||||
</h2> |
||||
<div class="transaction-detail__subheader"> |
||||
<div class="transaction-detail__hash"> |
||||
<%= @transaction.hash %> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="transaction-detail__attributes"> |
||||
<div class="transaction-detail__column"> |
||||
<dl> |
||||
<div class="transaction-detail__item"> |
||||
<dt><%= gettext "Age" %></dt> |
||||
<dd><%= @transaction.age %></dd> |
||||
</div> |
||||
<div class="transaction-detail__item"> |
||||
<dt><%= gettext "Timestamp" %></dt> |
||||
<dd><%= @transaction.formatted_timestamp %></dd> |
||||
</div> |
||||
</dl> |
||||
</div> |
||||
<div class="transaction-detail__column"> |
||||
<dl> |
||||
<div class="transaction-detail__item"> |
||||
<dt><%= gettext "Block Number" %></dt> |
||||
<dd><%= @transaction.block_number %></dd> |
||||
</div> |
||||
<div class="transaction-detail__item"> |
||||
<dt><%= gettext "Value" %></dt> |
||||
<dd><%= @transaction.value %></dd> |
||||
</div> |
||||
</dl> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</section> |
@ -0,0 +1,4 @@ |
||||
defmodule ExplorerWeb.TransactionView do |
||||
use ExplorerWeb, :view |
||||
@dialyzer :no_match |
||||
end |
@ -0,0 +1,25 @@ |
||||
defmodule Explorer.TransactionFormTest do |
||||
use Explorer.DataCase |
||||
alias Explorer.TransactionForm |
||||
|
||||
describe "build/1" do |
||||
test "that it has a block number" do |
||||
block = insert(:block, number: 622) |
||||
transaction = insert(:transaction, block: block) |
||||
assert TransactionForm.build(transaction).block_number == 622 |
||||
end |
||||
|
||||
test "that it returns the block's age" do |
||||
block = insert(:block, timestamp: Timex.now |> Timex.shift(hours: -2)) |
||||
transaction = insert(:transaction, block: block) |
||||
assert TransactionForm.build(transaction).age == "2 hours ago" |
||||
end |
||||
|
||||
test "formats the block's timestamp" do |
||||
date = "Feb-02-2010 10:48:56 AM Etc/UTC" |
||||
block = insert(:block, timestamp: Timex.parse!(date, "%b-%d-%Y %H:%M:%S %p %Z", :strftime)) |
||||
transaction = insert(:transaction, block: block) |
||||
assert TransactionForm.build(transaction).formatted_timestamp == date |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,11 @@ |
||||
defmodule ExplorerWeb.TransactionControllerTest do |
||||
use ExplorerWeb.ConnCase |
||||
|
||||
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 |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue