Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request blockscout#55 from celo-org/account-names
Browse files Browse the repository at this point in the history
Adding account names
  • Loading branch information
mrsmkl committed Dec 17, 2019
2 parents 9e9d39a + 7aca37e commit 7bf8129
Show file tree
Hide file tree
Showing 20 changed files with 182 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ defmodule BlockScoutWeb.BlockController do
necessity_by_association: %{
:transactions => :optional,
[miner: :names] => :optional,
:celo_delegator => :optional,
[celo_delegator: :celo_account] => :optional,
:rewards => :optional
},
block_type: "Block"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ defmodule BlockScoutWeb.BlockTransactionController do
case param_block_hash_or_number_to_block(formatted_block_hash_or_number,
necessity_by_association: %{
[miner: :names] => :required,
[celo_delegator: :celo_account] => :optional,
:uncles => :optional,
:nephews => :optional,
:rewards => :optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ defmodule BlockScoutWeb.ChainController do
paging_options: %PagingOptions{page_size: 4},
necessity_by_association: %{
[miner: :names] => :optional,
[celo_delegator: :celo_account] => :optional,
:transactions => :optional,
:rewards => :optional
}
Expand Down
2 changes: 1 addition & 1 deletion apps/block_scout_web/lib/block_scout_web/notifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ defmodule BlockScoutWeb.Notifier do
end

defp broadcast_block(block) do
preloaded_block = Repo.preload(block, [[miner: :names], :transactions, :rewards])
preloaded_block = Repo.preload(block, [[miner: :names], [celo_delegator: :celo_account], :transactions, :rewards])
average_block_time = AverageBlockTime.average_block_time()

Endpoint.broadcast("blocks:new_block", "new_block", %{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div class="tile tile-type-<%= String.downcase(@block_type) %> fade-up" data-selector="block-tile" data-block-number="<%= to_string(@block.number) %>" data-block-hash="<%= @block.hash %>">
<div class="row">
<div class="tile-transaction-type-block col-md-2 d-flex flex-row flex-md-column">
<%= if @block_type == "Block" do %>
<%=
if @block_type == "Block" do %>
<%= link(
class: "tile-label",
to: block_path(BlockScoutWeb.Endpoint, :show, @block),
Expand Down Expand Up @@ -38,7 +39,7 @@
<%= gettext "Miner" %>
<%= render BlockScoutWeb.AddressView,
"_link.html",
address: @block.miner,
address: block_miner(@block),
contract: false %>
</div>
<%= if show_reward?(@block.rewards) do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@

<%= render BlockScoutWeb.AddressView,
"_link.html",
address: @block.miner,
address: block_miner(@block),
contract: false,
class: "" %>
</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<%= gettext "Miner" %>
<%= render BlockScoutWeb.AddressView,
"_link.html",
address: @block.miner,
address: BlockScoutWeb.BlockView.block_miner(@block),
contract: false %>
</div>
<%= if BlockScoutWeb.BlockView.show_reward?(@block.rewards) do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ defmodule BlockScoutWeb.AddressView do
end
end

def primary_name(%Address{names: _}), do: nil
def primary_name(%Address{names: _} = _address) do
nil
end

def primary_validator_metadata(%Address{names: [_ | _] = address_names}) do
case Enum.find(address_names, &(&1.primary == true)) do
Expand Down
21 changes: 20 additions & 1 deletion apps/block_scout_web/lib/block_scout_web/views/block_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule BlockScoutWeb.BlockView do
import Math.Enum, only: [mean: 1]

alias Explorer.Chain
alias Explorer.Chain.{Block, Wei}
alias Explorer.Chain.{Address, Block, Wei}
alias Explorer.Chain.Block.Reward

@dialyzer :no_match
Expand All @@ -26,6 +26,25 @@ defmodule BlockScoutWeb.BlockView do
def block_type(%Block{consensus: false}), do: "Uncle"
def block_type(_block), do: "Block"

def block_miner(block) do
if block.miner.names == [] and
Ecto.assoc_loaded?(block.celo_delegator) and
block.celo_delegator != nil and
block.celo_delegator.celo_account != nil do
named = %Address.Name{
address: block.celo_delegator.celo_account.account_address,
address_hash: block.celo_delegator.celo_account.address,
name: block.celo_delegator.celo_account.name <> " (signer)",
primary: true,
metadata: %{}
}

%{block.miner | names: [named]}
else
block.miner
end
end

@doc """
Work-around for spec issue in `Cldr.Unit.to_string!/1`
"""
Expand Down
34 changes: 17 additions & 17 deletions apps/block_scout_web/priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgstr[0] ""
msgstr[1] ""

#, elixir-format
#: lib/block_scout_web/templates/block/_tile.html.eex:27
#: lib/block_scout_web/templates/block/_tile.html.eex:28
msgid "%{count} transaction"
msgid_plural "%{count} transactions"
msgstr[0] ""
Expand Down Expand Up @@ -252,7 +252,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:32
#: lib/block_scout_web/templates/address/overview.html.eex:97
#: lib/block_scout_web/templates/address_validation/index.html.eex:13
#: lib/block_scout_web/views/address_view.ex:340
#: lib/block_scout_web/views/address_view.ex:342
msgid "Blocks Validated"
msgstr ""

Expand Down Expand Up @@ -306,13 +306,13 @@ msgstr ""
#: 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:336
#: lib/block_scout_web/views/address_view.ex:338
msgid "Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:20
#: lib/block_scout_web/views/address_view.ex:339
#: lib/block_scout_web/views/address_view.ex:341
msgid "Coin Balance History"
msgstr ""

Expand Down Expand Up @@ -527,7 +527,7 @@ msgid "Decoded"
msgstr ""

#, elixir-format
#: lib/block_scout_web/views/address_view.ex:337
#: lib/block_scout_web/views/address_view.ex:339
msgid "Decompiled Code"
msgstr ""

Expand All @@ -547,14 +547,14 @@ msgid "Decompiler version"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/_tile.html.eex:56
#: lib/block_scout_web/templates/block/_tile.html.eex:57
#: lib/block_scout_web/templates/block/overview.html.eex:108
#: lib/block_scout_web/templates/block/overview.html.eex:158
msgid "Gas Limit"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/_tile.html.eex:61
#: lib/block_scout_web/templates/block/_tile.html.eex:62
#: lib/block_scout_web/templates/block/overview.html.eex:101
#: lib/block_scout_web/templates/block/overview.html.eex:152
msgid "Gas Used"
Expand Down Expand Up @@ -627,7 +627,7 @@ msgid "Emission Contract"
msgstr ""

#, elixir-format
#: lib/block_scout_web/views/block_view.ex:60
#: lib/block_scout_web/views/block_view.ex:79
msgid "Emission Reward"
msgstr ""

Expand All @@ -642,7 +642,7 @@ msgid "Error rendering value"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/_tile.html.eex:38
#: lib/block_scout_web/templates/block/_tile.html.eex:39
#: lib/block_scout_web/templates/block/overview.html.eex:124
#: lib/block_scout_web/templates/chain/_block.html.eex:15
msgid "Miner"
Expand Down Expand Up @@ -937,7 +937,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:8
#: lib/block_scout_web/templates/address_token/index.html.eex:8
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:9
#: lib/block_scout_web/views/address_view.ex:333
#: lib/block_scout_web/views/address_view.ex:335
msgid "Tokens"
msgstr ""

Expand Down Expand Up @@ -990,7 +990,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:19
#: 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:335
#: lib/block_scout_web/views/address_view.ex:337
#: lib/block_scout_web/views/transaction_view.ex:323
msgid "Internal Transactions"
msgstr ""
Expand Down Expand Up @@ -1079,7 +1079,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_logs/index.html.eex:8
#: 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:341
#: lib/block_scout_web/views/address_view.ex:343
#: lib/block_scout_web/views/transaction_view.ex:324
msgid "Logs"
msgstr ""
Expand Down Expand Up @@ -1114,7 +1114,7 @@ msgid "Method Id"
msgstr ""

#, elixir-format
#: lib/block_scout_web/views/block_view.ex:56
#: lib/block_scout_web/views/block_view.ex:75
msgid "Miner Reward"
msgstr ""

Expand Down Expand Up @@ -1270,7 +1270,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:66
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:25
#: lib/block_scout_web/views/address_view.ex:338
#: lib/block_scout_web/views/address_view.ex:340
#: lib/block_scout_web/views/tokens/overview_view.ex:37
msgid "Read Contract"
msgstr ""
Expand Down Expand Up @@ -1304,7 +1304,7 @@ msgid "Responses"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/_tile.html.eex:47
#: lib/block_scout_web/templates/block/_tile.html.eex:48
#: lib/block_scout_web/templates/chain/_block.html.eex:23
#: lib/block_scout_web/views/internal_transaction_view.ex:28
msgid "Reward"
Expand Down Expand Up @@ -1562,7 +1562,7 @@ msgstr ""
#: lib/block_scout_web/templates/block_transaction/index.html.eex:18
#: lib/block_scout_web/templates/chain/show.html.eex:145
#: lib/block_scout_web/templates/layout/_topnav.html.eex:64
#: lib/block_scout_web/views/address_view.ex:334
#: lib/block_scout_web/views/address_view.ex:336
msgid "Transactions"
msgstr ""

Expand Down Expand Up @@ -1602,7 +1602,7 @@ msgid "UTF-8"
msgstr ""

#, elixir-format
#: lib/block_scout_web/views/block_view.ex:64
#: lib/block_scout_web/views/block_view.ex:83
msgid "Uncle Reward"
msgstr ""

Expand Down

0 comments on commit 7bf8129

Please sign in to comment.