Merge branch 'master' into ac-update-readme-dependencies

pull/1073/head
Andrew Cravenho 6 years ago committed by GitHub
commit c5b9fb1228
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      apps/block_scout_web/assets/js/pages/address.js
  2. 19
      apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex
  3. 49
      apps/block_scout_web/lib/block_scout_web/templates/address_transaction/index.html.eex
  4. 11
      apps/block_scout_web/priv/gettext/default.pot
  5. 11
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  6. 43
      apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs
  7. 9
      apps/explorer/config/test.exs

@ -30,7 +30,9 @@ export const initialState = {
internalTransactionsBatch: [],
validatedBlocks: [],
beyondPageOne: null
beyondPageOne: null,
nextPageUrl: $('[data-selector="transactions-list"]').length ? URI(window.location).addQuery({ type: 'JSON' }).toString() : null
}
export const reducer = withInfiniteScroll(baseReducer)
@ -204,6 +206,15 @@ const elements = {
$el[0].innerHTML = numeral(state.pendingTransactions.filter(({ validated }) => !validated).length).format()
}
},
'[data-selector="empty-transactions-list"]': {
render ($el, state) {
if (state.transactions.length || state.loadingNextPage || state.pagingError) {
$el.hide()
} else {
$el.show()
}
}
},
'[data-selector="transactions-list"]': {
load ($el) {
return {

@ -35,7 +35,8 @@ defmodule BlockScoutWeb.AddressTransactionController do
|> Keyword.merge(paging_options(params))
|> Keyword.merge(current_filter(params))
{transactions, next_page} = get_transactions_and_next_page(address, options)
transactions_plus_one = Chain.address_to_transactions(address, options)
{transactions, next_page} = split_list_by_page(transactions_plus_one)
next_page_url =
case next_page_params(next_page, transactions, params) do
@ -82,23 +83,12 @@ defmodule BlockScoutWeb.AddressTransactionController do
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
pending_options =
@transaction_necessity_by_association
|> Keyword.merge(paging_options(params))
|> Keyword.merge(current_filter(params))
full_options = put_in(pending_options, [:necessity_by_association, :block], :required)
{transactions, next_page} = get_transactions_and_next_page(address, full_options)
render(
conn,
"index.html",
address: address,
next_page_params: next_page_params(next_page, transactions, params),
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(),
filter: params["filter"],
transactions: transactions,
transaction_count: transaction_count(address),
validation_count: validation_count(address)
)
@ -110,9 +100,4 @@ defmodule BlockScoutWeb.AddressTransactionController do
not_found(conn)
end
end
defp get_transactions_and_next_page(address, options) do
transactions_plus_one = Chain.address_to_transactions(address, options)
split_list_by_page(transactions_plus_one)
end
end

@ -51,42 +51,21 @@
</div>
</div>
<h2 class="card-title"><%= gettext "Transactions" %></h2>
<%= if Enum.count(@transactions) > 0 do %>
<span data-selector="transactions-list">
<%= for transaction <- @transactions do %>
<%= render(BlockScoutWeb.TransactionView, "_tile.html", current_address: @address, transaction: transaction) %>
<% end %>
<span data-selector="transactions-list">
</span>
<div data-selector="loading-next-page" class="tile tile-muted text-center mt-3">
<span class="loading-spinner-small mr-2">
<span class="loading-spinner-block-1"></span>
<span class="loading-spinner-block-2"></span>
</span>
<div data-selector="loading-next-page" 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>
<div data-selector="paging-error-message" class="alert alert-danger text-center mt-3" style="display: none;">
<%= gettext("Error trying to fetch next page.") %>
</div>
<% else %>
<div class="tile tile-muted text-center">
<span data-selector="empty-transactions-list"><%= gettext "There are no transactions for this address." %></span>
</div>
<% end %>
<%= if @next_page_params do %>
<%= link(
gettext("Older"),
class: "button button-secondary button-sm float-right mt-3",
"data-selector": "next-page-button",
to: address_transaction_path(
@conn,
:index,
@address,
@next_page_params
)
) %>
<% end %>
<%= gettext("Loading") %>...
</div>
<div data-selector="paging-error-message" class="alert alert-danger text-center mt-3" style="display: none;">
<%= gettext("Error trying to fetch transactions.") %>
</div>
<div class="tile tile-muted text-center" data-selector="empty-transactions-list" style="display: none;">
<%= gettext "There are no transactions for this address." %>
</div>
</div>
</div>
</section>

@ -632,7 +632,6 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:72
#: lib/block_scout_web/templates/address_transaction/index.html.eex:79
#: lib/block_scout_web/templates/address_validation/index.html.eex:117
#: lib/block_scout_web/templates/block/index.html.eex:30
#: lib/block_scout_web/templates/block_transaction/index.html.eex:50
@ -845,7 +844,7 @@ msgid "There are no tokens."
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_transaction/index.html.eex:73
#: lib/block_scout_web/templates/address_transaction/index.html.eex:67
msgid "There are no transactions for this address."
msgstr ""
@ -1195,7 +1194,6 @@ msgid "APIs"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_transaction/index.html.eex:68
#: lib/block_scout_web/templates/block/index.html.eex:25
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:36
#: lib/block_scout_web/templates/transaction/index.html.eex:36
@ -1208,7 +1206,7 @@ msgid "GraphQL"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_transaction/index.html.eex:65
#: lib/block_scout_web/templates/address_transaction/index.html.eex:61
#: lib/block_scout_web/templates/block/index.html.eex:22
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:33
#: lib/block_scout_web/templates/transaction/index.html.eex:33
@ -1241,3 +1239,8 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/overview.html.eex:164
msgid "copy"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_transaction/index.html.eex:64
msgid "Error trying to fetch transactions."
msgstr ""

@ -632,7 +632,6 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:72
#: lib/block_scout_web/templates/address_transaction/index.html.eex:79
#: lib/block_scout_web/templates/address_validation/index.html.eex:117
#: lib/block_scout_web/templates/block/index.html.eex:30
#: lib/block_scout_web/templates/block_transaction/index.html.eex:50
@ -845,7 +844,7 @@ msgid "There are no tokens."
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_transaction/index.html.eex:73
#: lib/block_scout_web/templates/address_transaction/index.html.eex:67
msgid "There are no transactions for this address."
msgstr ""
@ -1195,7 +1194,6 @@ msgid "APIs"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_transaction/index.html.eex:68
#: lib/block_scout_web/templates/block/index.html.eex:25
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:36
#: lib/block_scout_web/templates/transaction/index.html.eex:36
@ -1208,7 +1206,7 @@ msgid "GraphQL"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_transaction/index.html.eex:65
#: lib/block_scout_web/templates/address_transaction/index.html.eex:61
#: lib/block_scout_web/templates/block/index.html.eex:22
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:33
#: lib/block_scout_web/templates/transaction/index.html.eex:33
@ -1241,3 +1239,8 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/overview.html.eex:164
msgid "copy"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_transaction/index.html.eex:64
msgid "Error trying to fetch transactions."
msgstr ""

@ -1,7 +1,7 @@
defmodule BlockScoutWeb.AddressTransactionControllerTest do
use BlockScoutWeb.ConnCase
import BlockScoutWeb.Router.Helpers, only: [address_transaction_path: 3]
import BlockScoutWeb.Router.Helpers, only: [address_transaction_path: 3, address_transaction_path: 4]
alias Explorer.Chain.{Block, Transaction}
alias Explorer.ExchangeRates.Token
@ -34,15 +34,15 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
|> insert(to_address: address)
|> with_block(block)
conn = get(conn, address_transaction_path(conn, :index, address))
conn = get(conn, address_transaction_path(conn, :index, address), %{"type" => "JSON"})
actual_transaction_hashes =
conn.assigns.transactions
|> Enum.map(& &1.hash)
{:ok, %{"transactions" => transactions}} = conn.resp_body |> Poison.decode()
actual_transaction_hashes = Enum.map(transactions, & &1["transaction_hash"])
assert html_response(conn, 200)
assert Enum.member?(actual_transaction_hashes, from_transaction.hash)
assert Enum.member?(actual_transaction_hashes, to_transaction.hash)
assert json_response(conn, 200)
assert Enum.member?(actual_transaction_hashes, to_string(from_transaction.hash))
assert Enum.member?(actual_transaction_hashes, to_string(to_transaction.hash))
end
test "includes USD exchange rate value for address in assigns", %{conn: conn} do
@ -92,9 +92,18 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
|> insert_list(:transaction, from_address: address)
|> with_block(block)
conn = get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash))
conn = get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash), %{"type" => "JSON"})
{:ok, %{"next_page_url" => actual_next_page_url}} = conn.resp_body |> Poison.decode()
expected_next_page_url =
address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash, %{
"block_number" => number,
"index" => 10,
"type" => "JSON"
})
assert %{"block_number" => ^number, "index" => 10} = conn.assigns.next_page_params
assert expected_next_page_url = actual_next_page_url
end
test "next_page_params are empty if on last page", %{conn: conn} do
@ -104,9 +113,11 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
|> insert(from_address: address)
|> with_block()
conn = get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash))
conn = get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash), %{"type" => "JSON"})
{:ok, %{"next_page_url" => next_page_url}} = conn.resp_body |> Poison.decode()
refute conn.assigns.next_page_params
refute next_page_url
end
test "returns parent transaction for a contract address", %{conn: conn} do
@ -127,9 +138,13 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
transaction: transaction
)
conn = get(conn, address_transaction_path(conn, :index, address))
conn = get(conn, address_transaction_path(conn, :index, address), %{"type" => "JSON"})
{:ok, %{"transactions" => transactions}} = conn.resp_body |> Poison.decode()
transaction_hashes = Enum.map(transactions, & &1["transaction_hash"])
assert [transaction] == conn.assigns.transactions
assert [to_string(transaction.hash)] == transaction_hashes
end
end
end

@ -23,8 +23,13 @@ config :logger, :explorer,
level: :warn,
path: Path.absname("logs/test/explorer.log")
if File.exists?(file = "test.secret.exs") do
import_config file
secret_file =
__ENV__.file
|> Path.dirname()
|> Path.join("test.secret.exs")
if File.exists?(secret_file) do
import_config secret_file
end
config :explorer, Explorer.ExchangeRates.Source.TransactionAndLog,

Loading…
Cancel
Save