diff --git a/CHANGELOG.md b/CHANGELOG.md index fb0799bded..4847becf5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ ### Fixes - [#4812](https://github.com/blockscout/blockscout/pull/4812) - Check if exists custom_cap property of extended token object before access it - [#4810](https://github.com/blockscout/blockscout/pull/4810) - Show `nil` block.size as `N/A bytes` +- [#4801](https://github.com/blockscout/blockscout/pull/4801) - Added clauses and tests for get_total_staked_and_ordered/1 - [#4798](https://github.com/blockscout/blockscout/pull/4798) - Token instance View contract icon Safari fix - [#4796](https://github.com/blockscout/blockscout/pull/4796) - Fix nil.timestamp issue - [#4764](https://github.com/blockscout/blockscout/pull/4764) - Add cleaning of substrings of `require` messages from parsed constructor arguments diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 814b2ed977..b029d80a29 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -6319,7 +6319,9 @@ defmodule Explorer.Chain do ) end - def get_total_staked_and_ordered(address_hash) do + def get_total_staked_and_ordered(""), do: nil + + def get_total_staked_and_ordered(address_hash) when is_binary(address_hash) do StakingPoolsDelegator |> where([delegator], delegator.address_hash == ^address_hash and not delegator.is_deleted) |> select([delegator], %{ @@ -6329,6 +6331,8 @@ defmodule Explorer.Chain do |> Repo.one() end + def get_total_staked_and_ordered(_), do: nil + defp with_decompiled_code_flag(query, _hash, false), do: query defp with_decompiled_code_flag(query, hash, true) do diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 1f0178f279..08c9df0c67 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -5745,5 +5745,17 @@ defmodule Explorer.ChainTest do assert implementation_abi == @implementation_abi end + + test "get_total_staked_and_ordered should return just nil in case of invalid input and some response otherwise" do + assert Chain.get_total_staked_and_ordered(nil) == nil + assert Chain.get_total_staked_and_ordered(%{}) == nil + assert Chain.get_total_staked_and_ordered("") == nil + assert Chain.get_total_staked_and_ordered([]) == nil + + assert Chain.get_total_staked_and_ordered("0x3f7c51ef174ee8a62e3fcfb0947aa90c97bd2784") == %{ + stake_amount: Decimal.new(0), + ordered_withdraw: Decimal.new(0) + } + end end end