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

Loading…
Cancel
Save