diff --git a/CHANGELOG.md b/CHANGELOG.md index a0f3ae537b..4ff76585d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - [#3540](https://github.com/poanetwork/blockscout/pull/3540) - Apply DarkForest custom theme to NFT instances ### Fixes +- [#3551](https://github.com/poanetwork/blockscout/pull/3551) - Fix contract's method's output of tuple type ### Chore - [#3540](https://github.com/poanetwork/blockscout/pull/3540), [#3545](https://github.com/poanetwork/blockscout/pull/3545) - Support different versions of DarkForest (0.4 - 0.5) diff --git a/apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex b/apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex index 69a03441b8..a993801240 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex @@ -48,12 +48,16 @@ defmodule BlockScoutWeb.SmartContractView do end def values(values, type) when is_list(values) and type == "tuple[]" do - array_from_tuple = tupple_to_array(values) + array_from_tuple = tuple_array_to_array(values) array_from_tuple |> Enum.join(", ") end + def values(value, _type) when is_tuple(value) do + tuple_to_array(value) + end + def values(value, type) when type in ["address", "address payable"] do {:ok, address} = Explorer.Chain.Hash.Address.cast(value) to_string(address) @@ -62,16 +66,20 @@ defmodule BlockScoutWeb.SmartContractView do def values(values, _) when is_list(values), do: Enum.join(values, ",") def values(value, _), do: value - defp tupple_to_array(values) do + defp tuple_array_to_array(values) do values |> Enum.map(fn value -> - value - |> Tuple.to_list() - |> Enum.map(&binary_to_utf_string(&1)) - |> Enum.join(",") + tuple_to_array(value) end) end + defp tuple_to_array(value) do + value + |> Tuple.to_list() + |> Enum.map(&binary_to_utf_string(&1)) + |> Enum.join(",") + end + defp binary_to_utf_string(item) do if is_binary(item), do: "0x" <> Base.encode16(item, case: :lower), else: item end