chore: cleanup, error handling, tests

pull/1119/head
zachdaniel 6 years ago
parent a2f01eccae
commit 8f05ada7f4
  1. 22
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_decoded_input.html.eex
  2. 13
      apps/block_scout_web/lib/block_scout_web/templates/transaction_log/index.html.eex
  3. 4
      apps/block_scout_web/lib/block_scout_web/views/abi_encoded_value_view.ex
  4. 19
      apps/block_scout_web/priv/gettext/default.pot
  5. 19
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  6. 33
      apps/block_scout_web/test/block_scout_web/views/abi_encoded_value_view_test.exs

@ -35,15 +35,27 @@
<%= for {name, type, value} <- mapping do %> <%= for {name, type, value} <- mapping do %>
<tr> <tr>
<th scope="row"> <th scope="row">
<% copy_text = BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) %> <%= case BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) do %>
<button type="button" class="copy icon-link" data-toggle="tooltip" data-placement="top" data-clipboard-text="<%= copy_text %>" aria-label="Copy Value"> <% :error -> %>
<i class="fas fa-clone"></i> <%= nil %>
</button> <% copy_text -> %>
<button type="button" class="copy icon-link" data-toggle="tooltip" data-placement="top" data-clipboard-text="<%= copy_text %>" aria-label="Copy Value">
<i class="fas fa-clone"></i>
</button>
<% end %>
</th> </th>
<td><%= name %></td> <td><%= name %></td>
<td><%= type %></td> <td><%= type %></td>
<td> <td>
<pre class="transaction-input-text tile"><code><%= BlockScoutWeb.ABIEncodedValueView.value_html(type, value) %></code></pre> <%= case BlockScoutWeb.ABIEncodedValueView.value_html(type, value) do %>
<% :error -> %>
<div class="alert alert-danger">
<%= gettext "Error rendering value" %>
</div>
<% value -> %>
<pre class="transaction-input-text tile"><code><%= value %></code></pre>
<% end %>
</td> </td>
</tr> </tr>
<% end %> <% end %>

@ -56,11 +56,14 @@
<%= for {name, type, indexed?, value} <- mapping do %> <%= for {name, type, indexed?, value} <- mapping do %>
<tr> <tr>
<th scope="row"> <th scope="row">
<% copy_text = BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) %> <%= case BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) do %>
<% :error -> %>
<button type="button" class="copy icon-link" data-toggle="tooltip" data-placement="top" data-clipboard-text="<%= copy_text %>" aria-label="Copy Value"> <%= nil %>
<i class="fas fa-clone"></i> <% copy_text -> %>
</button> <button type="button" class="copy icon-link" data-toggle="tooltip" data-placement="top" data-clipboard-text="<%= copy_text %>" aria-label="Copy Value">
<i class="fas fa-clone"></i>
</button>
<% end %>
</th> </th>
<td><%= name %></td> <td><%= name %></td>
<td><%= type %></td> <td><%= type %></td>

@ -21,6 +21,8 @@ defmodule BlockScoutWeb.ABIEncodedValueView do
Logger.warn(fn -> Logger.warn(fn ->
["Error determining value html for #{inspect(type)}: ", Exception.format(:error, exception)] ["Error determining value html for #{inspect(type)}: ", Exception.format(:error, exception)]
end) end)
:error
end end
def copy_text(type, value) do def copy_text(type, value) do
@ -32,6 +34,8 @@ defmodule BlockScoutWeb.ABIEncodedValueView do
Logger.warn(fn -> Logger.warn(fn ->
["Error determining copy text for #{inspect(type)}: ", Exception.format(:error, exception)] ["Error determining copy text for #{inspect(type)}: ", Exception.format(:error, exception)]
end) end)
:error
end end
def do_copy_text({:bytes, _type}, value) do def do_copy_text({:bytes, _type}, value) do

@ -357,7 +357,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:33 #: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:33
#: lib/block_scout_web/templates/transaction_log/index.html.eex:54 #: lib/block_scout_web/templates/transaction_log/index.html.eex:54
#: lib/block_scout_web/templates/transaction_log/index.html.eex:115 #: lib/block_scout_web/templates/transaction_log/index.html.eex:118
msgid "Data" msgid "Data"
msgstr "" msgstr ""
@ -601,7 +601,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: #:
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:23 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:23
#: lib/block_scout_web/templates/transaction_log/index.html.eex:142 #: lib/block_scout_web/templates/transaction_log/index.html.eex:145
msgid "Newer" msgid "Newer"
msgstr "" msgstr ""
@ -823,7 +823,7 @@ msgid "There are no internal transactions for this transaction."
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction_log/index.html.eex:136 #: lib/block_scout_web/templates/transaction_log/index.html.eex:139
msgid "There are no logs for this transaction." msgid "There are no logs for this transaction."
msgstr "" msgstr ""
@ -935,7 +935,7 @@ msgid "Top Accounts - %{subnetwork} Explorer"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction_log/index.html.eex:79 #: lib/block_scout_web/templates/transaction_log/index.html.eex:82
msgid "Topics" msgid "Topics"
msgstr "" msgstr ""
@ -1329,12 +1329,12 @@ msgid "Indexed?"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction_log/index.html.eex:120 #: lib/block_scout_web/templates/transaction_log/index.html.eex:123
msgid "Show Raw Data" msgid "Show Raw Data"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction_log/index.html.eex:82 #: lib/block_scout_web/templates/transaction_log/index.html.eex:85
msgid "Show Raw Topics" msgid "Show Raw Topics"
msgstr "" msgstr ""
@ -1375,6 +1375,11 @@ msgid "here"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:53 #: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:65
msgid "Failed to decode input data." msgid "Failed to decode input data."
msgstr "" msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:53
msgid "Error rendering value"
msgstr ""

@ -357,7 +357,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:33 #: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:33
#: lib/block_scout_web/templates/transaction_log/index.html.eex:54 #: lib/block_scout_web/templates/transaction_log/index.html.eex:54
#: lib/block_scout_web/templates/transaction_log/index.html.eex:115 #: lib/block_scout_web/templates/transaction_log/index.html.eex:118
msgid "Data" msgid "Data"
msgstr "" msgstr ""
@ -601,7 +601,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: #:
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:23 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:23
#: lib/block_scout_web/templates/transaction_log/index.html.eex:142 #: lib/block_scout_web/templates/transaction_log/index.html.eex:145
msgid "Newer" msgid "Newer"
msgstr "" msgstr ""
@ -823,7 +823,7 @@ msgid "There are no internal transactions for this transaction."
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction_log/index.html.eex:136 #: lib/block_scout_web/templates/transaction_log/index.html.eex:139
msgid "There are no logs for this transaction." msgid "There are no logs for this transaction."
msgstr "" msgstr ""
@ -935,7 +935,7 @@ msgid "Top Accounts - %{subnetwork} Explorer"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction_log/index.html.eex:79 #: lib/block_scout_web/templates/transaction_log/index.html.eex:82
msgid "Topics" msgid "Topics"
msgstr "" msgstr ""
@ -1329,12 +1329,12 @@ msgid "Indexed?"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction_log/index.html.eex:120 #: lib/block_scout_web/templates/transaction_log/index.html.eex:123
msgid "Show Raw Data" msgid "Show Raw Data"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction_log/index.html.eex:82 #: lib/block_scout_web/templates/transaction_log/index.html.eex:85
msgid "Show Raw Topics" msgid "Show Raw Topics"
msgstr "" msgstr ""
@ -1375,6 +1375,11 @@ msgid "here"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:53 #: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:65
msgid "Failed to decode input data." msgid "Failed to decode input data."
msgstr "" msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:53
msgid "Error rendering value"
msgstr ""

@ -6,6 +6,13 @@ defmodule BlockScoutWeb.ABIEncodedValueViewTest do
defp value_html(type, value) do defp value_html(type, value) do
type type
|> ABIEncodedValueView.value_html(value) |> ABIEncodedValueView.value_html(value)
|> case do
:error ->
raise "failed to generate html"
other ->
other
end
|> Phoenix.HTML.Safe.to_iodata() |> Phoenix.HTML.Safe.to_iodata()
|> IO.iodata_to_binary() |> IO.iodata_to_binary()
end end
@ -13,6 +20,13 @@ defmodule BlockScoutWeb.ABIEncodedValueViewTest do
defp copy_text(type, value) do defp copy_text(type, value) do
type type
|> ABIEncodedValueView.copy_text(value) |> ABIEncodedValueView.copy_text(value)
|> case do
:error ->
raise "failed to generate copy text"
other ->
other
end
|> Phoenix.HTML.Safe.to_iodata() |> Phoenix.HTML.Safe.to_iodata()
|> IO.iodata_to_binary() |> IO.iodata_to_binary()
end end
@ -75,7 +89,11 @@ defmodule BlockScoutWeb.ABIEncodedValueViewTest do
address_bytes = "0x0000000000000000000000000000000000000000" |> String.trim_leading("0x") |> Base.decode16!() address_bytes = "0x0000000000000000000000000000000000000000" |> String.trim_leading("0x") |> Base.decode16!()
assert value_html("address[]", [address_bytes, address_bytes, address_bytes, address_bytes]) == expected assert value_html("address[4]", [address_bytes, address_bytes, address_bytes, address_bytes]) == expected
end
test "it renders :dynamic values as bytes" do
assert value_html("uint", {:dynamic, <<1>>}) == "0x01"
end end
end end
@ -88,7 +106,18 @@ defmodule BlockScoutWeb.ABIEncodedValueViewTest do
end end
test "it skips the formatting when copying lists" do test "it skips the formatting when copying lists" do
assert copy_text("uint[]", [1, 2, 3, 4]) == "[1, 2, 3, 4]" assert copy_text("uint[4]", [1, 2, 3, 4]) == "[1, 2, 3, 4]"
end
test "it copies bytes as their hex representation" do
hex = "0xffffff"
bytes = hex |> String.trim_leading("0x") |> Base.decode16!(case: :lower)
assert copy_text("bytes", bytes) == hex
end
test "it copies :dynamic values as bytes" do
assert copy_text("uint", {:dynamic, <<1>>}) == "0x01"
end end
end end
end end

Loading…
Cancel
Save