From 7354bec042a14f66f5b644149aa94ae0e6fa73b8 Mon Sep 17 00:00:00 2001 From: Lucas Narciso Date: Mon, 1 Oct 2018 11:50:44 -0300 Subject: [PATCH] Fix gettext bug on Contract's Code page --- .../templates/address_contract/index.html.eex | 2 +- .../views/address_contract_view.ex | 12 ++++++++++++ .../views/address_contract_view_test.exs | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 apps/block_scout_web/test/block_scout_web/views/address_contract_view_test.exs diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex index 8bddc2bfba..ed8707a1a2 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex @@ -24,7 +24,7 @@
<%= gettext "Optimization enabled" %>
-
<%= gettext("%{}", @address.smart_contract.optimization) %>
+
<%= format_optimization_text(@address.smart_contract.optimization) %>
<%= gettext "Compiler version" %>
diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex index 3f453e0478..3c51c70342 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex @@ -2,4 +2,16 @@ defmodule BlockScoutWeb.AddressContractView do use BlockScoutWeb, :view def format_smart_contract_abi(abi), do: Poison.encode!(abi, pretty: false) + + @doc """ + Returns the correct format for the optimization text. + + iex> BlockScoutWeb.AddressContractView.format_optimization_text(true) + "true" + + iex> BlockScoutWeb.AddressContractView.format_optimization_text(false) + "false" + """ + def format_optimization_text(true), do: gettext("true") + def format_optimization_text(false), do: gettext("false") end diff --git a/apps/block_scout_web/test/block_scout_web/views/address_contract_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/address_contract_view_test.exs new file mode 100644 index 0000000000..e483bfc7ea --- /dev/null +++ b/apps/block_scout_web/test/block_scout_web/views/address_contract_view_test.exs @@ -0,0 +1,17 @@ +defmodule BlockScoutWeb.AddressContractViewTest do + use BlockScoutWeb.ConnCase, async: true + + alias BlockScoutWeb.AddressContractView + + doctest BlockScoutWeb.AddressContractView + + describe "format_optimization_text/1" do + test "returns \"true\" for the boolean true" do + assert AddressContractView.format_optimization_text(true) == "true" + end + + test "returns \"false\" for the boolean false" do + assert AddressContractView.format_optimization_text(false) == "false" + end + end +end