From b717371a4d6b1a400b6bd75d431d043e582988d0 Mon Sep 17 00:00:00 2001 From: natlg Date: Wed, 5 Dec 2018 00:23:46 -0800 Subject: [PATCH 1/2] Add primary names to the top accounts page --- .../templates/address/_responsive_hash.html.eex | 7 ++++++- .../controllers/address_controller_test.exs | 9 +++++++++ apps/explorer/lib/explorer/chain.ex | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex index bea2a2159f..23e05644f8 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex @@ -1,6 +1,11 @@ <%= if name = primary_name(@address) do %> - <%= name %> (<%= short_hash(@address) %>...) + <%= if assigns[:truncate] do %> + <%= name %> (<%= short_hash(@address) %>...) + <% else %> + <%= name %> (<%= @address.hash %>) + <%= name %> (<%= BlockScoutWeb.AddressView.trimmed_hash(@address.hash) %>) + <% end %> <% else %> <%= if assigns[:truncate] do %> <%= BlockScoutWeb.AddressView.trimmed_hash(@address.hash) %> diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs index 071667cf77..6e917a4aab 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs @@ -14,6 +14,15 @@ defmodule BlockScoutWeb.AddressControllerTest do |> Enum.map(fn {address, _transaction_count} -> address end) |> Enum.map(& &1.hash) == address_hashes end + + test "returns an address's primary name when present", %{conn: conn} do + address = insert(:address) + address_name = insert(:address_name, address: address, primary: true, name: "POA Wallet3") + + conn = get(conn, address_path(conn, :index)) + + assert html_response(conn, 200) =~ address_name.name + end end describe "GET show/3" do diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 24ac174873..63509f9315 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -913,6 +913,7 @@ defmodule Explorer.Chain do from(a in Address, where: a.fetched_coin_balance > ^0, order_by: [desc: a.fetched_coin_balance, asc: a.hash], + preload: [:names], select: {a, fragment("coalesce(1 + ?, 0)", a.nonce)}, limit: 250 ) From 01e19cb13d8e931b2a74de141a18e511f03d3446 Mon Sep 17 00:00:00 2001 From: natlg Date: Wed, 5 Dec 2018 12:27:26 -0800 Subject: [PATCH 2/2] Fix test --- .../block_scout_web/controllers/address_controller_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs index 6e917a4aab..7734ef05aa 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs @@ -16,8 +16,8 @@ defmodule BlockScoutWeb.AddressControllerTest do end test "returns an address's primary name when present", %{conn: conn} do - address = insert(:address) - address_name = insert(:address_name, address: address, primary: true, name: "POA Wallet3") + address = insert(:address, fetched_coin_balance: 1) + address_name = insert(:address_name, address: address, primary: true, name: "POA Wallet") conn = get(conn, address_path(conn, :index))