Method name in tx tile

pull/3834/head
Viktor Baranov 4 years ago
parent 41fe715f7d
commit f4ce189e61
  1. 1
      CHANGELOG.md
  2. 3
      apps/block_scout_web/assets/css/components/_label.scss
  3. 6
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex
  4. 12
      apps/block_scout_web/priv/gettext/default.pot
  5. 12
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  6. 44
      apps/explorer/lib/explorer/chain/transaction.ex

@ -1,6 +1,7 @@
## Current
### Features
- [#3834](https://github.com/blockscout/blockscout/pull/3834) - Method name in tx tile
- [#3792](https://github.com/blockscout/blockscout/pull/3792) - Cancel pending transaction
- [#3786](https://github.com/blockscout/blockscout/pull/3786) - Read contract: enable methods with StateMutability: pure
- [#3758](https://github.com/blockscout/blockscout/pull/3758) - Add pool metadata display/change to Staking DApp

@ -39,6 +39,9 @@
background: $secondary;
color: #fff;
}
&.method {
color: #1e2022;
}
&.from-dropdown {
margin-top: -3px;
}

@ -18,7 +18,13 @@
</div>
<!-- Content -->
<div class="col-md-7 col-lg-8 d-flex flex-column pr-2 pr-sm-2 pr-md-0">
<span>
<%= render "_link.html", transaction_hash: @transaction.hash %>
<% method_name = Transaction.get_method_name(@transaction) %>
<%= if method_name do %>
<%= render BlockScoutWeb.FormView, "_tag.html", text: method_name, additional_classes: ["method", "ml-1"] %>
<% end %>
</span>
<span>
<%= @transaction |> BlockScoutWeb.AddressView.address_partial_selector(:from, assigns[:current_address]) |> BlockScoutWeb.RenderHelpers.render_partial() %>
&rarr;

@ -633,7 +633,7 @@ msgstr ""
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:20
#: lib/block_scout_web/templates/layout/app.html.eex:33
#: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20
#: lib/block_scout_web/templates/transaction/_tile.html.eex:29
#: lib/block_scout_web/templates/transaction/_tile.html.eex:35
#: lib/block_scout_web/templates/transaction/overview.html.eex:215
#: lib/block_scout_web/templates/transaction/overview.html.eex:268
#: lib/block_scout_web/views/wei_helpers.ex:78
@ -759,7 +759,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:38
#: lib/block_scout_web/templates/transaction/_tile.html.eex:72
#: lib/block_scout_web/templates/transaction/_tile.html.eex:78
msgid "IN"
msgstr ""
@ -777,7 +777,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:21
#: lib/block_scout_web/templates/transaction/_tile.html.eex:32
#: lib/block_scout_web/templates/transaction/_tile.html.eex:38
#: lib/block_scout_web/templates/transaction/overview.html.eex:118
msgid "TX Fee"
msgstr ""
@ -1104,7 +1104,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:36
#: lib/block_scout_web/templates/transaction/_tile.html.eex:68
#: lib/block_scout_web/templates/transaction/_tile.html.eex:74
msgid "OUT"
msgstr ""
@ -1610,12 +1610,12 @@ msgid "View Contract"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:53
#: lib/block_scout_web/templates/transaction/_tile.html.eex:59
msgid "View Less Transfers"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:52
#: lib/block_scout_web/templates/transaction/_tile.html.eex:58
msgid "View More Transfers"
msgstr ""

@ -633,7 +633,7 @@ msgstr ""
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:20
#: lib/block_scout_web/templates/layout/app.html.eex:33
#: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20
#: lib/block_scout_web/templates/transaction/_tile.html.eex:29
#: lib/block_scout_web/templates/transaction/_tile.html.eex:35
#: lib/block_scout_web/templates/transaction/overview.html.eex:215
#: lib/block_scout_web/templates/transaction/overview.html.eex:268
#: lib/block_scout_web/views/wei_helpers.ex:78
@ -759,7 +759,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:38
#: lib/block_scout_web/templates/transaction/_tile.html.eex:72
#: lib/block_scout_web/templates/transaction/_tile.html.eex:78
msgid "IN"
msgstr ""
@ -777,7 +777,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:21
#: lib/block_scout_web/templates/transaction/_tile.html.eex:32
#: lib/block_scout_web/templates/transaction/_tile.html.eex:38
#: lib/block_scout_web/templates/transaction/overview.html.eex:118
msgid "TX Fee"
msgstr ""
@ -1104,7 +1104,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:36
#: lib/block_scout_web/templates/transaction/_tile.html.eex:68
#: lib/block_scout_web/templates/transaction/_tile.html.eex:74
msgid "OUT"
msgstr ""
@ -1610,12 +1610,12 @@ msgid "View Contract"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:53
#: lib/block_scout_web/templates/transaction/_tile.html.eex:59
msgid "View Less Transfers"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_tile.html.eex:52
#: lib/block_scout_web/templates/transaction/_tile.html.eex:58
msgid "View More Transfers"
msgstr ""

@ -476,6 +476,50 @@ defmodule Explorer.Chain.Transaction do
do: {:ok, identifier, text, mapping}
end
def get_method_name(
%__MODULE__{
input: %{bytes: <<method_id::binary-size(4), _::binary>>}
} = transaction
) do
case Transaction.decoded_input_data(%__MODULE__{
to_address: %{smart_contract: nil},
input: transaction.input,
hash: transaction.hash
}) do
{:error, :contract_not_verified, [{:ok, _method_id, decoded_func, _}]} ->
parse_method_name(decoded_func)
{:error, :contract_not_verified, []} ->
"0x" <> Base.encode16(method_id, case: :lower)
_ ->
"Transfer"
end
end
def get_method_name(_), do: "Transfer"
defp parse_method_name(method_desc) do
method_desc
|> String.split("(")
|> Enum.at(0)
|> upcase_first
|> String.split(~r/(?<=[A-Z])|(?=[A-Z])/)
|> Enum.reduce("", fn string, acc ->
if acc == "" do
string
else
if string =~ ~r/^\p{Lu}$/u do
acc <> " " <> string
else
acc <> string
end
end
end)
end
defp upcase_first(<<first::utf8, rest::binary>>), do: String.upcase(<<first::utf8>>) <> rest
defp function_call(name, mapping) do
text =
mapping

Loading…
Cancel
Save