Fix gettext bug on Contract's Code page

pull/803/head
Lucas Narciso 6 years ago
parent 6fa24d9fa2
commit 7354bec042
No known key found for this signature in database
GPG Key ID: 9E89F4CF3FBAB001
  1. 2
      apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex
  2. 12
      apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex
  3. 17
      apps/block_scout_web/test/block_scout_web/views/address_contract_view_test.exs

@ -24,7 +24,7 @@
</dl>
<dl class="row">
<dt class="col-sm-4 col-md-2 text-muted"><%= gettext "Optimization enabled" %></dt>
<dd class="col-sm-8 col-md-10"><%= gettext("%{}", @address.smart_contract.optimization) %></dd>
<dd class="col-sm-8 col-md-10"><%= format_optimization_text(@address.smart_contract.optimization) %></dd>
</dl>
<dl class="row">
<dt class="col-sm-4 col-md-2 text-muted"><%= gettext "Compiler version" %></dt>

@ -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

@ -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
Loading…
Cancel
Save