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(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

@ -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

Loading…
Cancel
Save