commit
68ea9c1ea1
@ -0,0 +1,60 @@ |
|||||||
|
defmodule BlockScoutWeb.TokensController do |
||||||
|
use BlockScoutWeb, :controller |
||||||
|
|
||||||
|
import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1] |
||||||
|
|
||||||
|
alias BlockScoutWeb.TokensView |
||||||
|
alias Explorer.Chain |
||||||
|
alias Phoenix.View |
||||||
|
|
||||||
|
def index(conn, %{"type" => "JSON"} = params) do |
||||||
|
tokens = |
||||||
|
params |
||||||
|
|> paging_options() |
||||||
|
|> Chain.list_top_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( |
||||||
|
TokensView, |
||||||
|
"_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 |
After Width: | Height: | Size: 1.8 KiB |
@ -0,0 +1,36 @@ |
|||||||
|
<tr> |
||||||
|
<td class="stakes-td"> |
||||||
|
<!-- incremented number by order in the list --> |
||||||
|
<span class="color-lighten"> |
||||||
|
<%= @index %> |
||||||
|
</span> |
||||||
|
</td> |
||||||
|
<td class="stakes-td"> |
||||||
|
<% token = "#{@token.name} (#{@token.symbol})" %> |
||||||
|
<%= link(token, |
||||||
|
to: token_path(BlockScoutWeb.Endpoint, :show, @token.contract_address_hash), |
||||||
|
"data-test": "token_link", |
||||||
|
class: "text-truncate") %> |
||||||
|
</td> |
||||||
|
<td class="stakes-td"> |
||||||
|
<%= render BlockScoutWeb.AddressView, |
||||||
|
"_link.html", |
||||||
|
address: @token.contract_address, |
||||||
|
contract: true, |
||||||
|
use_custom_tooltip: false |
||||||
|
%> |
||||||
|
</td> |
||||||
|
<td class="stakes-td"> |
||||||
|
<%= if decimals?(@token) do %> |
||||||
|
<span data-test="token_supply"><%= format_according_to_decimals(@token.total_supply, @token.decimals) %></span> |
||||||
|
<% else %> |
||||||
|
<span data-test="token_supply"><%= format_integer_to_currency(@token.total_supply) %></span> |
||||||
|
<% end %> <%= @token.symbol %> |
||||||
|
</td> |
||||||
|
<td class="stakes-td"> |
||||||
|
<span class="mr-4"> |
||||||
|
<span data-test="transaction_count"> |
||||||
|
<%= @token.holder_count %> |
||||||
|
</span> |
||||||
|
</td> |
||||||
|
</tr> |
@ -0,0 +1,45 @@ |
|||||||
|
<section class="container"> |
||||||
|
<div class="card"> |
||||||
|
<div class="card-body" data-async-load data-async-listing="<%= @current_path %>"> |
||||||
|
<h1 class="card-title"><%= gettext "Tokens" %></h1> |
||||||
|
|
||||||
|
<%= 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 %> |
||||||
|
|
||||||
|
<div class="addresses-table-container"> |
||||||
|
<div class="stakes-table-container"> |
||||||
|
<table> |
||||||
|
<thead> |
||||||
|
<tr> |
||||||
|
<th class="stakes-table-th"> |
||||||
|
<div class="stakes-table-th-content"> </div> |
||||||
|
</th> |
||||||
|
<th class="stakes-table-th"> |
||||||
|
<div class="stakes-table-th-content">Token</div> |
||||||
|
</th> |
||||||
|
<th class="stakes-table-th"> |
||||||
|
<div class="stakes-table-th-content">Address</div> |
||||||
|
</th> |
||||||
|
<th class="stakes-table-th"> |
||||||
|
<div class="stakes-table-th-content"> |
||||||
|
Total Supply |
||||||
|
</div> |
||||||
|
</th> |
||||||
|
<th class="stakes-table-th"> |
||||||
|
<div class="stakes-table-th-content"> |
||||||
|
Holders Count |
||||||
|
</div> |
||||||
|
</th> |
||||||
|
</tr> |
||||||
|
</thead> |
||||||
|
<tbody data-items data-selector="top-tokens-list"> |
||||||
|
<%= render BlockScoutWeb.CommonComponentsView, "_table-loader.html", total_supply: @total_supply %> |
||||||
|
</tbody> |
||||||
|
</table> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
|
||||||
|
<%= 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 %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<script defer data-cfasync="false" src="<%= static_path(@conn, "/js/async-listing-load.js") %>"></script> |
||||||
|
</section> |
@ -0,0 +1,8 @@ |
|||||||
|
defmodule BlockScoutWeb.TokensView do |
||||||
|
use BlockScoutWeb, :view |
||||||
|
|
||||||
|
alias Explorer.Chain.Token |
||||||
|
|
||||||
|
def decimals?(%Token{decimals: nil}), do: false |
||||||
|
def decimals?(%Token{decimals: _}), do: true |
||||||
|
end |
Loading…
Reference in new issue