diff --git a/CHANGELOG.md b/CHANGELOG.md index 21543cfb98..b26ab858ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - [#2642](https://github.com/poanetwork/blockscout/pull/2642) - add ERC721 coin instance page ### Fixes +- [#2753](https://github.com/poanetwork/blockscout/pull/2753) - fix nft token instance images - [#2750](https://github.com/poanetwork/blockscout/pull/2750) - fixed contract buttons color for NFT token instance on each theme - [#2746](https://github.com/poanetwork/blockscout/pull/2746) - fixed wrong alignment in logs decoded view - [#2745](https://github.com/poanetwork/blockscout/pull/2745) - optimize addresses page diff --git a/apps/block_scout_web/lib/block_scout_web/csp_header.ex b/apps/block_scout_web/lib/block_scout_web/csp_header.ex index ace7894e86..75cfbf0cb6 100644 --- a/apps/block_scout_web/lib/block_scout_web/csp_header.ex +++ b/apps/block_scout_web/lib/block_scout_web/csp_header.ex @@ -15,7 +15,7 @@ defmodule BlockScoutWeb.CSPHeader do default-src 'self';\ script-src 'self' 'unsafe-inline' 'unsafe-eval';\ style-src 'self' 'unsafe-inline' 'unsafe-eval' https://fonts.googleapis.com;\ - img-src 'self' 'unsafe-inline' 'unsafe-eval' data: https:;\ + img-src 'self' * data:;\ font-src 'self' 'unsafe-inline' 'unsafe-eval' https://fonts.gstatic.com data:;\ " }) diff --git a/apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex b/apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex index 9df72f557a..f56d10761e 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex @@ -20,11 +20,22 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do def image_src(nil), do: "/images/controller.svg" def image_src(instance) do - cond do - instance.metadata && instance.metadata["image_url"] -> instance.metadata["image_url"] - instance.metadata && instance.metadata["image"] -> instance.metadata["image"] - true -> image_src(nil) - end + result = + cond do + instance.metadata && instance.metadata["image_url"] -> + instance.metadata["image_url"] + + instance.metadata && instance.metadata["image"] -> + instance.metadata["image"] + + instance.metadata && instance.metadata["properties"]["image"]["description"] -> + instance.metadata["properties"]["image"]["description"] + + true -> + image_src(nil) + end + + if String.trim(result) == "", do: image_src(nil), else: result end def total_supply_usd(token) do diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 3d391035c8..477e5803b4 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -925,7 +925,7 @@ msgstr "" #: lib/block_scout_web/templates/tokens/transfer/index.html.eex:15 #: 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/tokens/instance/overview_view.ex:60 +#: lib/block_scout_web/views/tokens/instance/overview_view.ex:71 #: lib/block_scout_web/views/tokens/overview_view.ex:35 #: lib/block_scout_web/views/transaction_view.ex:313 msgid "Token Transfers" @@ -1855,7 +1855,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18 #: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10 -#: lib/block_scout_web/views/tokens/instance/overview_view.ex:61 +#: lib/block_scout_web/views/tokens/instance/overview_view.ex:72 msgid "Metadata" msgstr "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index e3779d6254..477e5803b4 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -925,7 +925,7 @@ msgstr "" #: lib/block_scout_web/templates/tokens/transfer/index.html.eex:15 #: 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/tokens/instance/overview_view.ex:60 +#: lib/block_scout_web/views/tokens/instance/overview_view.ex:71 #: lib/block_scout_web/views/tokens/overview_view.ex:35 #: lib/block_scout_web/views/transaction_view.ex:313 msgid "Token Transfers" @@ -1820,7 +1820,7 @@ msgstr "" msgid "Copy Token ID" msgstr "" -#, elixir-format, fuzzy +#, elixir-format #: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:69 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:67 msgid "Decimals" @@ -1855,16 +1855,16 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18 #: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10 -#: lib/block_scout_web/views/tokens/instance/overview_view.ex:61 +#: lib/block_scout_web/views/tokens/instance/overview_view.ex:72 msgid "Metadata" msgstr "" -#, elixir-format, fuzzy +#, elixir-format #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:58 msgid "Module" msgstr "" -#, elixir-format, fuzzy +#, elixir-format #: lib/block_scout_web/templates/chain/show.html.eex:56 msgid "Total transactions" msgstr "" diff --git a/apps/block_scout_web/test/block_scout_web/views/tokens/instance/overview_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/tokens/instance/overview_view_test.exs new file mode 100644 index 0000000000..cf310bf266 --- /dev/null +++ b/apps/block_scout_web/test/block_scout_web/views/tokens/instance/overview_view_test.exs @@ -0,0 +1,41 @@ +defmodule BlockScoutWeb.Tokens.Instance.OverviewViewTest do + use BlockScoutWeb.ConnCase, async: true + + alias BlockScoutWeb.Tokens.Instance.OverviewView + + describe "image_src/1" do + test "fetches image from ['properties']['image']['description'] path" do + json = """ + { + "type": "object", + "title": "TestCore Metadata", + "properties": { + "name": { + "type": "string", + "description": "Identifies the asset to which this NFT represents" + }, + "image": { + "type": "string", + "description": "https://img.paoditu.com/images/cut_trace_images/6b/5f/5b754f6b5f3b5_500_500.jpg" + }, + "description": { + "type": "string", + "description": "Describes the asset to which this NFT represents" + } + } + } + """ + + data = Jason.decode!(json) + + assert OverviewView.image_src(%{metadata: data}) == + "https://img.paoditu.com/images/cut_trace_images/6b/5f/5b754f6b5f3b5_500_500.jpg" + end + + test "handles empty images" do + instance = %{metadata: %{"image" => ""}} + + assert OverviewView.image_src(instance) != "" + end + end +end