From 2b6ab7ceead5abbe1ea934e310baa52e882e181e Mon Sep 17 00:00:00 2001 From: Stamates Date: Fri, 8 Jun 2018 10:34:56 -0400 Subject: [PATCH] Add contract creation link to home page --- apps/explorer/lib/explorer/chain/statistics.ex | 14 +++++--------- .../templates/chain/_transactions.html.eex | 14 +++++++++++++- .../test/explorer_web/features/pages/home_page.ex | 14 ++++++++++---- .../features/pages/transaction_list_page.ex | 2 +- .../features/viewing_transactions_test.exs | 10 +++++++++- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/statistics.ex b/apps/explorer/lib/explorer/chain/statistics.ex index b87b292d5f..d67f5008aa 100644 --- a/apps/explorer/lib/explorer/chain/statistics.ex +++ b/apps/explorer/lib/explorer/chain/statistics.ex @@ -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 diff --git a/apps/explorer_web/lib/explorer_web/templates/chain/_transactions.html.eex b/apps/explorer_web/lib/explorer_web/templates/chain/_transactions.html.eex index ed4d1bff71..7f7ac03d04 100644 --- a/apps/explorer_web/lib/explorer_web/templates/chain/_transactions.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/chain/_transactions.html.eex @@ -20,7 +20,19 @@ <%= render ExplorerWeb.AddressView, "_link.html", conn: @conn, address: transaction.from_address %> - <%= 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 %> <%= ExplorerWeb.TransactionView.value(transaction, include_label: false) %> <%= transaction.block.timestamp |> Timex.from_now() %> diff --git a/apps/explorer_web/test/explorer_web/features/pages/home_page.ex b/apps/explorer_web/test/explorer_web/features/pages/home_page.ex index b87a1da057..affe0b970a 100644 --- a/apps/explorer_web/test/explorer_web/features/pages/home_page.ex +++ b/apps/explorer_web/test/explorer_web/features/pages/home_page.ex @@ -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 diff --git a/apps/explorer_web/test/explorer_web/features/pages/transaction_list_page.ex b/apps/explorer_web/test/explorer_web/features/pages/transaction_list_page.ex index f99e73521f..f4f84d2853 100644 --- a/apps/explorer_web/test/explorer_web/features/pages/transaction_list_page.ex +++ b/apps/explorer_web/test/explorer_web/features/pages/transaction_list_page.ex @@ -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 diff --git a/apps/explorer_web/test/explorer_web/features/viewing_transactions_test.exs b/apps/explorer_web/test/explorer_web/features/viewing_transactions_test.exs index a7b1734d6f..2bdf507f0f 100644 --- a/apps/explorer_web/test/explorer_web/features/viewing_transactions_test.exs +++ b/apps/explorer_web/test/explorer_web/features/viewing_transactions_test.exs @@ -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