Add internal transactions tab to address page

Co-authored-by: jimmay5469 <jimmay5469@gmail.com>
pull/156/head
Tim Mecklem 7 years ago
parent ae9ed5f5ce
commit b0bc8ff932
  1. 45
      apps/explorer_web/lib/explorer_web/controllers/address_internal_transaction_controller.ex
  2. 11
      apps/explorer_web/lib/explorer_web/router.ex
  3. 16
      apps/explorer_web/lib/explorer_web/templates/address/overview.html.eex
  4. 22
      apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex
  5. 25
      apps/explorer_web/lib/explorer_web/templates/address_transaction/index.html.eex
  6. 3
      apps/explorer_web/lib/explorer_web/views/address_internal_transaction_view.ex
  7. 3
      apps/explorer_web/lib/explorer_web/views/address_transaction_view.ex
  8. 2
      apps/explorer_web/mix.exs
  9. 31
      apps/explorer_web/test/explorer_web/features/address_page_test.exs
  10. 25
      apps/explorer_web/test/explorer_web/features/pages/address_page.ex

@ -0,0 +1,45 @@
defmodule ExplorerWeb.AddressInternalTransactionController do
@moduledoc """
Display all the Transactions that terminate at this Address.
"""
use ExplorerWeb, :controller
alias Explorer.Chain
def index(conn, %{"address_id" => address_hash}) do
case Chain.hash_to_address(address_hash) do
{:ok, address} ->
# options = [
# necessity_by_association: %{
# block: :required,
# from_address: :optional,
# to_address: :optional,
# receipt: :required
# },
# pagination: params
# ]
# page =
# Chain.address_to_transactions(
# address,
# Keyword.merge(options, current_filter(params))
# )
render(conn, "index.html", address: address)
{:error, :not_found} ->
not_found(conn)
end
end
# defp current_filter(params) do
# params
# |> Map.get("filter")
# |> case do
# "to" -> [direction: :to]
# "from" -> [direction: :from]
# _ -> []
# end
# end
end

@ -40,7 +40,8 @@ defmodule ExplorerWeb.Router do
end end
pipeline :jasmine do pipeline :jasmine do
if Mix.env() != :prod, do: plug(Jasmine, js_files: ["js/test.js"], css_files: ["css/test.css"]) if Mix.env() != :prod,
do: plug(Jasmine, js_files: ["js/test.js"], css_files: ["css/test.css"])
end end
pipeline :api do pipeline :api do
@ -76,11 +77,13 @@ defmodule ExplorerWeb.Router do
end end
resources "/addresses", AddressController, only: [:show] do resources "/addresses", AddressController, only: [:show] do
resources("/transactions", AddressTransactionController, only: [:index], as: :transaction)
resources( resources(
"/transactions", "/internal_transactions",
AddressTransactionController, AddressInternalTransactionController,
only: [:index], only: [:index],
as: :transaction as: :internal_transaction
) )
end end

@ -0,0 +1,16 @@
<div class="address__header">
<h1 class="address__heading"><%= gettext "Address" %></h1>
<h3 class="address__subheading"><%= @address.hash %></h3>
</div>
<div class="address__container">
<div class="address__attributes">
<dl>
<div class="address__item">
<dt class="address__item-key"><%= gettext "Balance" %></dt>
<dd class="address__item-value address__balance" title="<%= @address.hash %>">
<%= balance(@address) %> <%= gettext "Ether" %>
</dd>
</div>
</dl>
</div>
</div>

@ -0,0 +1,22 @@
<section class="container__section block">
<%= render ExplorerWeb.AddressView, "overview.html", assigns %>
<div class="address__container">
<div class="address__tabs">
<h2 class="address__tab address__tab">
<%= link(
gettext("Transactions"),
class: "address__link address__link",
to: address_transaction_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"])
) %>
</h2>
<h2 class="address__tab address__tab--active">
<%= link(
gettext("Internal Transactions"),
class: "address__link address__link--active",
to: address_internal_transaction_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"])
) %>
</h2>
</div>
</div>
</section>

@ -1,20 +1,5 @@
<section class="container__section block"> <section class="container__section block">
<div class="address__header"> <%= render ExplorerWeb.AddressView, "overview.html", assigns %>
<h1 class="address__heading"><%= gettext "Address" %></h1>
<h3 class="address__subheading"><%= @address.hash %></h3>
</div>
<div class="address__container">
<div class="address__attributes">
<dl>
<div class="address__item">
<dt class="address__item-key"><%= gettext "Balance" %></dt>
<dd class="address__item-value address__balance" title="<%= @address.hash %>">
<%= balance(@address) %> <%= gettext "Ether" %>
</dd>
</div>
</dl>
</div>
</div>
<div class="address__container"> <div class="address__container">
<div class="address__tabs"> <div class="address__tabs">
@ -25,6 +10,14 @@
to: address_transaction_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"]) to: address_transaction_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"])
) %> ) %>
</h2> </h2>
<h2 class="address__tab address__tab">
<%= link(
gettext("Internal Transactions"),
class: "address__link address__link",
"data-test": "internal_transactions_tab_link",
to: address_internal_transaction_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"])
) %>
</h2>
</div> </div>
<div class="dropdown u-float-right u-push-sm-right u-push-sm-bottom"> <div class="dropdown u-float-right u-push-sm-right u-push-sm-bottom">
<button data-test="filter_dropdown" class="button button--secondary dropdown-toggle" type="button" <button data-test="filter_dropdown" class="button button--secondary dropdown-toggle" type="button"

@ -0,0 +1,3 @@
defmodule ExplorerWeb.AddressInternalTransactionView do
use ExplorerWeb, :view
end

@ -1,9 +1,8 @@
defmodule ExplorerWeb.AddressTransactionView do defmodule ExplorerWeb.AddressTransactionView do
use ExplorerWeb, :view use ExplorerWeb, :view
alias ExplorerWeb.{AddressView, TransactionView} alias ExplorerWeb.TransactionView
defdelegate balance(address), to: AddressView
defdelegate fee(transaction), to: TransactionView defdelegate fee(transaction), to: TransactionView
def format_current_filter(filter) do def format_current_filter(filter) do

@ -41,7 +41,7 @@ defmodule ExplorerWeb.Mixfile do
end end
# Specifies which paths to compile per environment. # Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["test/support" | elixirc_paths()] defp elixirc_paths(:test), do: ["test/support", "test/explorer_web/features/pages"] ++ elixirc_paths()
defp elixirc_paths(_), do: elixirc_paths() defp elixirc_paths(_), do: elixirc_paths()
defp elixirc_paths, do: ["lib"] defp elixirc_paths, do: ["lib"]

@ -4,6 +4,7 @@ defmodule ExplorerWeb.AddressPageTest do
import Wallaby.Query, only: [css: 2] import Wallaby.Query, only: [css: 2]
alias Explorer.Chain.{Credit, Debit} alias Explorer.Chain.{Credit, Debit}
alias ExplorerWeb.AddressPage
setup do setup do
block = block =
@ -60,22 +61,28 @@ defmodule ExplorerWeb.AddressPageTest do
{:ok, %{internal: internal}} {:ok, %{internal: internal}}
end end
test "see's all addresses transactions by default", %{session: session} do def assert_true(session, assertion) do
assert assertion.(session)
session session
|> visit("/en/addresses/0xlincoln")
|> assert_has(css(".transactions__link--long-hash", text: "0xSk8"))
|> assert_has(css(".transactions__link--long-hash", text: "0xrazerscooter"))
end end
# test "can see internal transactions for an address", %{ test "sees all addresses transactions by default", %{session: session} do
# session: session, session
|> AddressPage.visit_page("0xlincoln")
|> assert_has(AddressPage.transaction("0xSk8"))
|> assert_has(AddressPage.transaction("0xrazerscooter"))
end
test "can see internal transactions for an address", %{
session: session
# internal: internal # internal: internal
# } do } do
# session
# |> visit("/en/transactions/0xSk8") session
# |> click(link("Internal Transactions")) |> AddressPage.visit_page("0xlincoln")
# |> assert_has(css(".internal-transaction__table", text: internal.call_type)) |> AddressPage.click_internal_transactions()
# end |> assert_has(AddressPage.internal_transactions(count: 1))
end
test "can filter to only see transactions to an address", %{session: session} do test "can filter to only see transactions to an address", %{session: session} do
session session

@ -0,0 +1,25 @@
defmodule ExplorerWeb.AddressPage do
@moduledoc false
use Wallaby.DSL
import Wallaby.Query, only: [css: 1, css: 2]
def visit_page(session, address_hash) do
visit(session, "/en/addresses/#{address_hash}")
end
@internal_transactions_link_selector "[data-test='internal_transactions_tab_link']"
def click_internal_transactions(session) do
click(session, css(@internal_transactions_link_selector))
end
@transaction_selector ".transactions__link--long-hash"
def transaction(transaction_hash) do
css(@transaction_selector, text: transaction_hash)
end
@internal_transactions_selector "[data-test='internal_transaction']"
def internal_transactions(count: count) do
css(@internal_transactions_selector, count: count)
end
end
Loading…
Cancel
Save