diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex index f79d9aa08d..56be858452 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex @@ -6,13 +6,15 @@ defmodule BlockScoutWeb.AddressLogsController do import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1] import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1] + alias BlockScoutWeb.AddressLogsView alias Explorer.{Chain, Market} alias Explorer.ExchangeRates.Token alias Indexer.Fetcher.CoinBalanceOnDemand + alias Phoenix.View use BlockScoutWeb, :controller - def index(conn, %{"address_id" => address_hash_string} = params) do + def index(conn, %{"address_id" => address_hash_string, "type" => "JSON"} = params) do with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), {:ok, address} <- Chain.hash_to_address(address_hash) do logs_plus_one = Chain.address_to_logs(address, paging_options(params)) @@ -24,19 +26,45 @@ defmodule BlockScoutWeb.AddressLogsController do nil next_page_params -> - address_logs_path(conn, :index, address, next_page_params) + address_logs_path(conn, :index, address, Map.delete(next_page_params, "type")) end + items = + results + |> Enum.map(fn log -> + View.render_to_string( + AddressLogsView, + "_logs.html", + log: log, + conn: conn + ) + end) + + json( + conn, + %{ + items: items, + next_page_path: next_page_url + } + ) + else + _ -> + not_found(conn) + end + end + + def index(conn, %{"address_id" => address_hash_string}) do + with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), + {:ok, address} <- Chain.hash_to_address(address_hash) do render( conn, "index.html", address: address, - logs: results, + current_path: current_path(conn), coin_balance_status: CoinBalanceOnDemand.trigger_fetch(address), exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), transaction_count: transaction_count(address), - validation_count: validation_count(address), - next_page_url: next_page_url + validation_count: validation_count(address) ) else _ -> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex new file mode 100644 index 0000000000..9d85567233 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex @@ -0,0 +1,54 @@ +
+
+
<%= gettext "Transaction" %>
+
+

+ <%= link( + @log.transaction, + to: transaction_path(@conn, :show, @log.transaction), + "data-test": "log_address_link", + "data-address-hash": @log.transaction + ) %> +

+
+
<%= gettext "Topics" %>
+
+
+ <%= unless is_nil(@log.first_topic) do %> +
+ [0] + <%= @log.first_topic %> +
+ <% end %> + <%= unless is_nil(@log.second_topic) do %> +
+ [1] + <%= @log.second_topic %> +
+ <% end %> + <%= unless is_nil(@log.third_topic) do %> +
+ [2] + <%= @log.third_topic %> +
+ <% end %> + <%= unless is_nil(@log.fourth_topic) do %> +
+ [3] + <%= @log.fourth_topic %> +
+ <% end %> +
+
+
+ <%= gettext "Data" %> +
+
+ <%= unless is_nil(@log.data) do %> +
+ <%= @log.data %> +
+ <% end %> +
+
+
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex index 22f446924f..9053158442 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex @@ -3,80 +3,26 @@
<%= render BlockScoutWeb.AddressView, "_tabs.html", assigns %> -
- +

<%= gettext "Logs" %>

- <%= if @next_page_url do %> - <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true, next_page_path: @next_page_url %> - <% end %> + <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> - <%= if !@next_page_url do %> - <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true %> - <% end %> + - <%= if Enum.count(@logs) > 0 do %> - <%= for log <- @logs do %> -
-
-
<%= gettext "Transaction" %>
-
-

- <%= link( - log.transaction, - to: transaction_path(@conn, :show, log.transaction), - "data-test": "log_address_link", - "data-address-hash": log.transaction - ) %> -

-
-
<%= gettext "Topics" %>
-
-
- <%= unless is_nil(log.first_topic) do %> -
- [0] - <%= log.first_topic %> -
- <% end %> - <%= unless is_nil(log.second_topic) do %> -
- [1] - <%= log.second_topic %> -
- <% end %> - <%= unless is_nil(log.third_topic) do %> -
- [2] - <%= log.third_topic %> -
- <% end %> - <%= unless is_nil(log.fourth_topic) do %> -
- [3] - <%= log.fourth_topic %> -
- <% end %> -
-
-
- <%= gettext "Data" %> -
-
- <%= unless is_nil(log.data) do %> -
- <%= log.data %> -
- <% end %> -
-
+
+
+ <%= gettext "There are no logs for this address." %>
- <% end %> - <% else %> -
- <%= gettext "There are no logs for this address." %> -
- <% end %> +
+ +
+ + <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> +
+
diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 1de0664736..8f9a685d5e 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -329,7 +329,7 @@ msgid "Curl" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:63 +#: lib/block_scout_web/templates/address_logs/_logs.html.eex:44 #: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:18 #: lib/block_scout_web/templates/transaction_log/index.html.eex:67 #: lib/block_scout_web/templates/transaction_log/index.html.eex:133 @@ -502,7 +502,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:26 -#: lib/block_scout_web/templates/address_logs/index.html.eex:8 +#: lib/block_scout_web/templates/address_logs/index.html.eex:7 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: lib/block_scout_web/templates/transaction_log/index.html.eex:8 #: lib/block_scout_web/views/address_view.ex:301 @@ -576,11 +576,6 @@ msgstr "" msgid "Newer" msgstr "" -#, elixir-format -#: lib/block_scout_web/templates/address_token/index.html.eex:39 -msgid "Next" -msgstr "" - #, elixir-format #: lib/block_scout_web/templates/tokens/inventory/index.html.eex:32 msgid "Next Page" @@ -765,7 +760,7 @@ msgid "There are no token transfers for this transaction." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_token/index.html.eex:24 +#: lib/block_scout_web/templates/address_token/index.html.eex:18 msgid "There are no tokens for this address." msgstr "" @@ -857,7 +852,7 @@ msgid "Top Accounts - %{subnetwork} Explorer" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:33 +#: lib/block_scout_web/templates/address_logs/_logs.html.eex:14 #: lib/block_scout_web/templates/transaction_log/index.html.eex:103 msgid "Topics" msgstr "" @@ -878,7 +873,7 @@ msgid "Total transactions" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:22 +#: lib/block_scout_web/templates/address_logs/_logs.html.eex:3 #: lib/block_scout_web/views/transaction_view.ex:287 msgid "Transaction" msgstr "" @@ -1282,6 +1277,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_coin_balance/index.html.eex:34 #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:61 +#: lib/block_scout_web/templates/address_logs/index.html.eex:12 +#: lib/block_scout_web/templates/address_token/index.html.eex:13 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:20 #: lib/block_scout_web/templates/address_transaction/index.html.eex:57 #: lib/block_scout_web/templates/address_validation/index.html.eex:22 @@ -1735,6 +1732,6 @@ msgid "Displaying the init data provided of the creating transaction." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:77 +#: lib/block_scout_web/templates/address_logs/index.html.eex:17 msgid "There are no logs for this address." msgstr "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index 0a763e8878..3f846b17de 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -329,7 +329,7 @@ msgid "Curl" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:63 +#: lib/block_scout_web/templates/address_logs/_logs.html.eex:44 #: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:18 #: lib/block_scout_web/templates/transaction_log/index.html.eex:67 #: lib/block_scout_web/templates/transaction_log/index.html.eex:133 @@ -502,7 +502,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:26 -#: lib/block_scout_web/templates/address_logs/index.html.eex:8 +#: lib/block_scout_web/templates/address_logs/index.html.eex:7 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: lib/block_scout_web/templates/transaction_log/index.html.eex:8 #: lib/block_scout_web/views/address_view.ex:301 @@ -576,11 +576,6 @@ msgstr "" msgid "Newer" msgstr "" -#, elixir-format -#: lib/block_scout_web/templates/address_token/index.html.eex:39 -msgid "Next" -msgstr "" - #, elixir-format #: lib/block_scout_web/templates/tokens/inventory/index.html.eex:32 msgid "Next Page" @@ -765,7 +760,7 @@ msgid "There are no token transfers for this transaction." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_token/index.html.eex:24 +#: lib/block_scout_web/templates/address_token/index.html.eex:18 msgid "There are no tokens for this address." msgstr "" @@ -857,7 +852,7 @@ msgid "Top Accounts - %{subnetwork} Explorer" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:33 +#: lib/block_scout_web/templates/address_logs/_logs.html.eex:14 #: lib/block_scout_web/templates/transaction_log/index.html.eex:103 msgid "Topics" msgstr "" @@ -878,7 +873,7 @@ msgid "Total transactions" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:22 +#: lib/block_scout_web/templates/address_logs/_logs.html.eex:3 #: lib/block_scout_web/views/transaction_view.ex:287 msgid "Transaction" msgstr "" @@ -1110,6 +1105,7 @@ msgstr "" msgid "GraphQL" msgstr "" +#, elixir-format #: lib/block_scout_web/templates/pending_transaction/index.html.eex:32 msgid "Loading" msgstr "" @@ -1281,6 +1277,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_coin_balance/index.html.eex:34 #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:61 +#: lib/block_scout_web/templates/address_logs/index.html.eex:12 +#: lib/block_scout_web/templates/address_token/index.html.eex:13 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:20 #: lib/block_scout_web/templates/address_transaction/index.html.eex:57 #: lib/block_scout_web/templates/address_validation/index.html.eex:22 @@ -1734,6 +1732,6 @@ msgid "Displaying the init data provided of the creating transaction." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/index.html.eex:77 +#: lib/block_scout_web/templates/address_logs/index.html.eex:17 msgid "There are no logs for this address." msgstr ""