Merge pull request #1999 from poanetwork/ab-load-data-async-on-addresses-page

load data async on addresses page
pull/2008/head
Ayrat Badykov 6 years ago committed by GitHub
commit b579019867
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 70
      apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex
  3. 21
      apps/block_scout_web/lib/block_scout_web/templates/address/index.html.eex
  4. 2
      apps/block_scout_web/lib/block_scout_web/views/address_view.ex
  5. 29
      apps/block_scout_web/priv/gettext/default.pot
  6. 37
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  7. 13
      apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs

@ -29,6 +29,7 @@
- [#1952](https://github.com/poanetwork/blockscout/pull/1952) - feat: exclude empty contracts by default
- [#1989](https://github.com/poanetwork/blockscout/pull/1989) - fix: consolidate address w/ balance one at a time
- [#1954](https://github.com/poanetwork/blockscout/pull/1954) - feat: use creation init on self destruct
- [#1999](https://github.com/poanetwork/blockscout/pull/1999) - load data async on addresses page
- [#2002](https://github.com/poanetwork/blockscout/pull/2002) - Get estimated count of blocks when cache is empty
### Fixes

@ -3,11 +3,13 @@ defmodule BlockScoutWeb.AddressController do
import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1]
alias BlockScoutWeb.AddressView
alias Explorer.{Chain, Market}
alias Explorer.Chain.Address
alias Explorer.ExchangeRates.Token
alias Phoenix.View
def index(conn, params) do
def index(conn, %{"type" => "JSON"} = params) do
addresses =
params
|> paging_options()
@ -15,41 +17,51 @@ defmodule BlockScoutWeb.AddressController do
{addresses_page, next_page} = split_list_by_page(addresses)
cur_page_number =
cond do
!params["prev_page_number"] -> 1
params["next_page"] -> String.to_integer(params["prev_page_number"]) + 1
params["prev_page"] -> String.to_integer(params["prev_page_number"]) - 1
end
next_page_path =
case next_page_params(next_page, addresses_page, params) do
nil ->
nil
next_page_params ->
next_params =
next_page_params
|> Map.put("prev_page_path", cur_page_path(conn, params))
|> Map.put("next_page", true)
|> Map.put("prev_page_number", cur_page_number)
address_path(
conn,
:index,
next_params
next_page_params
)
end
exchange_rate = Market.get_exchange_rate(Explorer.coin()) || Token.null()
total_supply = Chain.total_supply()
items =
addresses_page
|> Enum.with_index(1)
|> Enum.map(fn {{address, tx_count}, index} ->
View.render_to_string(
AddressView,
"_tile.html",
address: address,
index: index,
exchange_rate: exchange_rate,
total_supply: total_supply,
tx_count: tx_count,
validation_count: validation_count(address)
)
end)
json(
conn,
%{
items: items,
next_page_path: next_page_path
}
)
end
def index(conn, _params) do
render(conn, "index.html",
address_tx_count_pairs: addresses_page,
page_address_count: Enum.count(addresses_page),
address_count: Chain.count_addresses_with_balance_from_cache(),
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(),
total_supply: Chain.total_supply(),
next_page_path: next_page_path,
prev_page_path: params["prev_page_path"],
cur_page_number: cur_page_number
current_path: current_path(conn),
address_count: Chain.count_addresses_with_balance_from_cache()
)
end
@ -64,16 +76,4 @@ defmodule BlockScoutWeb.AddressController do
def validation_count(%Address{} = address) do
Chain.address_to_validation_count(address)
end
defp cur_page_path(conn, %{"hash" => _hash, "fetched_coin_balance" => _balance} = params) do
new_params = Map.put(params, "next_page", false)
address_path(
conn,
:index,
new_params
)
end
defp cur_page_path(conn, _), do: address_path(conn, :index)
end

@ -1,20 +1,21 @@
<section class="container">
<div class="card">
<div class="card-body">
<div class="card-body" data-async-load data-async-listing="<%= @current_path %>">
<h1 class="card-title"><%= gettext "Addresses" %></h1>
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", prev_page_path: @prev_page_path, next_page_path: @next_page_path, cur_page_number: @cur_page_number, show_pagination_limit: true %>
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true %>
<div data-selector="top-addresses-list">
<%= for {{address, tx_count}, index} <- Enum.with_index(@address_tx_count_pairs, 1) do %>
<%= render "_tile.html",
address: address, index: index, exchange_rate: @exchange_rate,
total_supply: @total_supply, tx_count: tx_count,
validation_count: validation_count(address) %>
<% end %>
<div data-items data-selector="top-addresses-list"></div>
<div data-loading-message class="tile tile-muted text-center mt-3" style="display: none;">
<span class="loading-spinner-small mr-2">
<span class="loading-spinner-block-1"></span>
<span class="loading-spinner-block-2"></span>
</span>
<%= gettext("Loading") %>...
</div>
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", prev_page_path: @prev_page_path, next_page_path: @next_page_path, cur_page_number: @cur_page_number, show_pagination_limit: true %>
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true %>
</div>
</div>
</section>

@ -3,8 +3,6 @@ defmodule BlockScoutWeb.AddressView do
require Logger
import BlockScoutWeb.AddressController, only: [validation_count: 1]
alias BlockScoutWeb.LayoutView
alias Explorer.Chain
alias Explorer.Chain.{Address, Hash, InternalTransaction, SmartContract, Token, TokenTransfer, Transaction, Wei}

@ -99,7 +99,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_validator_metadata_modal.html.eex:16
#: lib/block_scout_web/templates/transaction_log/index.html.eex:22
#: lib/block_scout_web/views/address_view.ex:101
#: lib/block_scout_web/views/address_view.ex:99
msgid "Address"
msgstr ""
@ -190,7 +190,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:32
#: lib/block_scout_web/templates/address/overview.html.eex:95
#: lib/block_scout_web/templates/address_validation/index.html.eex:13
#: lib/block_scout_web/views/address_view.ex:302
#: lib/block_scout_web/views/address_view.ex:300
msgid "Blocks Validated"
msgstr ""
@ -218,7 +218,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:42
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:165
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187
#: lib/block_scout_web/views/address_view.ex:298
#: lib/block_scout_web/views/address_view.ex:296
msgid "Code"
msgstr ""
@ -262,14 +262,14 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:13
#: lib/block_scout_web/views/address_view.ex:99
#: lib/block_scout_web/views/address_view.ex:97
msgid "Contract Address"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:16
#: lib/block_scout_web/views/address_view.ex:39
#: lib/block_scout_web/views/address_view.ex:73
#: lib/block_scout_web/views/address_view.ex:37
#: lib/block_scout_web/views/address_view.ex:71
msgid "Contract Address Pending"
msgstr ""
@ -478,7 +478,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:19
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:11
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6
#: lib/block_scout_web/views/address_view.ex:297
#: lib/block_scout_web/views/address_view.ex:295
#: lib/block_scout_web/views/transaction_view.ex:339
msgid "Internal Transactions"
msgstr ""
@ -505,7 +505,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_logs/index.html.eex:8
#: 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:303
#: lib/block_scout_web/views/address_view.ex:301
#: lib/block_scout_web/views/transaction_view.ex:340
msgid "Logs"
msgstr ""
@ -513,7 +513,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:31
#: lib/block_scout_web/templates/layout/app.html.eex:53
#: lib/block_scout_web/views/address_view.ex:123
#: lib/block_scout_web/views/address_view.ex:121
msgid "Market Cap"
msgstr ""
@ -683,7 +683,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:58
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:25
#: lib/block_scout_web/views/address_view.ex:300
#: lib/block_scout_web/views/address_view.ex:298
#: lib/block_scout_web/views/tokens/overview_view.ex:37
msgid "Read Contract"
msgstr ""
@ -863,7 +863,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:8
#: lib/block_scout_web/templates/address_token/index.html.eex:8
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:9
#: lib/block_scout_web/views/address_view.ex:295
#: lib/block_scout_web/views/address_view.ex:293
msgid "Tokens"
msgstr ""
@ -922,7 +922,7 @@ msgstr ""
#: lib/block_scout_web/templates/block_transaction/index.html.eex:17
#: lib/block_scout_web/templates/chain/show.html.eex:108
#: lib/block_scout_web/templates/layout/_topnav.html.eex:35
#: lib/block_scout_web/views/address_view.ex:296
#: lib/block_scout_web/views/address_view.ex:294
msgid "Transactions"
msgstr ""
@ -1130,6 +1130,7 @@ msgid "GraphQL"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/index.html.eex:15
#: lib/block_scout_web/templates/address_coin_balance/index.html.eex:66
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:73
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:90
@ -1349,7 +1350,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:20
#: lib/block_scout_web/views/address_view.ex:301
#: lib/block_scout_web/views/address_view.ex:299
msgid "Coin Balance History"
msgstr ""
@ -1658,7 +1659,7 @@ msgid "Copy Decompiled Contract Code"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/address_view.ex:299
#: lib/block_scout_web/views/address_view.ex:297
msgid "Decompiled Code"
msgstr ""

@ -99,7 +99,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_validator_metadata_modal.html.eex:16
#: lib/block_scout_web/templates/transaction_log/index.html.eex:22
#: lib/block_scout_web/views/address_view.ex:101
#: lib/block_scout_web/views/address_view.ex:99
msgid "Address"
msgstr ""
@ -190,7 +190,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:32
#: lib/block_scout_web/templates/address/overview.html.eex:95
#: lib/block_scout_web/templates/address_validation/index.html.eex:13
#: lib/block_scout_web/views/address_view.ex:302
#: lib/block_scout_web/views/address_view.ex:300
msgid "Blocks Validated"
msgstr ""
@ -218,7 +218,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:42
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:165
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187
#: lib/block_scout_web/views/address_view.ex:298
#: lib/block_scout_web/views/address_view.ex:296
msgid "Code"
msgstr ""
@ -262,14 +262,14 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:13
#: lib/block_scout_web/views/address_view.ex:99
#: lib/block_scout_web/views/address_view.ex:97
msgid "Contract Address"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:16
#: lib/block_scout_web/views/address_view.ex:39
#: lib/block_scout_web/views/address_view.ex:73
#: lib/block_scout_web/views/address_view.ex:37
#: lib/block_scout_web/views/address_view.ex:71
msgid "Contract Address Pending"
msgstr ""
@ -478,7 +478,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:19
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:11
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6
#: lib/block_scout_web/views/address_view.ex:297
#: lib/block_scout_web/views/address_view.ex:295
#: lib/block_scout_web/views/transaction_view.ex:339
msgid "Internal Transactions"
msgstr ""
@ -505,7 +505,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_logs/index.html.eex:8
#: 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:303
#: lib/block_scout_web/views/address_view.ex:301
#: lib/block_scout_web/views/transaction_view.ex:340
msgid "Logs"
msgstr ""
@ -513,7 +513,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/chain/show.html.eex:31
#: lib/block_scout_web/templates/layout/app.html.eex:53
#: lib/block_scout_web/views/address_view.ex:123
#: lib/block_scout_web/views/address_view.ex:121
msgid "Market Cap"
msgstr ""
@ -683,7 +683,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:58
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:25
#: lib/block_scout_web/views/address_view.ex:300
#: lib/block_scout_web/views/address_view.ex:298
#: lib/block_scout_web/views/tokens/overview_view.ex:37
msgid "Read Contract"
msgstr ""
@ -863,7 +863,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:8
#: lib/block_scout_web/templates/address_token/index.html.eex:8
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:9
#: lib/block_scout_web/views/address_view.ex:295
#: lib/block_scout_web/views/address_view.ex:293
msgid "Tokens"
msgstr ""
@ -922,7 +922,7 @@ msgstr ""
#: lib/block_scout_web/templates/block_transaction/index.html.eex:17
#: lib/block_scout_web/templates/chain/show.html.eex:108
#: lib/block_scout_web/templates/layout/_topnav.html.eex:35
#: lib/block_scout_web/views/address_view.ex:296
#: lib/block_scout_web/views/address_view.ex:294
msgid "Transactions"
msgstr ""
@ -1130,6 +1130,7 @@ msgid "GraphQL"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/index.html.eex:15
#: lib/block_scout_web/templates/address_coin_balance/index.html.eex:66
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:73
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:90
@ -1349,7 +1350,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:20
#: lib/block_scout_web/views/address_view.ex:301
#: lib/block_scout_web/views/address_view.ex:299
msgid "Coin Balance History"
msgstr ""
@ -1658,7 +1659,7 @@ msgid "Copy Decompiled Contract Code"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/address_view.ex:299
#: lib/block_scout_web/views/address_view.ex:297
msgid "Decompiled Code"
msgstr ""
@ -1748,12 +1749,12 @@ msgstr ""
msgid "of"
msgstr ""
#, elixir-format, fuzzy
#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:83
msgid "Contract Byte Code"
msgstr ""
#, elixir-format, fuzzy
#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:69
msgid "Contract Creation Code"
msgstr ""
@ -1763,7 +1764,7 @@ msgstr ""
msgid "Contracts that self destruct in their constructors have no contract code published and cannot be verified."
msgstr ""
#, elixir-format, fuzzy
#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:85
msgid "Copy Contract Byte Code"
msgstr ""
@ -1773,7 +1774,7 @@ msgstr ""
msgid "Displaying the init data provided of the creating transaction."
msgstr ""
#, elixir-format, fuzzy
#, elixir-format
#: lib/block_scout_web/templates/address_logs/index.html.eex:77
msgid "There are no logs for this address."
msgstr ""

@ -15,11 +15,10 @@ defmodule BlockScoutWeb.AddressControllerTest do
start_supervised!(AddressesWithBalanceCounter)
AddressesWithBalanceCounter.consolidate()
conn = get(conn, address_path(conn, :index))
conn = get(conn, address_path(conn, :index, %{type: "JSON"}))
{:ok, %{"items" => items}} = Poison.decode(conn.resp_body)
assert conn.assigns.address_tx_count_pairs
|> Enum.map(fn {address, _transaction_count} -> address end)
|> Enum.map(& &1.hash) == address_hashes
assert Enum.count(items) == Enum.count(address_hashes)
end
test "returns an address's primary name when present", %{conn: conn} do
@ -29,9 +28,11 @@ defmodule BlockScoutWeb.AddressControllerTest do
start_supervised!(AddressesWithBalanceCounter)
AddressesWithBalanceCounter.consolidate()
conn = get(conn, address_path(conn, :index))
conn = get(conn, address_path(conn, :index, %{type: "JSON"}))
assert html_response(conn, 200) =~ address_name.name
{:ok, %{"items" => [item]}} = Poison.decode(conn.resp_body)
assert String.contains?(item, "POA Wallet")
end
end

Loading…
Cancel
Save