From 768afccee85f08a9677b377588b4ad448c03c171 Mon Sep 17 00:00:00 2001 From: nikitosing Date: Fri, 23 Jul 2021 17:56:39 +0700 Subject: [PATCH] Fix zero total supply bug --- CHANGELOG.md | 1 + .../lib/block_scout_web/views/tokens/holder_view.ex | 2 ++ .../test/block_scout_web/views/tokens/holder_view_test.exs | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36cdb48698..3eddbdf955 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#4353](https://github.com/blockscout/blockscout/pull/4353) - Added live-reload on the token holders page ### Fixes +- [#4429](https://github.com/blockscout/blockscout/pull/4429) - Fix 500 response on `/tokens/{addressHash}/token-holders?type=JSON` when total supply is zero - [#4419](https://github.com/blockscout/blockscout/pull/4419) - Order contracts in the search by inserted_at in descending order - [#4418](https://github.com/blockscout/blockscout/pull/4418) - Fix empty search results for the full-word search criteria - [#4406](https://github.com/blockscout/blockscout/pull/4406) - Fix internal server error on the validator's txs page diff --git a/apps/block_scout_web/lib/block_scout_web/views/tokens/holder_view.ex b/apps/block_scout_web/lib/block_scout_web/views/tokens/holder_view.ex index 03d7e74cd8..80c74d47e2 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/tokens/holder_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/tokens/holder_view.ex @@ -33,6 +33,8 @@ defmodule BlockScoutWeb.Tokens.HolderView do "20.0000%" """ + def total_supply_percentage(_, 0), do: "N/A%" + def total_supply_percentage(value, total_supply) do result = value diff --git a/apps/block_scout_web/test/block_scout_web/views/tokens/holder_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/tokens/holder_view_test.exs index 9541a11eab..f25d26d980 100644 --- a/apps/block_scout_web/test/block_scout_web/views/tokens/holder_view_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/tokens/holder_view_test.exs @@ -40,6 +40,13 @@ defmodule BlockScoutWeb.Tokens.HolderViewTest do assert HolderView.total_supply_percentage(value, total_supply) == "0.0005%" end + + test "zero total_supply" do + %Token{total_supply: total_supply} = build(:token, total_supply: 0) + %TokenBalance{value: value} = build(:token_balance, value: 0) + + assert HolderView.total_supply_percentage(value, total_supply) == "N/A%" + end end describe "format_token_balance_value/1" do