From 0c6722b56300031d24988cecd903b062878c8cd2 Mon Sep 17 00:00:00 2001 From: CJ Bryan and Matt Olenick Date: Wed, 7 Feb 2018 11:26:35 -0800 Subject: [PATCH] Update transactions show page to display pending for incomplete block information --- lib/explorer/forms/transaction_form.ex | 15 ++++++++++++--- .../templates/transaction/show.html.eex | 6 +----- test/explorer/forms/transaction_form_test.exs | 11 +++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/explorer/forms/transaction_form.ex b/lib/explorer/forms/transaction_form.ex index 6cc77211d4..2d5836b6c0 100644 --- a/lib/explorer/forms/transaction_form.ex +++ b/lib/explorer/forms/transaction_form.ex @@ -17,6 +17,7 @@ defmodule Explorer.TransactionForm do Map.merge(transaction, %{ block_number: block |> block_number, age: block |> block_age, + formatted_age: block |> format_age, formatted_timestamp: block |> format_timestamp, cumulative_gas_used: block |> cumulative_gas_used, to_address: transaction |> to_address, @@ -31,15 +32,23 @@ defmodule Explorer.TransactionForm do end 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 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 def cumulative_gas_used(block) do - block && block.gas_used |> Number.to_string! || "" + block && block.gas_used |> Number.to_string! || gettext("Pending") end def to_address(transaction) do diff --git a/lib/explorer_web/templates/transaction/show.html.eex b/lib/explorer_web/templates/transaction/show.html.eex index 71db5f7b84..5bf37d6e9f 100644 --- a/lib/explorer_web/templates/transaction/show.html.eex +++ b/lib/explorer_web/templates/transaction/show.html.eex @@ -31,7 +31,7 @@
<%= gettext "Age" %>
-
<%= @transaction.age %> (<%= @transaction.formatted_timestamp %>)
+
<%= @transaction.formatted_age %>
<%= gettext "Value" %>
@@ -45,10 +45,6 @@
<%= gettext "To" %>
<%= link(@transaction.to_address, to: address_path(@conn, :show, @conn.assigns.locale, @transaction.to_address)) %>
-
-
<%= gettext "Value" %>
-
<%= @transaction.value %>
-
diff --git a/test/explorer/forms/transaction_form_test.exs b/test/explorer/forms/transaction_form_test.exs index 1de6dc5111..75b61a7d94 100644 --- a/test/explorer/forms/transaction_form_test.exs +++ b/test/explorer/forms/transaction_form_test.exs @@ -18,11 +18,13 @@ defmodule Explorer.TransactionFormTest do |> with_addresses(%{to: "0xsleepypuppy", from: "0xilovefrogs"}) |> Repo.preload(:block) form = TransactionForm.build(transaction) + formatted_timestamp = block.timestamp |> Timex.format!("%b-%d-%Y %H:%M:%S %p %Z", :strftime) assert(form == Map.merge(transaction, %{ block_number: 1, 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", to_address: "0xsleepypuppy", from_address: "0xilovefrogs", @@ -37,9 +39,10 @@ defmodule Explorer.TransactionFormTest do assert(form == Map.merge(transaction, %{ block_number: "", - age: "", - formatted_timestamp: "", - cumulative_gas_used: "", + age: "Pending", + formatted_age: "Pending", + formatted_timestamp: "Pending", + cumulative_gas_used: "Pending", to_address: "0xchadmuska", from_address: "0xtonyhawk", confirmations: 0,