Merge pull request #1900 from poanetwork/supported-chains-env-var

SUPPORTED_CHAINS ENV var
pull/1941/head
Victor Baranov 6 years ago committed by GitHub
commit cc3b0df467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .dialyzer-ignore
  2. 1
      CHANGELOG.md
  3. 60
      apps/block_scout_web/config/config.exs
  4. 4
      apps/block_scout_web/lib/block_scout_web/templates/layout/_footer.html.eex
  5. 6
      apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex
  6. 100
      apps/block_scout_web/lib/block_scout_web/views/layout_view.ex
  7. 119
      apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs

@ -4,3 +4,4 @@
apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex:400: Function timestamp_to_datetime/1 has no local return apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex:400: Function timestamp_to_datetime/1 has no local return
apps/explorer/lib/explorer/repo/prometheus_logger.ex:8: Function microseconds_time/1 has no local return apps/explorer/lib/explorer/repo/prometheus_logger.ex:8: Function microseconds_time/1 has no local return
apps/explorer/lib/explorer/repo/prometheus_logger.ex:8: The call 'Elixir.System':convert_time_unit(__@1::any(),'native','microseconds') breaks the contract (integer(),time_unit() | 'native',time_unit() | 'native') -> integer() apps/explorer/lib/explorer/repo/prometheus_logger.ex:8: The call 'Elixir.System':convert_time_unit(__@1::any(),'native','microseconds') breaks the contract (integer(),time_unit() | 'native',time_unit() | 'native') -> integer()
apps/block_scout_web/lib/block_scout_web/views/layout_view.ex:162: The call 'Elixir.Poison.Parser':'parse!'(any(),#{'keys':='atoms!'}) will never return since the success typing is (binary() | maybe_improper_list(binary() | maybe_improper_list(any(),binary() | []) | byte(),binary() | []),[{atom(),_}]) -> 'false' | 'nil' | 'true' | binary() | ['false' | 'nil' | 'true' | binary() | [any()] | number() | map()] | number() | map() and the contract is (iodata(),'Elixir.Keyword':t()) -> t()

@ -40,6 +40,7 @@
- [#1814](https://github.com/poanetwork/blockscout/pull/1814) - Clear build artefacts script - [#1814](https://github.com/poanetwork/blockscout/pull/1814) - Clear build artefacts script
- [#1837](https://github.com/poanetwork/blockscout/pull/1837) - Add -f flag to clear_build.sh script delete static folder - [#1837](https://github.com/poanetwork/blockscout/pull/1837) - Add -f flag to clear_build.sh script delete static folder
- [#1900](https://github.com/poanetwork/blockscout/pull/1900) - SUPPORTED_CHAINS ENV var
- [#1892](https://github.com/poanetwork/blockscout/pull/1892) - Remove temporary worker modules - [#1892](https://github.com/poanetwork/blockscout/pull/1892) - Remove temporary worker modules
## 1.3.10-beta ## 1.3.10-beta

@ -28,65 +28,7 @@ config :block_scout_web,
"EtherChain" => "https://www.etherchain.org/", "EtherChain" => "https://www.etherchain.org/",
"Bloxy" => "https://bloxy.info/" "Bloxy" => "https://bloxy.info/"
}, },
other_networks: [ other_networks: System.get_env("SUPPORTED_CHAINS")
%{
title: "POA Core",
url: "https://blockscout.com/poa/core"
},
%{
title: "POA Sokol",
url: "https://blockscout.com/poa/sokol",
test_net?: true
},
%{
title: "xDai Chain",
url: "https://blockscout.com/poa/dai"
},
%{
title: "Ethereum Mainnet",
url: "https://blockscout.com/eth/mainnet"
},
%{
title: "Kovan Testnet",
url: "https://blockscout.com/eth/kovan",
test_net?: true
},
%{
title: "Ropsten Testnet",
url: "https://blockscout.com/eth/ropsten",
test_net?: true
},
%{
title: "Goerli Testnet",
url: "https://blockscout.com/eth/goerli",
test_net?: true
},
%{
title: "Rinkeby Testnet",
url: "https://blockscout.com/eth/rinkeby",
test_net?: true
},
%{
title: "Ethereum Classic",
url: "https://blockscout.com/etc/mainnet",
other?: true
},
%{
title: "Aerum Mainnet",
url: "https://blockscout.com/aerum/mainnet",
other?: true
},
%{
title: "Callisto Mainnet",
url: "https://blockscout.com/callisto/mainnet",
other?: true
},
%{
title: "RSK Mainnet",
url: "https://blockscout.com/rsk/mainnet",
other?: true
}
]
config :block_scout_web, BlockScoutWeb.Counters.BlocksIndexedCounter, enabled: true config :block_scout_web, BlockScoutWeb.Counters.BlocksIndexedCounter, enabled: true

@ -37,7 +37,7 @@
<li><a href="https://forum.poa.network/c/blockscout" rel="noreferrer" class="footer-link"><%= gettext("Support") %></a></li> <li><a href="https://forum.poa.network/c/blockscout" rel="noreferrer" class="footer-link"><%= gettext("Support") %></a></li>
</ul> </ul>
</div> </div>
<% main_nets = main_nets() %> <% main_nets = main_nets(other_networks()) %>
<%= unless Enum.empty?(main_nets) do %> <%= unless Enum.empty?(main_nets) do %>
<div class="col-md-<%= col_size %> footer-list"> <div class="col-md-<%= col_size %> footer-list">
@ -50,7 +50,7 @@
</div> </div>
<% end %> <% end %>
<% test_nets = test_nets() %> <% test_nets = test_nets(other_networks()) %>
<%= unless Enum.empty?(test_nets) do %> <%= unless Enum.empty?(test_nets) do %>
<div class="col-md-<%= col_size %> footer-list"> <div class="col-md-<%= col_size %> footer-list">

@ -85,15 +85,15 @@
</a> </a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown"> <div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item header division">Mainnets</a> <a class="dropdown-item header division">Mainnets</a>
<%= for %{url: url, title: title} <- head_main_nets() do %> <%= for %{url: url, title: title} <- dropdown_head_main_nets() do %>
<a class="dropdown-item" href="<%= url%>"><%= title %></a> <a class="dropdown-item" href="<%= url%>"><%= title %></a>
<% end %> <% end %>
<a class="dropdown-item header division">Testnets</a> <a class="dropdown-item header division">Testnets</a>
<%= for %{url: url, title: title} <- test_nets() do %> <%= for %{url: url, title: title} <- test_nets(dropdown_nets()) do %>
<a class="dropdown-item" href="<%= url%>"><%= title %></a> <a class="dropdown-item" href="<%= url%>"><%= title %></a>
<% end %> <% end %>
<a class="dropdown-item header division">Other networks</a> <a class="dropdown-item header division">Other networks</a>
<%= for %{url: url, title: title} <- other_nets() do %> <%= for %{url: url, title: title} <- dropdown_other_nets() do %>
<a class="dropdown-item" href="<%= url%>"><%= title %></a> <a class="dropdown-item" href="<%= url%>"><%= title %></a>
<% end %> <% end %>
</div> </div>

@ -2,8 +2,68 @@ defmodule BlockScoutWeb.LayoutView do
use BlockScoutWeb, :view use BlockScoutWeb, :view
alias Plug.Conn alias Plug.Conn
alias Poison.Parser
@issue_url "https://github.com/poanetwork/blockscout/issues/new" @issue_url "https://github.com/poanetwork/blockscout/issues/new"
@default_other_networks [
%{
title: "POA Core",
url: "https://blockscout.com/poa/core"
},
%{
title: "POA Sokol",
url: "https://blockscout.com/poa/sokol",
test_net?: true
},
%{
title: "xDai Chain",
url: "https://blockscout.com/poa/dai"
},
%{
title: "Ethereum Mainnet",
url: "https://blockscout.com/eth/mainnet"
},
%{
title: "Kovan Testnet",
url: "https://blockscout.com/eth/kovan",
test_net?: true
},
%{
title: "Ropsten Testnet",
url: "https://blockscout.com/eth/ropsten",
test_net?: true
},
%{
title: "Goerli Testnet",
url: "https://blockscout.com/eth/goerli",
test_net?: true
},
%{
title: "Rinkeby Testnet",
url: "https://blockscout.com/eth/rinkeby",
test_net?: true
},
%{
title: "Ethereum Classic",
url: "https://blockscout.com/etc/mainnet",
other?: true
},
%{
title: "Aerum Mainnet",
url: "https://blockscout.com/aerum/mainnet",
other?: true
},
%{
title: "Callisto Mainnet",
url: "https://blockscout.com/callisto/mainnet",
other?: true
},
%{
title: "RSK Mainnet",
url: "https://blockscout.com/rsk/mainnet",
other?: true
}
]
alias BlockScoutWeb.SocialMedia alias BlockScoutWeb.SocialMedia
@ -95,29 +155,47 @@ defmodule BlockScoutWeb.LayoutView do
def ignore_version?(_), do: false def ignore_version?(_), do: false
def other_networks do def other_networks do
:block_scout_web get_other_networks =
|> Application.get_env(:other_networks, []) if Application.get_env(:block_scout_web, :other_networks) do
:block_scout_web
|> Application.get_env(:other_networks)
|> Parser.parse!(%{keys: :atoms!})
else
@default_other_networks
end
get_other_networks
|> Enum.reject(fn %{title: title} -> |> Enum.reject(fn %{title: title} ->
title == subnetwork_title() title == subnetwork_title()
end) end)
|> Enum.sort() |> Enum.sort()
end end
def main_nets do def main_nets(nets) do
Enum.reject(other_networks(), &Map.get(&1, :test_net?)) nets
|> Enum.reject(&Map.get(&1, :test_net?))
end end
def head_main_nets do def test_nets(nets) do
main_nets() nets
|> Enum.reject(&Map.get(&1, :other?)) |> Enum.filter(&Map.get(&1, :test_net?))
end end
def test_nets do def dropdown_nets do
Enum.filter(other_networks(), &Map.get(&1, :test_net?)) other_networks()
|> Enum.reject(&Map.get(&1, :hide_in_dropdown?))
end
def dropdown_head_main_nets do
dropdown_nets()
|> main_nets()
|> Enum.reject(&Map.get(&1, :other?))
end end
def other_nets do def dropdown_other_nets do
Enum.filter(other_networks(), &Map.get(&1, :other?)) dropdown_nets()
|> main_nets()
|> Enum.filter(&Map.get(&1, :other?))
end end
def other_explorers do def other_explorers do

@ -86,4 +86,123 @@ defmodule BlockScoutWeb.LayoutViewTest do
~s(<a href="https://github.com/poanetwork/blockscout/releases/tag/v1.3.4-beta" class="footer-link" target="_blank">1.3.4</a>)} ~s(<a href="https://github.com/poanetwork/blockscout/releases/tag/v1.3.4-beta" class="footer-link" target="_blank">1.3.4</a>)}
end end
end end
@supported_chains_pattern ~s([ { "title": "RSK Mainnet", "url": "https://blockscout.com/rsk/mainnet", "other?": true }, { "title": "POA Sokol", "url": "https://blockscout.com/poa/sokol", "test_net?": true }, { "title": "POA Core", "url": "https://blockscout.com/poa/core" }, { "title": "LUKSO L14 testnet", "url": "https://blockscout.com/lukso/l14", "test_net?": true, "hide_in_dropdown?": true } ])
describe "other_networks/0" do
test "get networks list based on env variables" do
Application.put_env(:block_scout_web, :other_networks, @supported_chains_pattern)
assert LayoutView.other_networks() == [
%{
title: "POA Core",
url: "https://blockscout.com/poa/core"
},
%{
title: "RSK Mainnet",
url: "https://blockscout.com/rsk/mainnet",
other?: true
},
%{
title: "POA Sokol",
url: "https://blockscout.com/poa/sokol",
test_net?: true
},
%{
title: "LUKSO L14 testnet",
url: "https://blockscout.com/lukso/l14",
test_net?: true,
hide_in_dropdown?: true
}
]
end
end
describe "main_nets/1" do
test "get all main networks list based on env variables" do
Application.put_env(:block_scout_web, :other_networks, @supported_chains_pattern)
assert LayoutView.main_nets(LayoutView.other_networks()) == [
%{
title: "POA Core",
url: "https://blockscout.com/poa/core"
},
%{
title: "RSK Mainnet",
url: "https://blockscout.com/rsk/mainnet",
other?: true
}
]
end
end
describe "test_nets/1" do
test "get all networks list based on env variables" do
Application.put_env(:block_scout_web, :other_networks, @supported_chains_pattern)
assert LayoutView.test_nets(LayoutView.other_networks()) == [
%{
title: "POA Sokol",
url: "https://blockscout.com/poa/sokol",
test_net?: true
},
%{
title: "LUKSO L14 testnet",
url: "https://blockscout.com/lukso/l14",
test_net?: true,
hide_in_dropdown?: true
}
]
end
end
describe "dropdown_nets/0" do
test "get all dropdown networks list based on env variables" do
Application.put_env(:block_scout_web, :other_networks, @supported_chains_pattern)
assert LayoutView.dropdown_nets() == [
%{
title: "POA Core",
url: "https://blockscout.com/poa/core"
},
%{
title: "RSK Mainnet",
url: "https://blockscout.com/rsk/mainnet",
other?: true
},
%{
title: "POA Sokol",
url: "https://blockscout.com/poa/sokol",
test_net?: true
}
]
end
end
describe "dropdown_head_main_nets/0" do
test "get dropdown all main networks except those of 'other' type list based on env variables" do
Application.put_env(:block_scout_web, :other_networks, @supported_chains_pattern)
assert LayoutView.dropdown_head_main_nets() == [
%{
title: "POA Core",
url: "https://blockscout.com/poa/core"
}
]
end
end
describe "dropdown_other_nets/0" do
test "get dropdown networks of 'other' type list based on env variables" do
Application.put_env(:block_scout_web, :other_networks, @supported_chains_pattern)
assert LayoutView.dropdown_other_nets() == [
%{
title: "RSK Mainnet",
url: "https://blockscout.com/rsk/mainnet",
other?: true
}
]
end
end
end end

Loading…
Cancel
Save