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. 3
      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,6 +20,7 @@ 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
result =
cond do cond do
instance.metadata && instance.metadata["image_url"] -> instance.metadata && instance.metadata["image_url"] ->
instance.metadata["image_url"] instance.metadata["image_url"]
@ -33,6 +34,8 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do
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