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

@ -20,7 +20,19 @@
<%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: transaction.from_address %>
</td>
<td>
<%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: transaction.to_address %>
<%= cond do %>
<% transaction.to_address_hash != nil -> %>
<%= 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><%= ExplorerWeb.TransactionView.value(transaction, include_label: false) %> </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]
alias Explorer.Chain.InternalTransaction
def blocks(count: count) do
css("[data-test='chain_block']", count: count)
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
session
|> fill_in(css("[data-test='search_input']"), with: text)
|> send_keys([:enter])
end
def visit_page(session) do
visit(session, "/")
end
def transactions(count: count) do
css("[data-test='chain_transaction']", count: count)
end
def visit_page(session) do
visit(session, "/")
end
end

@ -16,7 +16,7 @@ defmodule ExplorerWeb.TransactionListPage do
end
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
def transaction(%Transaction{hash: transaction_hash}) do

@ -75,6 +75,14 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
|> assert_has(HomePage.transactions(count: 5))
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
session
|> TransactionListPage.visit_page()
@ -89,7 +97,7 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
|> assert_has(TransactionListPage.transaction(pending))
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)
session

Loading…
Cancel
Save