Fix broken functions input

pull/5034/head
nikitosing 3 years ago
parent 871327dbde
commit 0e4de06099
  1. 1
      CHANGELOG.md
  2. 10
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex
  3. 48
      apps/block_scout_web/lib/block_scout_web/views/abi_encoded_value_view.ex
  4. 2
      apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex

@ -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

@ -27,12 +27,12 @@
<td><%= name %></td>
<td><%= type %></td>
<td align=left>
<%= case BlockScoutWeb.ABIEncodedValueView.value_html(type, value) do %>
<%= case BlockScoutWeb.ABIEncodedValueView.value_html(type, value, true) do %>
<% :error -> %>
<div class="alert alert-danger">
<%= gettext "Error rendering value" %>
</div>
<% _value -> %>
<% value_with_no_links -> %>
<%= case BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) do %>
<% :error -> %>
<%= nil %>
@ -50,9 +50,9 @@
</svg>
</span>
<% end %>
<% template = BlockScoutWeb.ABIEncodedValueView.value_html(type, value)%>
<% string = template_to_string(template) %>
<pre class="transaction-input-text pre-wrap" style="margin-bottom: 0px;"><code style="line-height: 25px;"><%= if String.length(string) > max_length do %><div data-input-container><% input = trim(max_length, string) %><%= input[:show] %><span data-placeholder-dots>...</span><button type="button" class="btn-line" id="button-expand" aria-label="Expand" button-expand-input><%= gettext "Expand" %></button><span class="more d-none" data-hidden-text><%= input[:hide] %></span><button type="button" class="btn-line d-none" aria-label="Collapse" button-collapse-input><%= gettext "Collapse" %></button></div><% else %><%= template %><% end %></code></pre>
<% value_with_links = BlockScoutWeb.ABIEncodedValueView.value_html(type, value, false)%>
<% string = template_to_string(value_with_no_links) %>
<pre class="transaction-input-text pre-wrap" style="margin-bottom: 0px;"><code style="line-height: 25px;"><%= if String.length(string) > max_length do %><div data-input-container><% input = trim(max_length, string) %><%= input[:show] %><span data-placeholder-dots>...</span><button type="button" class="btn-line" id="button-expand" aria-label="Expand" button-expand-input><%= gettext "Expand" %></button><span class="more d-none" data-hidden-text><%= input[:hide] %></span><button type="button" class="btn-line d-none" aria-label="Collapse" button-collapse-input><%= gettext "Collapse" %></button></div><% else %><%= value_with_links %><% end %></code></pre>
<% end %>
</td>
</tr>

@ -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|<a href="<%= address_path(BlockScoutWeb.Endpoint, :show, address) %>" target="_blank"><%= address %></a>|
~E|<a href="<%= address_path(BlockScoutWeb.Endpoint, :show, address) %>" target="_blank"><%= address %></a>|
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

@ -550,7 +550,7 @@ defmodule BlockScoutWeb.TransactionView do
case Integer.parse(string_value) do
{integer, ""} -> integer
_ -> 0
_ -> 2040
end
end

Loading…
Cancel
Save