From a9567fdf4ff0db7154762b4441c2c8680a800220 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 4 Oct 2019 15:03:00 +0300 Subject: [PATCH 1/7] allow images from ['properties']['image']['description'] in nft token --- .../views/tokens/instance/overview_view.ex | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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..9bbca70b5e 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 @@ -21,9 +21,17 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do 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) + 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 end From 49078b845276741c53f08558af4b2cca560e2d75 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 4 Oct 2019 15:05:41 +0300 Subject: [PATCH 2/7] allow images from all sources --- apps/block_scout_web/lib/block_scout_web/csp_header.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..3442945455 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 https: data:;\ font-src 'self' 'unsafe-inline' 'unsafe-eval' https://fonts.gstatic.com data:;\ " }) From 30518f0435005aaea8a9b221474f01bbd1b03655 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 4 Oct 2019 15:07:51 +0300 Subject: [PATCH 3/7] add CHANGELOG entry --- CHANGELOG.md | 1 + .../tokens/instance/overview_view_test.exs | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 apps/block_scout_web/test/block_scout_web/views/tokens/instance/overview_view_test.exs 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/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..dc3647baa9 --- /dev/null +++ b/apps/block_scout_web/test/block_scout_web/views/tokens/instance/overview_view_test.exs @@ -0,0 +1,35 @@ +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 + end +end From f5bf757537ec150b5bc5150340f9e8074ba504de Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 4 Oct 2019 15:12:57 +0300 Subject: [PATCH 4/7] handle empty images --- .../views/tokens/instance/overview_view.ex | 23 +++++++++++-------- .../tokens/instance/overview_view_test.exs | 6 +++++ 2 files changed, 19 insertions(+), 10 deletions(-) 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 9bbca70b5e..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,19 +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"] + 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["image"] -> + instance.metadata["image"] - instance.metadata && instance.metadata["properties"]["image"]["description"] -> - instance.metadata["properties"]["image"]["description"] + instance.metadata && instance.metadata["properties"]["image"]["description"] -> + instance.metadata["properties"]["image"]["description"] - true -> - image_src(nil) - end + 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/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 index dc3647baa9..cf310bf266 100644 --- 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 @@ -31,5 +31,11 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewViewTest do 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 From 4596af5be9ee6460d575da5f6d99cb4e90a83eaa Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 4 Oct 2019 15:18:35 +0300 Subject: [PATCH 5/7] fix gettext --- apps/block_scout_web/priv/gettext/default.pot | 4 ++-- .../priv/gettext/en/LC_MESSAGES/default.po | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) 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 "" From 6149ddf99b27dd890c01adabeb06ec3121f61975 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 4 Oct 2019 16:18:16 +0300 Subject: [PATCH 6/7] allow all sources --- apps/block_scout_web/lib/block_scout_web/csp_header.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3442945455..1b61c78978 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 https: data:;\ + img-src * data:;\ font-src 'self' 'unsafe-inline' 'unsafe-eval' https://fonts.gstatic.com data:;\ " }) From abd4991659a74729628ed2df869bbe20d0e1d3ae Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 4 Oct 2019 16:38:13 +0300 Subject: [PATCH 7/7] add self to image csp --- apps/block_scout_web/lib/block_scout_web/csp_header.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1b61c78978..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 * data:;\ + img-src 'self' * data:;\ font-src 'self' 'unsafe-inline' 'unsafe-eval' https://fonts.gstatic.com data:;\ " })