chore: remove single implementation name, address from API v2 response (#10390)

pull/10392/head
Victor Baranov 5 months ago committed by GitHub
parent 3c268d2196
commit fd22965fca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 17
      apps/block_scout_web/lib/block_scout_web/views/api/v2/address_view.ex
  2. 17
      apps/block_scout_web/lib/block_scout_web/views/api/v2/helper.ex
  3. 6
      apps/block_scout_web/test/block_scout_web/controllers/account/api/v2/user_controller_test.exs
  4. 5
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs

@ -113,9 +113,6 @@ defmodule BlockScoutWeb.API.V2.AddressView do
creation_tx = creator_hash && AddressView.transaction_hash(address)
token = address.token && TokenView.render("token.json", %{token: address.token})
# todo: added for backward compatibility, remove when frontend unbound from these props
{implementation_address, implementation_name} = single_implementation(implementations)
extended_info =
Map.merge(base_info, %{
"creator_address_hash" => creator_hash && Address.checksum(creator_hash),
@ -137,25 +134,11 @@ defmodule BlockScoutWeb.API.V2.AddressView do
extended_info
else
Map.merge(extended_info, %{
# todo: added for backward compatibility, remove when frontend unbound from these props
"implementation_address" => implementation_address,
"implementation_name" => implementation_name,
"implementations" => implementations
})
end
end
defp single_implementation(implementations) do
%{"address" => implementation_address, "name" => implementation_name} =
if Enum.empty?(implementations) do
%{"address" => nil, "name" => nil}
else
implementations |> Enum.at(0)
end
{implementation_address, implementation_name}
end
@spec prepare_token_balance(Chain.Address.TokenBalance.t(), boolean()) :: map()
defp prepare_token_balance(token_balance, fetch_token_instance? \\ false) do
%{

@ -64,31 +64,25 @@ defmodule BlockScoutWeb.API.V2.Helper do
def address_with_info(%Address{} = address, _address_hash) do
smart_contract? = Address.smart_contract?(address)
{proxy_implementations, implementation_address_hashes, implementation_names, implementation_address,
implementation_name} =
{proxy_implementations, implementation_address_hashes, implementation_names} =
case address.proxy_implementations do
%NotLoaded{} ->
{nil, [], [], nil, nil}
{nil, [], []}
nil ->
{nil, [], [], nil, nil}
{nil, [], []}
proxy_implementations ->
address_hashes = proxy_implementations.address_hashes
names = proxy_implementations.names
address_hash = Enum.at(address_hashes, 0) && address_hashes |> Enum.at(0) |> Address.checksum()
{proxy_implementations, address_hashes, names, address_hash, Enum.at(names, 0)}
{proxy_implementations, address_hashes, names}
end
%{
"hash" => Address.checksum(address),
"is_contract" => smart_contract?,
"name" => address_name(address),
# todo: added for backward compatibility, remove when frontend unbound from these props
"implementation_address" => implementation_address,
"implementation_name" => implementation_name,
"implementations" => proxy_object_info(implementation_address_hashes, implementation_names),
"is_verified" => verified?(address) || verified_minimal_proxy?(proxy_implementations),
"ens_domain_name" => address.ens_domain_name,
@ -116,9 +110,6 @@ defmodule BlockScoutWeb.API.V2.Helper do
"hash" => Address.checksum(address_hash),
"is_contract" => false,
"name" => nil,
# todo: added for backward compatibility, remove when frontend unbound from these props
"implementation_address" => nil,
"implementation_name" => nil,
"implementations" => [],
"is_verified" => nil,
"ens_domain_name" => nil,

@ -151,9 +151,6 @@ defmodule BlockScoutWeb.Account.Api.V2.UserControllerTest do
"name" => name,
"address" => %{
"hash" => Address.checksum(addr),
# todo: added for backward compatibility, remove when frontend unbound from these props
"implementation_address" => nil,
"implementation_name" => nil,
"implementations" => [],
"is_contract" => false,
"is_verified" => false,
@ -210,9 +207,6 @@ defmodule BlockScoutWeb.Account.Api.V2.UserControllerTest do
"name" => name,
"address" => %{
"hash" => Address.checksum(addr),
# todo: added for backward compatibility, remove when frontend unbound from these props
"implementation_address" => nil,
"implementation_name" => nil,
"implementations" => [],
"is_contract" => false,
"is_verified" => false,

@ -71,9 +71,6 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
"creation_tx_hash" => nil,
"token" => nil,
"coin_balance" => nil,
# todo: added for backward compatibility, remove when frontend unbound from these props
"implementation_address" => nil,
"implementation_name" => nil,
"implementations" => [],
"block_number_balance_updated_at" => nil,
"has_decompiled_code" => false,
@ -209,7 +206,6 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
"watchlist_names" => [],
"creator_address_hash" => ^from,
"creation_tx_hash" => ^tx_hash,
"implementation_address" => ^checksummed_implementation_contract_address_hash,
"implementations" => [
%{"address" => ^checksummed_implementation_contract_address_hash, "name" => ^name}
]
@ -255,7 +251,6 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
"watchlist_names" => [],
"creator_address_hash" => ^from,
"creation_tx_hash" => ^tx_hash,
"implementation_address" => ^implementation_address_hash_string,
"implementations" => [%{"address" => ^implementation_address_hash_string, "name" => nil}]
} = json_response(request, 200)
end

Loading…
Cancel
Save