Merge pull request #5263 from blockscout/np-fix-contract-name-bug

Fix bug with name absence for contract
pull/5268/head
Victor Baranov 3 years ago committed by GitHub
commit 403e118c39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 8
      apps/block_scout_web/lib/block_scout_web/views/address_view.ex
  3. 26
      apps/block_scout_web/priv/gettext/default.pot
  4. 26
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  5. 4
      apps/block_scout_web/test/block_scout_web/views/address_view_test.exs
  6. 6
      apps/explorer/lib/explorer/chain.ex

@ -5,6 +5,7 @@
### Fixes
- [#5269](https://github.com/blockscout/blockscout/pull/5269) - Address Page: Fix implementation address align
- [#5264](https://github.com/blockscout/blockscout/pull/5264) - Fix bug with 500 response on `partial` sourcify status
- [#5263](https://github.com/blockscout/blockscout/pull/5263) - Fix bug with name absence for contract
- [#5259](https://github.com/blockscout/blockscout/pull/5259) - Fix `coin-balances/by-day` bug
- [#5239](https://github.com/blockscout/blockscout/pull/5239) - Add accounting for block rewards in `getblockreward` api method

@ -180,8 +180,12 @@ defmodule BlockScoutWeb.AddressView do
"""
def primary_name(%Address{names: [_ | _] = address_names}) do
case Enum.find(address_names, &(&1.primary == true)) do
nil -> nil
%Address.Name{name: name} -> name
nil ->
%Address.Name{name: name} = Enum.at(address_names, 0)
name
%Address.Name{name: name} ->
name
end
end

@ -430,7 +430,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:48
#: lib/block_scout_web/templates/address/overview.html.eex:291 lib/block_scout_web/templates/address_validation/index.html.eex:11
#: lib/block_scout_web/views/address_view.ex:356
#: lib/block_scout_web/views/address_view.ex:360
msgid "Blocks Validated"
msgstr ""
@ -569,13 +569,13 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:58
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:165 lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187
#: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:126 lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:149
#: lib/block_scout_web/views/address_view.ex:349
#: lib/block_scout_web/views/address_view.ex:353
msgid "Code"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:34
#: lib/block_scout_web/views/address_view.ex:355
#: lib/block_scout_web/views/address_view.ex:359
msgid "Coin Balance History"
msgstr ""
@ -910,7 +910,7 @@ msgid "Decoded"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/address_view.ex:350
#: lib/block_scout_web/views/address_view.ex:354
msgid "Decompiled Code"
msgstr ""
@ -1377,7 +1377,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:28
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:17 lib/block_scout_web/templates/transaction/_tabs.html.eex:11
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 lib/block_scout_web/views/address_view.ex:346
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 lib/block_scout_web/views/address_view.ex:350
#: lib/block_scout_web/views/transaction_view.ex:512
msgid "Internal Transactions"
msgstr ""
@ -1492,7 +1492,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:41
#: lib/block_scout_web/templates/address_logs/index.html.eex:10 lib/block_scout_web/templates/transaction/_tabs.html.eex:17
#: lib/block_scout_web/templates/transaction_log/index.html.eex:8 lib/block_scout_web/views/address_view.ex:357
#: lib/block_scout_web/templates/transaction_log/index.html.eex:8 lib/block_scout_web/views/address_view.ex:361
#: lib/block_scout_web/views/transaction_view.ex:513
msgid "Logs"
msgstr ""
@ -1933,14 +1933,14 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:81
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:27 lib/block_scout_web/views/address_view.ex:351
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:27 lib/block_scout_web/views/address_view.ex:355
#: lib/block_scout_web/views/tokens/overview_view.ex:43
msgid "Read Contract"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:88
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:41 lib/block_scout_web/views/address_view.ex:352
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:41 lib/block_scout_web/views/address_view.ex:356
msgid "Read Proxy"
msgstr ""
@ -2628,7 +2628,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:19 lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:3
#: lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:16 lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:5
#: lib/block_scout_web/templates/tokens/transfer/index.html.eex:14 lib/block_scout_web/templates/transaction/_tabs.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 lib/block_scout_web/views/address_view.ex:348
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 lib/block_scout_web/views/address_view.ex:352
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:186 lib/block_scout_web/views/tokens/overview_view.ex:41
#: lib/block_scout_web/views/transaction_view.ex:511
msgid "Token Transfers"
@ -2649,7 +2649,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/overview.html.eex:192 lib/block_scout_web/templates/address_token/overview.html.eex:58
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:13 lib/block_scout_web/templates/layout/_topnav.html.eex:69
#: lib/block_scout_web/templates/layout/_topnav.html.eex:101 lib/block_scout_web/templates/tokens/index.html.eex:10
#: lib/block_scout_web/views/address_view.ex:345
#: lib/block_scout_web/views/address_view.ex:349
msgid "Tokens"
msgstr ""
@ -2797,7 +2797,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/overview.html.eex:217 lib/block_scout_web/templates/address_transaction/index.html.eex:13
#: lib/block_scout_web/templates/block/overview.html.eex:80 lib/block_scout_web/templates/block_transaction/index.html.eex:10
#: lib/block_scout_web/templates/chain/show.html.eex:236 lib/block_scout_web/templates/layout/_topnav.html.eex:43
#: lib/block_scout_web/views/address_view.ex:347
#: lib/block_scout_web/views/address_view.ex:351
msgid "Transactions"
msgstr ""
@ -3139,13 +3139,13 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:95
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:34 lib/block_scout_web/views/address_view.ex:353
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:34 lib/block_scout_web/views/address_view.ex:357
msgid "Write Contract"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:102
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:48 lib/block_scout_web/views/address_view.ex:354
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:48 lib/block_scout_web/views/address_view.ex:358
msgid "Write Proxy"
msgstr ""

@ -430,7 +430,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:48
#: lib/block_scout_web/templates/address/overview.html.eex:291 lib/block_scout_web/templates/address_validation/index.html.eex:11
#: lib/block_scout_web/views/address_view.ex:356
#: lib/block_scout_web/views/address_view.ex:360
msgid "Blocks Validated"
msgstr ""
@ -569,13 +569,13 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:58
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:165 lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187
#: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:126 lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:149
#: lib/block_scout_web/views/address_view.ex:349
#: lib/block_scout_web/views/address_view.ex:353
msgid "Code"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:34
#: lib/block_scout_web/views/address_view.ex:355
#: lib/block_scout_web/views/address_view.ex:359
msgid "Coin Balance History"
msgstr ""
@ -910,7 +910,7 @@ msgid "Decoded"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/address_view.ex:350
#: lib/block_scout_web/views/address_view.ex:354
msgid "Decompiled Code"
msgstr ""
@ -1377,7 +1377,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:28
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:17 lib/block_scout_web/templates/transaction/_tabs.html.eex:11
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 lib/block_scout_web/views/address_view.ex:346
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 lib/block_scout_web/views/address_view.ex:350
#: lib/block_scout_web/views/transaction_view.ex:512
msgid "Internal Transactions"
msgstr ""
@ -1492,7 +1492,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:41
#: lib/block_scout_web/templates/address_logs/index.html.eex:10 lib/block_scout_web/templates/transaction/_tabs.html.eex:17
#: lib/block_scout_web/templates/transaction_log/index.html.eex:8 lib/block_scout_web/views/address_view.ex:357
#: lib/block_scout_web/templates/transaction_log/index.html.eex:8 lib/block_scout_web/views/address_view.ex:361
#: lib/block_scout_web/views/transaction_view.ex:513
msgid "Logs"
msgstr ""
@ -1933,14 +1933,14 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:81
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:27 lib/block_scout_web/views/address_view.ex:351
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:27 lib/block_scout_web/views/address_view.ex:355
#: lib/block_scout_web/views/tokens/overview_view.ex:43
msgid "Read Contract"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:88
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:41 lib/block_scout_web/views/address_view.ex:352
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:41 lib/block_scout_web/views/address_view.ex:356
msgid "Read Proxy"
msgstr ""
@ -2628,7 +2628,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:19 lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:3
#: lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:16 lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:5
#: lib/block_scout_web/templates/tokens/transfer/index.html.eex:14 lib/block_scout_web/templates/transaction/_tabs.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 lib/block_scout_web/views/address_view.ex:348
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 lib/block_scout_web/views/address_view.ex:352
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:186 lib/block_scout_web/views/tokens/overview_view.ex:41
#: lib/block_scout_web/views/transaction_view.ex:511
msgid "Token Transfers"
@ -2649,7 +2649,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/overview.html.eex:192 lib/block_scout_web/templates/address_token/overview.html.eex:58
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:13 lib/block_scout_web/templates/layout/_topnav.html.eex:69
#: lib/block_scout_web/templates/layout/_topnav.html.eex:101 lib/block_scout_web/templates/tokens/index.html.eex:10
#: lib/block_scout_web/views/address_view.ex:345
#: lib/block_scout_web/views/address_view.ex:349
msgid "Tokens"
msgstr ""
@ -2797,7 +2797,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/overview.html.eex:217 lib/block_scout_web/templates/address_transaction/index.html.eex:13
#: lib/block_scout_web/templates/block/overview.html.eex:80 lib/block_scout_web/templates/block_transaction/index.html.eex:10
#: lib/block_scout_web/templates/chain/show.html.eex:236 lib/block_scout_web/templates/layout/_topnav.html.eex:43
#: lib/block_scout_web/views/address_view.ex:347
#: lib/block_scout_web/views/address_view.ex:351
msgid "Transactions"
msgstr ""
@ -3139,13 +3139,13 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:95
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:34 lib/block_scout_web/views/address_view.ex:353
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:34 lib/block_scout_web/views/address_view.ex:357
msgid "Write Contract"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:102
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:48 lib/block_scout_web/views/address_view.ex:354
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:48 lib/block_scout_web/views/address_view.ex:358
msgid "Write Proxy"
msgstr ""

@ -218,11 +218,11 @@ defmodule BlockScoutWeb.AddressViewTest do
assert AddressView.primary_name(preloaded_address) == address_name.name
end
test "returns nil when no primary available" do
test "returns any when no primary available" do
address_name = insert(:address_name, name: "POA Wallet")
preloaded_address = Explorer.Repo.preload(address_name.address, :names)
refute AddressView.primary_name(preloaded_address)
assert AddressView.primary_name(preloaded_address) == address_name.name
end
end

@ -4013,10 +4013,6 @@ defmodule Explorer.Chain do
Multi.new()
|> Multi.run(:set_address_verified, fn repo, _ -> set_address_verified(repo, address_hash) end)
|> Multi.run(:clear_primary_address_names, fn repo, _ -> clear_primary_address_names(repo, address_hash) end)
|> Multi.run(:insert_address_name, fn repo, _ ->
name = Changeset.get_field(smart_contract_changeset, :name)
create_address_name(repo, name, address_hash)
end)
|> Multi.insert(:smart_contract, smart_contract_changeset)
insert_contract_query_with_additional_sources =
@ -4030,6 +4026,8 @@ defmodule Explorer.Chain do
insert_contract_query_with_additional_sources
|> Repo.transaction()
create_address_name(Repo, Changeset.get_field(smart_contract_changeset, :name), address_hash)
case insert_result do
{:ok, %{smart_contract: smart_contract}} ->
{:ok, smart_contract}

Loading…
Cancel
Save