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 ### Features
### Fixes ### 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 - [#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 - [#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><%= name %></td>
<td><%= type %></td> <td><%= type %></td>
<td align=left> <td align=left>
<%= case BlockScoutWeb.ABIEncodedValueView.value_html(type, value) do %> <%= case BlockScoutWeb.ABIEncodedValueView.value_html(type, value, true) do %>
<% :error -> %> <% :error -> %>
<div class="alert alert-danger"> <div class="alert alert-danger">
<%= gettext "Error rendering value" %> <%= gettext "Error rendering value" %>
</div> </div>
<% _value -> %> <% value_with_no_links -> %>
<%= case BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) do %> <%= case BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) do %>
<% :error -> %> <% :error -> %>
<%= nil %> <%= nil %>
@ -50,9 +50,9 @@
</svg> </svg>
</span> </span>
<% end %> <% end %>
<% template = BlockScoutWeb.ABIEncodedValueView.value_html(type, value)%> <% value_with_links = BlockScoutWeb.ABIEncodedValueView.value_html(type, value, false)%>
<% string = template_to_string(template) %> <% 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 %><%= template %><% end %></code></pre> <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 %> <% end %>
</td> </td>
</tr> </tr>

@ -12,10 +12,12 @@ defmodule BlockScoutWeb.ABIEncodedValueView do
require Logger 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) decoded_type = FunctionSelector.decode_type(type)
do_value_html(decoded_type, value) do_value_html(decoded_type, value, no_links)
rescue rescue
exception -> exception ->
Logger.warn(fn -> Logger.warn(fn ->
@ -78,20 +80,20 @@ defmodule BlockScoutWeb.ABIEncodedValueView do
to_string(value) to_string(value)
end 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 defp do_value_html({:bytes, _}, value, no_links, depth) do
do_value_html(:bytes, value, depth) do_value_html(:bytes, value, no_links, depth)
end end
defp do_value_html({:array, type, _}, value, depth) do defp do_value_html({:array, type, _}, value, no_links, depth) do
do_value_html({:array, type}, value, depth) do_value_html({:array, type}, value, no_links, depth)
end end
defp do_value_html({:array, type}, value, depth) do defp do_value_html({:array, type}, value, no_links, depth) do
values = values =
Enum.map(value, fn inner_value -> 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) end)
spacing = String.duplicate(" ", depth * 2) spacing = String.duplicate(" ", depth * 2)
@ -100,44 +102,48 @@ defmodule BlockScoutWeb.ABIEncodedValueView do
~E|<%= spacing %>[<%= "\n" %><%= delimited %><%= "\n" %><%= spacing %>]| ~E|<%= spacing %>[<%= "\n" %><%= delimited %><%= "\n" %><%= spacing %>]|
end end
defp do_value_html({:tuple, types}, values, _) do defp do_value_html({:tuple, types}, values, no_links, _) do
values_list = values_list =
values values
|> Tuple.to_list() |> Tuple.to_list()
|> Enum.with_index() |> Enum.with_index()
|> Enum.map(fn {value, i} -> |> Enum.map(fn {value, i} ->
do_value_html(Enum.at(types, i), value) do_value_html(Enum.at(types, i), value, no_links)
end) end)
delimited = Enum.intersperse(values_list, ",") delimited = Enum.intersperse(values_list, ",")
~E|(<%= delimited %>)| ~E|(<%= delimited %>)|
end end
defp do_value_html(type, value, depth) do defp do_value_html(type, value, no_links, depth) do
spacing = String.duplicate(" ", depth * 2) spacing = String.duplicate(" ", depth * 2)
~E|<%= spacing %><%=base_value_html(type, value)%>| ~E|<%= spacing %><%=base_value_html(type, value, no_links)%>|
[spacing, base_value_html(type, value)] [spacing, base_value_html(type, value, no_links)]
end end
defp base_value_html(_, {:dynamic, value}) do defp base_value_html(_, {:dynamic, value}, _no_links) do
~E|<%= hex(value) %>| ~E|<%= hex(value) %>|
end end
defp base_value_html(:address, value) do defp base_value_html(:address, value, no_links) do
address = hex(value) 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 end
defp base_value_html(:address_text, value) do defp base_value_html(:address_text, value, _no_links) do
~E|<%= hex(value) %>| ~E|<%= hex(value) %>|
end end
defp base_value_html(:bytes, value) do defp base_value_html(:bytes, value, _no_links) do
~E|<%= hex(value) %>| ~E|<%= hex(value) %>|
end 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) defp hex(value), do: "0x" <> Base.encode16(value, case: :lower)
end end

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

Loading…
Cancel
Save