Contributors can view Transaction details.

pull/2/head
CJ Bryan and Matt Olenick 7 years ago
parent 22b86b59de
commit 960eb451a9
  1. 5
      assets/css/components/_all.scss
  2. 58
      assets/css/components/_transaction-detail.scss
  3. 24
      lib/explorer/forms/transaction_form.ex
  4. 2
      lib/explorer_web/controllers/page_controller.ex
  5. 17
      lib/explorer_web/controllers/transaction_controller.ex
  6. 1
      lib/explorer_web/router.ex
  7. 8
      lib/explorer_web/templates/page/index.html.eex
  8. 40
      lib/explorer_web/templates/transaction/show.html.eex
  9. 4
      lib/explorer_web/views/transaction_view.ex
  10. 11
      priv/gettext/default.pot
  11. 11
      priv/gettext/en/LC_MESSAGES/default.po
  12. 5
      test/explorer/forms/block_form_test.exs
  13. 25
      test/explorer/forms/transaction_form_test.exs
  14. 11
      test/explorer_web/controllers/transaction_controller_test.exs
  15. 10
      test/explorer_web/features/contributor_browsing_test.exs

@ -1,6 +1,7 @@
@import "block-detail";
@import "blocks";
@import "container";
@import "footer";
@import "header";
@import "block-detail";
@import "transaction-detail";
@import "transactions";
@import "footer";

@ -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

@ -5,6 +5,7 @@ defmodule ExplorerWeb.PageController do
alias Explorer.Transaction
alias Explorer.Repo
alias Explorer.BlockForm
alias Explorer.TransactionForm
def index(conn, _params) do
blocks = Block
@ -19,6 +20,7 @@ defmodule ExplorerWeb.PageController do
|> limit(5)
|> Repo.all
|> Repo.preload(:block)
|> Enum.map(&TransactionForm.build/1)
render(conn, "index.html", blocks: blocks, transactions: transactions)
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

@ -30,5 +30,6 @@ defmodule ExplorerWeb.Router do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
resources "/blocks", BlockController, only: [:show]
resources "/transactions", TransactionController, only: [:show]
end
end

@ -44,10 +44,12 @@
<%= for transaction <- @transactions do %>
<tr class="transactions__row">
<td class="transactions__column transactions__column--hash">
<div class="transactions__hash" title="<%= transaction.hash %>"><%= transaction.hash %></div>
<div class="transactions__hash" title="<%= transaction.hash %>">
<%= link(transaction.hash, to: transaction_path(@conn, :show, @conn.assigns.locale, transaction.id)) %>
</div>
</td>
<td class="transactions__column transactions__column--block"><%= transaction.block.number %></td>
<td class="transactions__column transactions__column--age"><%= transaction.block.timestamp |> Timex.from_now %></td>
<td class="transactions__column transactions__column--block"><%= transaction.block_number %></td>
<td class="transactions__column transactions__column--age"><%= transaction.age %></td>
<td class="transactions__column transactions__column--value"><%= transaction.value %></td>
</tr>
<% 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

@ -1,6 +1,7 @@
#: lib/explorer_web/templates/block/show.html.eex:14
#: lib/explorer_web/templates/page/index.html.eex:11
#: lib/explorer_web/templates/page/index.html.eex:39
#: lib/explorer_web/templates/transaction/show.html.eex:17
msgid "Age"
msgstr ""
@ -42,6 +43,7 @@ msgid "Transactions"
msgstr ""
#: lib/explorer_web/templates/page/index.html.eex:40
#: lib/explorer_web/templates/transaction/show.html.eex:33
msgid "Value"
msgstr ""
@ -78,9 +80,18 @@ msgid "Size"
msgstr ""
#: lib/explorer_web/templates/block/show.html.eex:18
#: lib/explorer_web/templates/transaction/show.html.eex:21
msgid "Timestamp"
msgstr ""
#: lib/explorer_web/templates/block/show.html.eex:46
msgid "Total Difficulty"
msgstr ""
#: lib/explorer_web/templates/transaction/show.html.eex:29
msgid "Block Number"
msgstr ""
#: lib/explorer_web/templates/transaction/show.html.eex:5
msgid "Transaction Details"
msgstr ""

@ -13,6 +13,7 @@ msgstr ""
#: lib/explorer_web/templates/block/show.html.eex:14
#: lib/explorer_web/templates/page/index.html.eex:11
#: lib/explorer_web/templates/page/index.html.eex:39
#: lib/explorer_web/templates/transaction/show.html.eex:17
msgid "Age"
msgstr "Age"
@ -54,6 +55,7 @@ msgid "Transactions"
msgstr "Transactions"
#: lib/explorer_web/templates/page/index.html.eex:40
#: lib/explorer_web/templates/transaction/show.html.eex:33
msgid "Value"
msgstr "Value"
@ -90,9 +92,18 @@ msgid "Size"
msgstr "Size"
#: lib/explorer_web/templates/block/show.html.eex:18
#: lib/explorer_web/templates/transaction/show.html.eex:21
msgid "Timestamp"
msgstr "Timestamp"
#: lib/explorer_web/templates/block/show.html.eex:46
msgid "Total Difficulty"
msgstr "Total Difficulty"
#: lib/explorer_web/templates/transaction/show.html.eex:29
msgid "Block Number"
msgstr "Block Height"
#: lib/explorer_web/templates/transaction/show.html.eex:5
msgid "Transaction Details"
msgstr "Transaction Details"

@ -3,11 +3,6 @@ defmodule Explorer.BlockFormTest do
alias Explorer.BlockForm
describe "build/1" do
test "that it works" do
block = insert(:block)
assert BlockForm.build(block)
end
test "that it has a number" do
block = insert(:block, number: 311)
insert_list(2, :transaction, block: block)

@ -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

@ -42,13 +42,19 @@ defmodule ExplorerWeb.UserListTest do
test "views transactions on the home page", %{session: session} do
transaction_block = insert(:block, timestamp: Timex.now |> Timex.shift(hours: -2))
insert_list(5, :transaction, block: transaction_block)
insert_list(4, :transaction, block: transaction_block)
insert(:transaction, hash: "0xSk8", value: 5656)
session
|> visit("/en")
|> assert_has(css(".transactions__title", text: "Transactions"))
|> assert_has(css(".transactions__column--hash", count: 5))
|> assert_has(css(".transactions__column--value", count: 5))
|> assert_has(css(".transactions__column--age", count: 5, text: "2 hours ago"))
|> assert_has(css(".transactions__column--age", count: 5))
session
|> click(link("0xSk8"))
|> assert_has(css(".transaction-detail__hash", text: "0xSk8"))
|> assert_has(css(".transaction-detail__item", text: "5656"))
end
end

Loading…
Cancel
Save