Add contract creation link to home page

pull/275/head
Stamates 7 years ago committed by katibest
parent 43d0a62118
commit 2b6ab7ceea
  1. 14
      apps/explorer/lib/explorer/chain/statistics.ex
  2. 12
      apps/explorer_web/lib/explorer_web/templates/chain/_transactions.html.eex
  3. 14
      apps/explorer_web/test/explorer_web/features/pages/home_page.ex
  4. 2
      apps/explorer_web/test/explorer_web/features/pages/transaction_list_page.ex
  5. 10
      apps/explorer_web/test/explorer_web/features/viewing_transactions_test.exs

@ -6,7 +6,7 @@ defmodule Explorer.Chain.Statistics do
import Ecto.Query import Ecto.Query
alias Ecto.Adapters.SQL alias Ecto.Adapters.SQL
alias Explorer.{Chain, Repo} alias Explorer.{Chain, PagingOptions, Repo}
alias Explorer.Chain.{Block, Transaction} alias Explorer.Chain.{Block, Transaction}
alias Timex.Duration alias Timex.Duration
@ -115,13 +115,9 @@ defmodule Explorer.Chain.Statistics do
) )
transactions = transactions =
from( [paging_options: %PagingOptions{page_size: 5}]
transaction in Transaction, |> Chain.recent_collated_transactions()
join: block in assoc(transaction, :block), |> Repo.preload([:block])
order_by: [desc: block.number],
preload: [:from_address, :to_address, block: block],
limit: 5
)
%__MODULE__{ %__MODULE__{
average_time: query_duration(@average_time_query), average_time: query_duration(@average_time_query),
@ -130,7 +126,7 @@ defmodule Explorer.Chain.Statistics do
lag: query_duration(@lag_query), lag: query_duration(@lag_query),
transaction_count: query_value(@transaction_count_query), transaction_count: query_value(@transaction_count_query),
transaction_velocity: query_value(@transaction_velocity_query), transaction_velocity: query_value(@transaction_velocity_query),
transactions: Repo.all(transactions) transactions: transactions
} }
|> put_max_numbered_block() |> put_max_numbered_block()
end end

@ -20,7 +20,19 @@
<%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: transaction.from_address %> <%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: transaction.from_address %>
</td> </td>
<td> <td>
<%= cond do %>
<% transaction.to_address_hash != nil -> %>
<%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: transaction.to_address %> <%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: transaction.to_address %>
<% transaction.created_contract_address_hash != nil -> %>
<%= link(
"Contract Creation",
class: "transaction__link",
"data-address-hash": transaction.created_contract_address_hash,
to: address_path(@conn, :show, @conn.assigns.locale, transaction.created_contract_address_hash),
title: transaction.created_contract_address_hash
) %>
<% true -> %>
<% end %>
</td> </td>
<td><%= ExplorerWeb.TransactionView.value(transaction, include_label: false) %> </td> <td><%= ExplorerWeb.TransactionView.value(transaction, include_label: false) %> </td>
<td><%= transaction.block.timestamp |> Timex.from_now() %></td> <td><%= transaction.block.timestamp |> Timex.from_now() %></td>

@ -5,21 +5,27 @@ defmodule ExplorerWeb.HomePage do
import Wallaby.Query, only: [css: 1, css: 2] import Wallaby.Query, only: [css: 1, css: 2]
alias Explorer.Chain.InternalTransaction
def blocks(count: count) do def blocks(count: count) do
css("[data-test='chain_block']", count: count) css("[data-test='chain_block']", count: count)
end end
def contract_creation(%InternalTransaction{created_contract_address_hash: hash}) do
css("[data-address-hash='#{hash}']", text: "Contract Creation")
end
def search(session, text) do def search(session, text) do
session session
|> fill_in(css("[data-test='search_input']"), with: text) |> fill_in(css("[data-test='search_input']"), with: text)
|> send_keys([:enter]) |> send_keys([:enter])
end end
def visit_page(session) do
visit(session, "/")
end
def transactions(count: count) do def transactions(count: count) do
css("[data-test='chain_transaction']", count: count) css("[data-test='chain_transaction']", count: count)
end end
def visit_page(session) do
visit(session, "/")
end
end end

@ -16,7 +16,7 @@ defmodule ExplorerWeb.TransactionListPage do
end end
def contract_creation(%InternalTransaction{created_contract_address_hash: hash}) do def contract_creation(%InternalTransaction{created_contract_address_hash: hash}) do
css("[data-address-hash='#{hash}']", text: "Contract Created") css("[data-address-hash='#{hash}']", text: "Contract Creation")
end end
def transaction(%Transaction{hash: transaction_hash}) do def transaction(%Transaction{hash: transaction_hash}) do

@ -75,6 +75,14 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
|> assert_has(HomePage.transactions(count: 5)) |> assert_has(HomePage.transactions(count: 5))
end end
test "contract creation is shown for to_address on home page", %{session: session} do
internal_transaction = insert(:internal_transaction_create, index: 0)
session
|> HomePage.visit_page()
|> assert_has(HomePage.contract_creation(internal_transaction))
end
test "viewing the default transactions tab", %{session: session, transaction: transaction, pending: pending} do test "viewing the default transactions tab", %{session: session, transaction: transaction, pending: pending} do
session session
|> TransactionListPage.visit_page() |> TransactionListPage.visit_page()
@ -89,7 +97,7 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
|> assert_has(TransactionListPage.transaction(pending)) |> assert_has(TransactionListPage.transaction(pending))
end end
test "contract creation is shown for to_address", %{session: session} do test "contract creation is shown for to_address on list page", %{session: session} do
internal_transaction = insert(:internal_transaction_create, index: 0) internal_transaction = insert(:internal_transaction_create, index: 0)
session session

Loading…
Cancel
Save