fix failing in rpc if balance is empty

pull/1697/head
Ayrat Badykov 6 years ago
parent 313df94cec
commit dcbc541acc
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 10
      apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex

@ -9,7 +9,7 @@ defmodule BlockScoutWeb.API.RPC.AddressView do
end end
def render("balance.json", %{addresses: [address]}) do def render("balance.json", %{addresses: [address]}) do
RPCView.render("show.json", data: "#{address.fetched_coin_balance.value}") RPCView.render("show.json", data: "#{balance(address)}")
end end
def render("balance.json", assigns) do def render("balance.json", assigns) do
@ -21,7 +21,7 @@ defmodule BlockScoutWeb.API.RPC.AddressView do
Enum.map(addresses, fn address -> Enum.map(addresses, fn address ->
%{ %{
"account" => "#{address.hash}", "account" => "#{address.hash}",
"balance" => "#{address.fetched_coin_balance.value}" "balance" => "#{balance(address)}"
} }
end) end)
@ -157,4 +157,10 @@ defmodule BlockScoutWeb.API.RPC.AddressView do
"symbol" => token.symbol "symbol" => token.symbol
} }
end end
defp balance(address) do
balance = address.fetched_coin_balance && address.fetched_coin_balance.value
balance || 0
end
end end

Loading…
Cancel
Save