handle empty images

pull/2753/head
Ayrat Badykov 5 years ago
parent 30518f0435
commit f5bf757537
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 23
      apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex
  2. 6
      apps/block_scout_web/test/block_scout_web/views/tokens/instance/overview_view_test.exs

@ -20,19 +20,22 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do
def image_src(nil), do: "/images/controller.svg" def image_src(nil), do: "/images/controller.svg"
def image_src(instance) do def image_src(instance) do
cond do result =
instance.metadata && instance.metadata["image_url"] -> cond do
instance.metadata["image_url"] instance.metadata && instance.metadata["image_url"] ->
instance.metadata["image_url"]
instance.metadata && instance.metadata["image"] -> instance.metadata && instance.metadata["image"] ->
instance.metadata["image"] instance.metadata["image"]
instance.metadata && instance.metadata["properties"]["image"]["description"] -> instance.metadata && instance.metadata["properties"]["image"]["description"] ->
instance.metadata["properties"]["image"]["description"] instance.metadata["properties"]["image"]["description"]
true -> true ->
image_src(nil) image_src(nil)
end end
if String.trim(result) == "", do: image_src(nil), else: result
end end
def total_supply_usd(token) do def total_supply_usd(token) do

@ -31,5 +31,11 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewViewTest do
assert OverviewView.image_src(%{metadata: data}) == assert OverviewView.image_src(%{metadata: data}) ==
"https://img.paoditu.com/images/cut_trace_images/6b/5f/5b754f6b5f3b5_500_500.jpg" "https://img.paoditu.com/images/cut_trace_images/6b/5f/5b754f6b5f3b5_500_500.jpg"
end end
test "handles empty images" do
instance = %{metadata: %{"image" => ""}}
assert OverviewView.image_src(instance) != ""
end
end end
end end

Loading…
Cancel
Save