From dcbc541accba3d57ecb6b18e0a1a52578eeef853 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 3 Apr 2019 13:57:20 +0300 Subject: [PATCH] fix failing in rpc if balance is empty --- .../lib/block_scout_web/views/api/rpc/address_view.ex | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex index f614f3cb88..90da6bed23 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex +++ b/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