Change Transaction Details redirection behaviour

Redirects to Token Transfers if the transaction contains token
transfers, otherwise keeps the old way of redirecting to Internal
Transactions.
pull/496/head
Lucas Narciso 6 years ago
parent 42f7c3e168
commit b816543851
No known key found for this signature in database
GPG Key ID: 9E89F4CF3FBAB001
  1. 8
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_controller.ex
  2. 4
      apps/block_scout_web/lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex
  3. 2
      apps/block_scout_web/lib/block_scout_web/templates/transaction_log/index.html.eex
  4. 23
      apps/block_scout_web/test/block_scout_web/controllers/transaction_controller_test.exs

@ -34,6 +34,12 @@ defmodule BlockScoutWeb.TransactionController do
end
def show(conn, %{"id" => id, "locale" => locale}) do
redirect(conn, to: transaction_internal_transaction_path(conn, :index, locale, id))
{:ok, transaction_hash} = Chain.string_to_transaction_hash(id)
if Chain.transaction_has_token_transfers?(transaction_hash) do
redirect(conn, to: transaction_token_transfer_path(conn, :index, locale, id))
else
redirect(conn, to: transaction_internal_transaction_path(conn, :index, locale, id))
end
end
end

@ -19,7 +19,7 @@
<%= link(
gettext("Internal Transactions"),
class: "nav-link active",
to: transaction_path(@conn, :show, @conn.assigns.locale, @transaction)
to: transaction_internal_transaction_path(@conn, :index, @conn.assigns.locale, @transaction)
) %>
</li>
<li class="nav-item">
@ -48,7 +48,7 @@
<%= link(
gettext("Internal Transactions"),
class: "dropdown-item",
to: transaction_path(@conn, :show, @conn.assigns.locale, @transaction)
to: transaction_internal_transaction_path(@conn, :index, @conn.assigns.locale, @transaction)
) %>
<%= link(
gettext("Logs"),

@ -20,7 +20,7 @@
<%= link(
gettext("Internal Transactions"),
class: "nav-link",
to: transaction_path(@conn, :show, @conn.assigns.locale, @transaction)
to: transaction_internal_transaction_path(@conn, :index, @conn.assigns.locale, @transaction)
) %>
</li>
<li class="nav-item">

@ -2,7 +2,8 @@ defmodule BlockScoutWeb.TransactionControllerTest do
use BlockScoutWeb.ConnCase
alias Explorer.Chain.{Block, Transaction}
import BlockScoutWeb.Router.Helpers, only: [transaction_path: 4, transaction_internal_transaction_path: 4]
import BlockScoutWeb.Router.Helpers,
only: [transaction_path: 4, transaction_internal_transaction_path: 4, transaction_token_transfer_path: 4]
describe "GET index/2" do
test "returns a collated transactions", %{conn: conn} do
@ -98,12 +99,24 @@ defmodule BlockScoutWeb.TransactionControllerTest do
end
describe "GET show/3" do
test "redirects to transactions/:transaction_id/internal_transactions", %{conn: conn} do
test "redirects to transactions/:transaction_id/token_transfers when there are token transfers", %{conn: conn} do
locale = "en"
hash = "0x9"
conn = get(conn, transaction_path(BlockScoutWeb.Endpoint, :show, locale, hash))
transaction = insert(:transaction)
insert(:token_transfer, transaction: transaction)
conn = get(conn, transaction_path(BlockScoutWeb.Endpoint, :show, locale, transaction))
assert redirected_to(conn) =~ transaction_internal_transaction_path(BlockScoutWeb.Endpoint, :index, locale, hash)
assert redirected_to(conn) =~ transaction_token_transfer_path(BlockScoutWeb.Endpoint, :index, locale, transaction)
end
test "redirects to transactions/:transaction_id/internal_transactions when there are no token transfers", %{
conn: conn
} do
locale = "en"
transaction = insert(:transaction)
conn = get(conn, transaction_path(BlockScoutWeb.Endpoint, :show, locale, transaction))
assert redirected_to(conn) =~
transaction_internal_transaction_path(BlockScoutWeb.Endpoint, :index, locale, transaction)
end
end
end

Loading…
Cancel
Save