Display last seen and first seen for transactions

pull/2/head
CJ Bryan and Matt Olenick 7 years ago
parent feef86e6b8
commit 12e67122bc
  1. 10
      lib/explorer/forms/transaction_form.ex
  2. 8
      lib/explorer_web/templates/transaction/show.html.eex
  3. 14
      test/explorer/forms/transaction_form_test.exs
  4. 4
      test/explorer_web/features/contributor_browsing_test.exs

@ -24,6 +24,8 @@ defmodule Explorer.TransactionForm do
from_address: transaction |> from_address,
confirmations: block |> confirmations,
status: transaction |> status,
first_seen: transaction |> first_seen,
last_seen: transaction |> last_seen,
})
end
@ -85,4 +87,12 @@ defmodule Explorer.TransactionForm do
gettext("Pending")
end
end
def first_seen(transaction) do
transaction.inserted_at |> Timex.from_now
end
def last_seen(transaction) do
transaction.updated_at |> Timex.from_now
end
end

@ -69,6 +69,14 @@
<dt class="transaction__item-key"><%= gettext "Input" %></dt>
<dd class="transaction__item-value" title="<%= @transaction.input %>"><%= @transaction.input %></dd>
</div>
<div class="transaction__item">
<dt class="transaction__item-key"><%= gettext "First Seen" %></dt>
<dd class="transaction__item-value" title="<%= @transaction.first_seen %>"><%= @transaction.first_seen %></dd>
</div>
<div class="transaction__item">
<dt class="transaction__item-key"><%= gettext "Last Seen" %></dt>
<dd class="transaction__item-value" title="<%= @transaction.last_seen %>"><%= @transaction.last_seen %></dd>
</div>
</dl>
</div>
</div>

@ -13,7 +13,9 @@ defmodule Explorer.TransactionFormTest do
timestamp: time,
})
transaction =
insert(:transaction)
insert(:transaction,
inserted_at: Timex.parse!("1970-01-01T00:00:18-00:00", "{ISO:Extended}"),
updated_at: Timex.parse!("1980-01-01T00:00:18-00:00", "{ISO:Extended}"))
|> with_block(block)
|> with_addresses(%{to: "0xsleepypuppy", from: "0xilovefrogs"})
|> Repo.preload(:block)
@ -30,11 +32,17 @@ defmodule Explorer.TransactionFormTest do
from_address: "0xilovefrogs",
confirmations: 23,
status: "Success",
first_seen: "48 years ago",
last_seen: "38 years ago",
}))
end
test "works when there is no block" do
transaction = insert(:transaction) |> with_addresses(%{to: "0xchadmuska", from: "0xtonyhawk"}) |> Repo.preload(:block)
transaction = insert(
:transaction,
inserted_at: Timex.parse!("1970-01-01T00:00:18-00:00", "{ISO:Extended}"),
updated_at: Timex.parse!("1980-01-01T00:00:18-00:00", "{ISO:Extended}"))
|> with_addresses(%{to: "0xchadmuska", from: "0xtonyhawk"}) |> Repo.preload(:block)
form = TransactionForm.build(transaction)
assert(form == Map.merge(transaction, %{
@ -47,6 +55,8 @@ defmodule Explorer.TransactionFormTest do
from_address: "0xtonyhawk",
confirmations: 0,
status: "Pending",
first_seen: "48 years ago",
last_seen: "38 years ago",
}))
end
end

@ -65,6 +65,8 @@ defmodule ExplorerWeb.UserListTest do
gas_price: 7890000000898912300045,
input: "0x00012",
nonce: 99045,
inserted_at: Timex.parse!("1970-01-01T00:00:18-00:00", "{ISO:Extended}"),
updated_at: Timex.parse!("1980-01-01T00:00:18-00:00", "{ISO:Extended}"),
})
|> with_block(block)
|> with_addresses(%{to: "0xabelincoln", from: "0xhowardtaft"})
@ -94,6 +96,8 @@ defmodule ExplorerWeb.UserListTest do
|> assert_has(css(".transaction__item", text: "0xabelincoln"))
|> assert_has(css(".transaction__item", text: "0xhowardtaft"))
|> assert_has(css(".transaction__item", text: "block confirmations"))
|> assert_has(css(".transaction__item", text: "48 years ago"))
|> assert_has(css(".transaction__item", text: "38 years ago"))
session
|> click(link("0xabelincoln"))

Loading…
Cancel
Save