From 2467d6622239eb88db3be8e83711b38489128285 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 16 May 2019 15:47:22 +0300 Subject: [PATCH] add forgotten files --- .../controllers/address_logs_controller.ex | 46 +++++++++++ .../templates/address_logs/index.html.eex | 82 +++++++++++++++++++ .../views/address_logs_view.ex | 3 + 3 files changed, 131 insertions(+) create mode 100644 apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex create mode 100644 apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex create mode 100644 apps/block_scout_web/lib/block_scout_web/views/address_logs_view.ex 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 new file mode 100644 index 0000000000..f79d9aa08d --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex @@ -0,0 +1,46 @@ +defmodule BlockScoutWeb.AddressLogsController do + @moduledoc """ + Manages events logs tab. + """ + + 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 Explorer.{Chain, Market} + alias Explorer.ExchangeRates.Token + alias Indexer.Fetcher.CoinBalanceOnDemand + + use BlockScoutWeb, :controller + + def index(conn, %{"address_id" => address_hash_string} = 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)) + {results, next_page} = split_list_by_page(logs_plus_one) + + next_page_url = + case next_page_params(next_page, results, params) do + nil -> + nil + + next_page_params -> + address_logs_path(conn, :index, address, next_page_params) + end + + render( + conn, + "index.html", + address: address, + logs: results, + 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 + ) + else + _ -> + not_found(conn) + end + end +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 new file mode 100644 index 0000000000..22f446924f --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex @@ -0,0 +1,82 @@ +
+ <%= render BlockScoutWeb.AddressView, "overview.html", assigns %> +
+ <%= 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 %> + + <%= 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 %> +
+
+
+ <% end %> + <% else %> +
+ <%= gettext "There are no logs for this address." %> +
+ <% end %> +
+
+
diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_logs_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_logs_view.ex new file mode 100644 index 0000000000..7155e65206 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/views/address_logs_view.ex @@ -0,0 +1,3 @@ +defmodule BlockScoutWeb.AddressLogsView do + use BlockScoutWeb, :view +end