Update transactions show page to display pending for incomplete block information

pull/2/head
CJ Bryan and Matt Olenick 7 years ago
parent 92dbd05a9a
commit 0c6722b563
  1. 15
      lib/explorer/forms/transaction_form.ex
  2. 6
      lib/explorer_web/templates/transaction/show.html.eex
  3. 11
      test/explorer/forms/transaction_form_test.exs

@ -17,6 +17,7 @@ defmodule Explorer.TransactionForm do
Map.merge(transaction, %{ Map.merge(transaction, %{
block_number: block |> block_number, block_number: block |> block_number,
age: block |> block_age, age: block |> block_age,
formatted_age: block |> format_age,
formatted_timestamp: block |> format_timestamp, formatted_timestamp: block |> format_timestamp,
cumulative_gas_used: block |> cumulative_gas_used, cumulative_gas_used: block |> cumulative_gas_used,
to_address: transaction |> to_address, to_address: transaction |> to_address,
@ -31,15 +32,23 @@ defmodule Explorer.TransactionForm do
end end
def block_age(block) do def block_age(block) do
block && block.timestamp |> Timex.from_now || "" block && block.timestamp |> Timex.from_now || "Pending"
end
def format_age(block) do
if block do
"#{block_age(block)} (#{format_timestamp(block)})"
else
gettext("Pending")
end
end end
def format_timestamp(block) do def format_timestamp(block) do
block && block.timestamp |> Timex.format!("%b-%d-%Y %H:%M:%S %p %Z", :strftime) || "" block && block.timestamp |> Timex.format!("%b-%d-%Y %H:%M:%S %p %Z", :strftime) || gettext("Pending")
end end
def cumulative_gas_used(block) do def cumulative_gas_used(block) do
block && block.gas_used |> Number.to_string! || "" block && block.gas_used |> Number.to_string! || gettext("Pending")
end end
def to_address(transaction) do def to_address(transaction) do

@ -31,7 +31,7 @@
</div> </div>
<div class="transaction__item"> <div class="transaction__item">
<dt class="transaction__item-key"><%= gettext "Age" %></dt> <dt class="transaction__item-key"><%= gettext "Age" %></dt>
<dd class="transaction__item-value" title="<%= @transaction.formatted_timestamp %>"><%= @transaction.age %> (<%= @transaction.formatted_timestamp %>)</dd> <dd class="transaction__item-value" title="<%= @transaction.formatted_timestamp %>"><%= @transaction.formatted_age %></dd>
</div> </div>
<div class="transaction__item"> <div class="transaction__item">
<dt class="transaction__item-key"><%= gettext "Value" %></dt> <dt class="transaction__item-key"><%= gettext "Value" %></dt>
@ -45,10 +45,6 @@
<dt class="transaction__item-key"><%= gettext "To" %></dt> <dt class="transaction__item-key"><%= gettext "To" %></dt>
<dd class="transaction__item-value"><%= link(@transaction.to_address, to: address_path(@conn, :show, @conn.assigns.locale, @transaction.to_address)) %></dd> <dd class="transaction__item-value"><%= link(@transaction.to_address, to: address_path(@conn, :show, @conn.assigns.locale, @transaction.to_address)) %></dd>
</div> </div>
<div class="transaction__item">
<dt class="transaction__item-key"><%= gettext "Value" %></dt>
<dd class="transaction__item-value"><%= @transaction.value %></dd>
</div>
</dl> </dl>
</div> </div>
<div class="transaction__column"> <div class="transaction__column">

@ -18,11 +18,13 @@ defmodule Explorer.TransactionFormTest do
|> with_addresses(%{to: "0xsleepypuppy", from: "0xilovefrogs"}) |> with_addresses(%{to: "0xsleepypuppy", from: "0xilovefrogs"})
|> Repo.preload(:block) |> Repo.preload(:block)
form = TransactionForm.build(transaction) form = TransactionForm.build(transaction)
formatted_timestamp = block.timestamp |> Timex.format!("%b-%d-%Y %H:%M:%S %p %Z", :strftime)
assert(form == Map.merge(transaction, %{ assert(form == Map.merge(transaction, %{
block_number: 1, block_number: 1,
age: "2 hours ago", age: "2 hours ago",
formatted_timestamp: block.timestamp |> Timex.format!("%b-%d-%Y %H:%M:%S %p %Z", :strftime), formatted_age: "2 hours ago (#{formatted_timestamp})",
formatted_timestamp: formatted_timestamp,
cumulative_gas_used: "99,523", cumulative_gas_used: "99,523",
to_address: "0xsleepypuppy", to_address: "0xsleepypuppy",
from_address: "0xilovefrogs", from_address: "0xilovefrogs",
@ -37,9 +39,10 @@ defmodule Explorer.TransactionFormTest do
assert(form == Map.merge(transaction, %{ assert(form == Map.merge(transaction, %{
block_number: "", block_number: "",
age: "", age: "Pending",
formatted_timestamp: "", formatted_age: "Pending",
cumulative_gas_used: "", formatted_timestamp: "Pending",
cumulative_gas_used: "Pending",
to_address: "0xchadmuska", to_address: "0xchadmuska",
from_address: "0xtonyhawk", from_address: "0xtonyhawk",
confirmations: 0, confirmations: 0,

Loading…
Cancel
Save