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 %>
<tr>
<th scope="row">
<% copy_text = BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) %>
<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>
<%= case BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) do %>
<% :error -> %>
<%= nil %>
<% 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>
<td><%= name %></td>
<td><%= type %></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>
</tr>
<% end %>

@ -56,11 +56,14 @@
<%= for {name, type, indexed?, value} <- mapping do %>
<tr>
<th scope="row">
<% copy_text = BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) %>
<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>
<%= case BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) do %>
<% :error -> %>
<%= nil %>
<% 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>
<td><%= name %></td>
<td><%= type %></td>

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

@ -357,7 +357,7 @@ msgstr ""
#, elixir-format
#: 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:115
#: lib/block_scout_web/templates/transaction_log/index.html.eex:118
msgid "Data"
msgstr ""
@ -601,7 +601,7 @@ msgstr ""
#, elixir-format
#:
#: 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"
msgstr ""
@ -823,7 +823,7 @@ msgid "There are no internal transactions for this transaction."
msgstr ""
#, 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."
msgstr ""
@ -935,7 +935,7 @@ msgid "Top Accounts - %{subnetwork} Explorer"
msgstr ""
#, 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"
msgstr ""
@ -1329,12 +1329,12 @@ msgid "Indexed?"
msgstr ""
#, 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"
msgstr ""
#, 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"
msgstr ""
@ -1375,6 +1375,11 @@ msgid "here"
msgstr ""
#, 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."
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
#: 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:115
#: lib/block_scout_web/templates/transaction_log/index.html.eex:118
msgid "Data"
msgstr ""
@ -601,7 +601,7 @@ msgstr ""
#, elixir-format
#:
#: 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"
msgstr ""
@ -823,7 +823,7 @@ msgid "There are no internal transactions for this transaction."
msgstr ""
#, 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."
msgstr ""
@ -935,7 +935,7 @@ msgid "Top Accounts - %{subnetwork} Explorer"
msgstr ""
#, 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"
msgstr ""
@ -1329,12 +1329,12 @@ msgid "Indexed?"
msgstr ""
#, 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"
msgstr ""
#, 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"
msgstr ""
@ -1375,6 +1375,11 @@ msgid "here"
msgstr ""
#, 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."
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
type
|> ABIEncodedValueView.value_html(value)
|> case do
:error ->
raise "failed to generate html"
other ->
other
end
|> Phoenix.HTML.Safe.to_iodata()
|> IO.iodata_to_binary()
end
@ -13,6 +20,13 @@ defmodule BlockScoutWeb.ABIEncodedValueViewTest do
defp copy_text(type, value) do
type
|> ABIEncodedValueView.copy_text(value)
|> case do
:error ->
raise "failed to generate copy text"
other ->
other
end
|> Phoenix.HTML.Safe.to_iodata()
|> IO.iodata_to_binary()
end
@ -75,7 +89,11 @@ defmodule BlockScoutWeb.ABIEncodedValueViewTest do
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
@ -88,7 +106,18 @@ defmodule BlockScoutWeb.ABIEncodedValueViewTest do
end
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

Loading…
Cancel
Save