From 76f9b3b541ea1f1ddac99d76c6d9fcf66ae20a74 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Mon, 28 Dec 2020 16:17:35 +0300 Subject: [PATCH] DarkForest: apply theme to token instance, differentiate versions of DF --- .dialyzer-ignore | 2 +- CHANGELOG.md | 2 + .../custom_contracts/_dark-forest-theme.scss | 15 ++- apps/block_scout_web/config/config.exs | 1 + .../lib/block_scout_web/controller.ex | 2 +- .../decompiled_smart_contract_controller.ex | 2 +- .../v1/verified_smart_contract_controller.ex | 2 +- .../controllers/page_not_found_controller.ex | 2 +- .../address/_custom_view_df_title.html.eex | 19 +++ .../templates/address/_tabs.html.eex | 4 +- .../templates/address/overview.html.eex | 27 +--- .../templates/address_contract/index.html.eex | 21 +-- .../templates/layout/app.html.eex | 12 +- .../smart_contract/_functions.html.eex | 2 +- apps/block_scout_web/priv/gettext/default.pot | 125 +++++++++--------- .../priv/gettext/en/LC_MESSAGES/default.po | 125 +++++++++--------- 16 files changed, 191 insertions(+), 172 deletions(-) create mode 100644 apps/block_scout_web/lib/block_scout_web/templates/address/_custom_view_df_title.html.eex diff --git a/.dialyzer-ignore b/.dialyzer-ignore index ccb1c2e71b..1324d90572 100644 --- a/.dialyzer-ignore +++ b/.dialyzer-ignore @@ -23,6 +23,6 @@ lib/indexer/fetcher/token_total_supply_on_demand.ex:16 lib/explorer/exchange_rates/source.ex:104 lib/explorer/exchange_rates/source.ex:107 lib/explorer/smart_contract/verifier.ex:89 -lib/block_scout_web/templates/address_contract/index.html.eex:117 +lib/block_scout_web/templates/address_contract/index.html.eex:118 lib/explorer/staking/stake_snapshotting.ex:14: Function do_snapshotting/6 has no local return lib/explorer/staking/stake_snapshotting.ex:183 diff --git a/CHANGELOG.md b/CHANGELOG.md index f46f9aae3c..9f5de8eb50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,12 @@ ## Current ### Features +- [#3540](https://github.com/poanetwork/blockscout/pull/3540) - Apply DarkForest custom theme to NFT instances ### Fixes ### Chore +- [#3540](https://github.com/poanetwork/blockscout/pull/3540) - Support different versions of DarkForest (0.4 - 0.5) ## 3.5.0-beta diff --git a/apps/block_scout_web/assets/css/theme/custom_contracts/_dark-forest-theme.scss b/apps/block_scout_web/assets/css/theme/custom_contracts/_dark-forest-theme.scss index df7909057f..3294353c51 100644 --- a/apps/block_scout_web/assets/css/theme/custom_contracts/_dark-forest-theme.scss +++ b/apps/block_scout_web/assets/css/theme/custom_contracts/_dark-forest-theme.scss @@ -269,7 +269,7 @@ $dark-primary-alternate: $dark-primary; content: url(/images/custom-themes/dark-forest/qr.svg); } - .btn-copy-icon, .btn-qr-icon, .btn-address-card-icon .btn-contract-icon { + .btn-copy-icon, .btn-qr-icon, .btn-address-card-icon { border-radius: 0; border: none; border-color: $dark-primary; @@ -277,6 +277,19 @@ $dark-primary-alternate: $dark-primary; background-color: rgba(117, 249, 77, 0.4); } } + + .btn-contract-icon { + border-radius: 0; + border-color: $dark-primary; + &:hover { + background-color: rgba(117, 249, 77, 0.4); + } + svg { + path { + fill: $dark-primary; + } + } + } // pagination .pagination-container .pagination .page-link { diff --git a/apps/block_scout_web/config/config.exs b/apps/block_scout_web/config/config.exs index de69c50848..6ab54f6e8b 100644 --- a/apps/block_scout_web/config/config.exs +++ b/apps/block_scout_web/config/config.exs @@ -42,6 +42,7 @@ config :block_scout_web, restricted_list: System.get_env("RESTRICTED_LIST", nil), restricted_list_key: System.get_env("RESTRICTED_LIST_KEY", nil), dark_forest_addresses: System.get_env("CUSTOM_CONTRACT_ADDRESSES_DARK_FOREST"), + dark_forest_addresses_v_0_5: System.get_env("CUSTOM_CONTRACT_ADDRESSES_DARK_FOREST_V_0_5"), circles_addresses: System.get_env("CUSTOM_CONTRACT_ADDRESSES_CIRCLES") config :block_scout_web, BlockScoutWeb.Counters.BlocksIndexedCounter, enabled: true diff --git a/apps/block_scout_web/lib/block_scout_web/controller.ex b/apps/block_scout_web/lib/block_scout_web/controller.ex index 38f28be0c6..5cff2fa955 100644 --- a/apps/block_scout_web/lib/block_scout_web/controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controller.ex @@ -13,7 +13,7 @@ defmodule BlockScoutWeb.Controller do conn |> put_status(:not_found) |> put_view(BlockScoutWeb.PageNotFoundView) - |> render(:index) + |> render(:index, token: nil) |> halt() end diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller.ex index 7b783b9761..6b03afe82a 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller.ex @@ -12,7 +12,7 @@ defmodule BlockScoutWeb.API.V1.DecompiledSmartContractController do {:contract, Chain.check_decompiled_contract_exists(params["address_hash"], params["decompiler_version"])} do case Chain.create_decompiled_smart_contract(params) do {:ok, decompiled_smart_contract} -> - send_resp(conn, :created, Jason.encode!(decompiled_smart_contract)) + send_resp(conn, :created, encode(decompiled_smart_contract)) {:error, changeset} -> errors = diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/verified_smart_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/verified_smart_contract_controller.ex index 8b3d3d71eb..af74c0c4df 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/verified_smart_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/verified_smart_contract_controller.ex @@ -13,7 +13,7 @@ defmodule BlockScoutWeb.API.V1.VerifiedSmartContractController do case Publisher.publish(hash, params, external_libraries) do {:ok, _} -> - send_resp(conn, :created, Jason.encode!(%{status: :success})) + send_resp(conn, :created, encode(%{status: :success})) {:error, changeset} -> errors = diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/page_not_found_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/page_not_found_controller.ex index 7ea8fab254..fabcb3b733 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/page_not_found_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/page_not_found_controller.ex @@ -4,6 +4,6 @@ defmodule BlockScoutWeb.PageNotFoundController do def index(conn, _params) do conn |> put_status(:not_found) - |> render("index.html") + |> render("index.html", token: nil) end end diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_custom_view_df_title.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_custom_view_df_title.html.eex new file mode 100644 index 0000000000..fd99f0af95 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_custom_view_df_title.html.eex @@ -0,0 +1,19 @@ +
+ +
+ + <%= @title %> + + + + + + +
+
\ No newline at end of file diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_tabs.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_tabs.html.eex index 9150fa9642..2d8b5d3790 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/_tabs.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_tabs.html.eex @@ -1,4 +1,6 @@ -<% dark_forest_addresses_list = CustomContractsHelpers.get_custom_addresses_list(:dark_forest_addresses) %> +<% dark_forest_addresses_list_0_4 = CustomContractsHelpers.get_custom_addresses_list(:dark_forest_addresses) %> +<% dark_forest_addresses_list_0_5 = CustomContractsHelpers.get_custom_addresses_list(:dark_forest_addresses_v_0_5) %> +<% dark_forest_addresses_list = dark_forest_addresses_list_0_4 ++ dark_forest_addresses_list_0_5 %> <% current_address = "0x" <> Base.encode16(@address.hash.bytes, case: :lower) %>
<%= link( diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex index d60df0b6dc..a6518b0d91 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex @@ -1,5 +1,6 @@
- <% dark_forest_addresses_list = CustomContractsHelpers.get_custom_addresses_list(:dark_forest_addresses) %> + <% dark_forest_addresses_list_0_4 = CustomContractsHelpers.get_custom_addresses_list(:dark_forest_addresses) %> + <% dark_forest_addresses_list_0_5 = CustomContractsHelpers.get_custom_addresses_list(:dark_forest_addresses_v_0_5) %> <% circles_addresses_list = CustomContractsHelpers.get_custom_addresses_list(:circles_addresses) %> <% current_address = "0x" <> Base.encode16(@address.hash.bytes, case: :lower) %> <% created_from_address_hash = if from_address_hash(@address), do: "0x" <> Base.encode16(from_address_hash(@address).bytes, case: :lower), else: nil %> @@ -9,26 +10,10 @@
<%= cond do %> - <% Enum.member?(dark_forest_addresses_list, current_address) -> %> -
- -
- - <%= gettext "zkSnark space warfare (v0.4)" %> - - - - - - -
-
+ <% Enum.member?(dark_forest_addresses_list_0_4, current_address) -> %> + <%= render BlockScoutWeb.AddressView, "_custom_view_df_title.html", title: "zkSnark space warfare (v0.4)" %> + <% Enum.member?(dark_forest_addresses_list_0_5, current_address) -> %> + <%= render BlockScoutWeb.AddressView, "_custom_view_df_title.html", title: "zkSnark space warfare (v0.5)" %> <% Enum.member?(circles_addresses_list, current_address) -> %>
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex index df111a0c0f..40e554cd33 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex @@ -1,5 +1,6 @@ <% contract_creation_code = contract_creation_code(@address) %> <% metadata_for_verification = Chain.address_verified_twin_contract(@address.hash) %> +<% smart_contract_verified = BlockScoutWeb.AddressView.smart_contract_verified?(@address) %>
<%= render BlockScoutWeb.AddressView, "overview.html", assigns %> @@ -7,17 +8,17 @@
<%= render BlockScoutWeb.AddressView, "_tabs.html", assigns %>
- <%= unless BlockScoutWeb.AddressView.smart_contract_verified?(@address) do %> + <%= unless smart_contract_verified do %> <%= if metadata_for_verification do %>
- <%= gettext("Contract is not verified. However, we found a verified contract with the same bytecode in our DB") %> <%= link( + <%= gettext("Contract is not verified. However, we found a verified contract with the same bytecode in Blockscout DB") %> <%= link( metadata_for_verification.address_hash, to: address_contract_path(@conn, :index, metadata_for_verification.address_hash)) %>.
<%= gettext("All metadata displayed below is from that contract. In order to verify current contract, click") %> <%= gettext("Verify & Publish") %> <%= gettext("button") %>
<% end %> <% end %> - <%= if BlockScoutWeb.AddressView.smart_contract_verified?(@address) || (!BlockScoutWeb.AddressView.smart_contract_verified?(@address) && metadata_for_verification) do %> - <% target_contract = if BlockScoutWeb.AddressView.smart_contract_verified?(@address), do: @address.smart_contract, else: metadata_for_verification %> + <%= if smart_contract_verified || (!smart_contract_verified && metadata_for_verification) do %> + <% target_contract = if smart_contract_verified, do: @address.smart_contract, else: metadata_for_verification %>
<%= gettext "Contract name:" %>
@@ -37,14 +38,14 @@
<%= target_contract.optimization_runs %>
<% end %>
- <%= if BlockScoutWeb.AddressView.smart_contract_verified?(@address) && target_contract.evm_version do %> + <%= if smart_contract_verified && target_contract.evm_version do %>
<%= gettext "EVM Version" %>
<%= target_contract.evm_version %>
<% end %>
- <%= if BlockScoutWeb.AddressView.smart_contract_verified?(@address) && target_contract.constructor_arguments do %> + <%= if smart_contract_verified && target_contract.constructor_arguments do %>

<%= gettext "Constructor Arguments" %>

@@ -98,7 +99,7 @@
<%= transaction_init %>
<% {:ok, contract_code} -> %> - <%= if BlockScoutWeb.AddressView.smart_contract_verified?(@address) do %> + <%= if smart_contract_verified do %>

<%= gettext "Contract Byte Code" %>

<% else %> - <%= if !BlockScoutWeb.AddressView.smart_contract_verified?(@address) do %> + <%= if !smart_contract_verified do %> <%= link( gettext("Verify & Publish"), to: address_verify_contract_path(@conn, :new, @address.hash), @@ -137,8 +138,8 @@ <% end %>
- <%= if BlockScoutWeb.AddressView.smart_contract_verified?(@address) || (!BlockScoutWeb.AddressView.smart_contract_verified?(@address) && metadata_for_verification) do %> - <% target_contract = if BlockScoutWeb.AddressView.smart_contract_verified?(@address), do: @address.smart_contract, else: metadata_for_verification %> + <%= if smart_contract_verified || (!smart_contract_verified && metadata_for_verification) do %> + <% target_contract = if smart_contract_verified, do: @address.smart_contract, else: metadata_for_verification %> <%= if target_contract.external_libraries && target_contract.external_libraries != [] do %>
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/layout/app.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/layout/app.html.eex index d7c643a013..c79055db01 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/layout/app.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/layout/app.html.eex @@ -37,7 +37,10 @@ - <% raw_dark_forest_addresses = CustomContractsHelpers.get_raw_custom_addresses_list(:dark_forest_addresses) %> + <% raw_dark_forest_addresses_0_4 = CustomContractsHelpers.get_raw_custom_addresses_list(:dark_forest_addresses) || "" %> + <% raw_dark_forest_addresses_0_5 = CustomContractsHelpers.get_raw_custom_addresses_list(:dark_forest_addresses_v_0_5) || "" %> + <% raw_dark_forest_addresses = raw_dark_forest_addresses_0_4 <> "," <> raw_dark_forest_addresses_0_5 %> + <% raw_circles_addresses = CustomContractsHelpers.get_raw_custom_addresses_list(:circles_addresses) %> <%= cond do %> <% ( @@ -116,9 +119,12 @@ <% ( @view_module == Elixir.BlockScoutWeb.Tokens.TransferView || @view_module == Elixir.BlockScoutWeb.Tokens.ReadContractView || - @view_module == Elixir.BlockScoutWeb.Tokens.HolderView + @view_module == Elixir.BlockScoutWeb.Tokens.HolderView || + @view_module == Elixir.BlockScoutWeb.Tokens.Instance.TransferView || + @view_module == Elixir.BlockScoutWeb.Tokens.Instance.MetadataView || + @view_module == Elixir.BlockScoutWeb.PageNotFoundView ) -> %> - <% {:ok, created_from_address} = if @token.contract_address_hash, do: Chain.hash_to_address(@token.contract_address_hash), else: {:ok, nil} %> + <% {:ok, created_from_address} = if @token && @token.contract_address_hash, do: Chain.hash_to_address(@token.contract_address_hash), else: {:ok, nil} %> <% created_from_address_hash = if from_address_hash(created_from_address), do: "0x" <> Base.encode16(from_address_hash(created_from_address).bytes, case: :lower), else: nil %>