From 019916096d2adee22b9355387657efdea9fd9ce1 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 28 Aug 2020 15:55:35 +0300 Subject: [PATCH] Bridged tokens table --- CHANGELOG.md | 1 + .../tokens/bridged_tokens_controller.ex | 60 +++++++++++++++++++ .../templates/bridged_tokens/_tile.html.eex | 36 +++++++++++ .../templates/bridged_tokens/index.html.eex | 45 ++++++++++++++ .../templates/layout/_topnav.html.eex | 39 +++++++++--- .../templates/layout/app.html.eex | 1 + .../views/bridged_tokens_view.ex | 22 +++++++ .../lib/block_scout_web/web_router.ex | 2 + apps/block_scout_web/priv/gettext/default.pot | 32 ++++++---- .../priv/gettext/en/LC_MESSAGES/default.po | 32 ++++++---- apps/explorer/lib/explorer/chain.ex | 22 +++++++ 11 files changed, 264 insertions(+), 28 deletions(-) create mode 100644 apps/block_scout_web/lib/block_scout_web/controllers/tokens/bridged_tokens_controller.ex create mode 100644 apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/_tile.html.eex create mode 100644 apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/index.html.eex create mode 100644 apps/block_scout_web/lib/block_scout_web/views/bridged_tokens_view.ex diff --git a/CHANGELOG.md b/CHANGELOG.md index b91644d075..db30d5accb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#3261](https://github.com/poanetwork/blockscout/pull/3261) - Bridged tokens table ### Fixes - [#3256](https://github.com/poanetwork/blockscout/pull/3256) - Fix for invisible validator address at block page and wrong alert text color at xDai diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/tokens/bridged_tokens_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/tokens/bridged_tokens_controller.ex new file mode 100644 index 0000000000..815077567f --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/controllers/tokens/bridged_tokens_controller.ex @@ -0,0 +1,60 @@ +defmodule BlockScoutWeb.BridgedTokensController do + use BlockScoutWeb, :controller + + import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1] + + alias BlockScoutWeb.BridgedTokensView + alias Explorer.Chain + alias Phoenix.View + + def index(conn, %{"type" => "JSON"} = params) do + tokens = + params + |> paging_options() + |> Chain.list_top_bridged_tokens() + + {tokens_page, next_page} = split_list_by_page(tokens) + + next_page_path = + case next_page_params(next_page, tokens_page, params) do + nil -> + nil + + next_page_params -> + tokens_path( + conn, + :index, + Map.delete(next_page_params, "type") + ) + end + + items = + tokens_page + |> Enum.with_index(1) + |> Enum.map(fn {token, index} -> + View.render_to_string( + BridgedTokensView, + "_tile.html", + token: token, + index: index + ) + end) + + json( + conn, + %{ + items: items, + next_page_path: next_page_path + } + ) + end + + def index(conn, _params) do + total_supply = Chain.total_supply() + + render(conn, "index.html", + current_path: current_path(conn), + total_supply: total_supply + ) + end +end diff --git a/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/_tile.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/_tile.html.eex new file mode 100644 index 0000000000..094a16442a --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/_tile.html.eex @@ -0,0 +1,36 @@ + + + + + <%= @index %> + + + + <% token = token_display_name(@token) %> + <%= link(token, + to: token_path(BlockScoutWeb.Endpoint, :show, @token.contract_address_hash), + "data-test": "token_link", + class: "text-truncate") %> + + + <%= render BlockScoutWeb.AddressView, + "_link.html", + address: @token.contract_address, + contract: true, + use_custom_tooltip: false + %> + + + <%= if decimals?(@token) do %> + <%= format_according_to_decimals(@token.total_supply, @token.decimals) %> + <% else %> + <%= format_integer_to_currency(@token.total_supply) %> + <% end %> <%= @token.symbol %> + + + + + <%= @token.holder_count %> + + + diff --git a/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/index.html.eex new file mode 100644 index 0000000000..5b76450d69 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/bridged_tokens/index.html.eex @@ -0,0 +1,45 @@ +
+
+
+

<%= gettext "Bridged Tokens" %>

+ + <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> + +
+
+ + + + + + + + + + + + <%= render BlockScoutWeb.CommonComponentsView, "_table-loader.html", total_supply: @total_supply %> + +
+
 
+
+
Token
+
+
Address
+
+
+ Total Supply +
+
+
+ Holders Count +
+
+
+
+ + <%= 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/lib/block_scout_web/templates/layout/_topnav.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex index 4d0ef2d6c9..631c92493d 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex @@ -75,14 +75,37 @@ <%= gettext("Accounts") %> <% end %> - + <%= if Application.get_env(:block_scout_web, :multi_token_bridge_mediator) && Application.get_env(:block_scout_web, :multi_token_bridge_mediator) != "" do %> + + <% else %> + + <% end %> <% end %> <%= if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter)[:reading_enabled] || Application.get_env(:block_scout_web, :api_url) do %>