From 0e4de060994358325fb0264fc513954e0097ae56 Mon Sep 17 00:00:00 2001 From: nikitosing Date: Thu, 23 Dec 2021 18:55:21 +0300 Subject: [PATCH] Fix broken functions input --- CHANGELOG.md | 1 + .../transaction/_decoded_input_body.html.eex | 10 ++-- .../views/abi_encoded_value_view.ex | 48 +++++++++++-------- .../block_scout_web/views/transaction_view.ex | 2 +- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d93cab758..97ce72437c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features ### Fixes +- [#5034](https://github.com/blockscout/blockscout/pull/5034) - Fix broken functions input at transation page - [#5025](https://github.com/blockscout/blockscout/pull/5025) - Add standard input JSON files validation - [#5051](https://github.com/blockscout/blockscout/pull/5051) - Fix 500 response when ABI method was parsed as nil diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex index c0c84d459f..3675d4c501 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex @@ -27,12 +27,12 @@ <%= name %> <%= type %> - <%= case BlockScoutWeb.ABIEncodedValueView.value_html(type, value) do %> + <%= case BlockScoutWeb.ABIEncodedValueView.value_html(type, value, true) do %> <% :error -> %>
<%= gettext "Error rendering value" %>
- <% _value -> %> + <% value_with_no_links -> %> <%= case BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) do %> <% :error -> %> <%= nil %> @@ -50,9 +50,9 @@ <% end %> - <% template = BlockScoutWeb.ABIEncodedValueView.value_html(type, value)%> - <% string = template_to_string(template) %> -
<%= if String.length(string) > max_length do %>
<% input = trim(max_length, string) %><%= input[:show] %>...<%= input[:hide] %>
<% else %><%= template %><% end %>
+ <% value_with_links = BlockScoutWeb.ABIEncodedValueView.value_html(type, value, false)%> + <% string = template_to_string(value_with_no_links) %> +
<%= if String.length(string) > max_length do %>
<% input = trim(max_length, string) %><%= input[:show] %>...<%= input[:hide] %>
<% else %><%= value_with_links %><% end %>
<% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/views/abi_encoded_value_view.ex b/apps/block_scout_web/lib/block_scout_web/views/abi_encoded_value_view.ex index aad184898a..0f09ce2302 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/abi_encoded_value_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/abi_encoded_value_view.ex @@ -12,10 +12,12 @@ defmodule BlockScoutWeb.ABIEncodedValueView do require Logger - def value_html(type, value) do + def value_html(type, value, no_links \\ false) + + def value_html(type, value, no_links) do decoded_type = FunctionSelector.decode_type(type) - do_value_html(decoded_type, value) + do_value_html(decoded_type, value, no_links) rescue exception -> Logger.warn(fn -> @@ -78,20 +80,20 @@ defmodule BlockScoutWeb.ABIEncodedValueView do to_string(value) end - defp do_value_html(type, value, depth \\ 0) + defp do_value_html(type, value, no_links, depth \\ 0) - defp do_value_html({:bytes, _}, value, depth) do - do_value_html(:bytes, value, depth) + defp do_value_html({:bytes, _}, value, no_links, depth) do + do_value_html(:bytes, value, no_links, depth) end - defp do_value_html({:array, type, _}, value, depth) do - do_value_html({:array, type}, value, depth) + defp do_value_html({:array, type, _}, value, no_links, depth) do + do_value_html({:array, type}, value, no_links, depth) end - defp do_value_html({:array, type}, value, depth) do + defp do_value_html({:array, type}, value, no_links, depth) do values = Enum.map(value, fn inner_value -> - do_value_html(type, inner_value, depth + 1) + do_value_html(type, inner_value, no_links, depth + 1) end) spacing = String.duplicate(" ", depth * 2) @@ -100,44 +102,48 @@ defmodule BlockScoutWeb.ABIEncodedValueView do ~E|<%= spacing %>[<%= "\n" %><%= delimited %><%= "\n" %><%= spacing %>]| end - defp do_value_html({:tuple, types}, values, _) do + defp do_value_html({:tuple, types}, values, no_links, _) do values_list = values |> Tuple.to_list() |> Enum.with_index() |> Enum.map(fn {value, i} -> - do_value_html(Enum.at(types, i), value) + do_value_html(Enum.at(types, i), value, no_links) end) delimited = Enum.intersperse(values_list, ",") ~E|(<%= delimited %>)| end - defp do_value_html(type, value, depth) do + defp do_value_html(type, value, no_links, depth) do spacing = String.duplicate(" ", depth * 2) - ~E|<%= spacing %><%=base_value_html(type, value)%>| - [spacing, base_value_html(type, value)] + ~E|<%= spacing %><%=base_value_html(type, value, no_links)%>| + [spacing, base_value_html(type, value, no_links)] end - defp base_value_html(_, {:dynamic, value}) do + defp base_value_html(_, {:dynamic, value}, _no_links) do ~E|<%= hex(value) %>| end - defp base_value_html(:address, value) do - address = hex(value) + defp base_value_html(:address, value, no_links) do + if no_links do + base_value_html(:address_text, value, no_links) + else + address = hex(value) - ~E|<%= address %>| + ~E|<%= address %>| + end end - defp base_value_html(:address_text, value) do + defp base_value_html(:address_text, value, _no_links) do ~E|<%= hex(value) %>| end - defp base_value_html(:bytes, value) do + defp base_value_html(:bytes, value, _no_links) do ~E|<%= hex(value) %>| end - defp base_value_html(_, value), do: HTML.html_escape(value) + defp base_value_html(_, value, _no_links), do: HTML.html_escape(value) defp hex(value), do: "0x" <> Base.encode16(value, case: :lower) end diff --git a/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex b/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex index 85c22f3a1b..ab2be5a31e 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex @@ -550,7 +550,7 @@ defmodule BlockScoutWeb.TransactionView do case Integer.parse(string_value) do {integer, ""} -> integer - _ -> 0 + _ -> 2040 end end