Fix token instance QR code data when api_path is different from path

pull/3017/head
Victor Baranov 5 years ago
parent c7c379b4cf
commit 6ba9fa5733
  1. 2
      CHANGELOG.md
  2. 26
      apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex
  3. 25
      apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex
  4. 4
      apps/block_scout_web/priv/gettext/default.pot
  5. 4
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  6. 33
      apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs
  7. 15
      apps/block_scout_web/test/block_scout_web/controllers/address_read_contract_controller_test.exs
  8. 14
      apps/block_scout_web/test/block_scout_web/controllers/address_token_controller_test.exs
  9. 14
      apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs
  10. 14
      apps/block_scout_web/test/block_scout_web/schema/subscription/token_transfers_test.exs
  11. 34
      apps/block_scout_web/test/block_scout_web/views/api_docs_view_test.exs

@ -5,7 +5,7 @@
- [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash
### Fixes
- [#3016](https://github.com/poanetwork/blockscout/pull/3016) - Fix token instance QR code data
- [#3016](https://github.com/poanetwork/blockscout/pull/3016), [#3017](https://github.com/poanetwork/blockscout/pull/3017) - Fix token instance QR code data
- [#3012](https://github.com/poanetwork/blockscout/pull/3012) - Speedup token transfers list query
- [#3011](https://github.com/poanetwork/blockscout/pull/3011) - Revert realtime fetcher small skips feature
- [#3009](https://github.com/poanetwork/blockscout/pull/3009) - Fix broken export to CSV

@ -34,7 +34,21 @@ defmodule BlockScoutWeb.APIDocsView do
end)
end
def blockscout_url(is_api, set_path) do
def blockscout_url(set_path) when set_path == false do
url_params = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url]
host = url_params[:host]
scheme = Keyword.get(url_params, :scheme, "http")
if host != "localhost" do
"#{scheme}://#{host}"
else
port = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:http][:port]
"#{scheme}://#{host}:#{to_string(port)}"
end
end
def blockscout_url(set_path, is_api) when set_path == true do
url_params = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url]
host = url_params[:host]
@ -48,7 +62,7 @@ defmodule BlockScoutWeb.APIDocsView do
scheme = Keyword.get(url_params, :scheme, "http")
if host != "localhost" do
if set_path, do: "#{scheme}://#{host}#{path}", else: "#{scheme}://#{host}"
"#{scheme}://#{host}#{path}"
else
port = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:http][:port]
"#{scheme}://#{host}:#{to_string(port)}"
@ -59,8 +73,8 @@ defmodule BlockScoutWeb.APIDocsView do
is_api = true
set_path = true
is_api
|> blockscout_url(set_path)
set_path
|> blockscout_url(is_api)
|> Path.join("api")
end
@ -68,8 +82,8 @@ defmodule BlockScoutWeb.APIDocsView do
is_api = true
set_path = true
is_api
|> blockscout_url(set_path)
set_path
|> blockscout_url(is_api)
|> Path.join("api/eth_rpc")
end
end

@ -4,7 +4,7 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do
alias BlockScoutWeb.CurrencyHelpers
alias Explorer.Chain.{Address, SmartContract, Token}
import BlockScoutWeb.APIDocsView, only: [blockscout_url: 2]
import BlockScoutWeb.APIDocsView, only: [blockscout_url: 1, blockscout_url: 2]
@tabs ["token_transfers", "metadata"]
@ -55,9 +55,26 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do
def qr_code(conn, token_id, hash) do
token_instance_path = token_instance_path(conn, :show, to_string(hash), to_string(token_id))
is_api = false
set_path = false
url = Path.join(blockscout_url(is_api, set_path), token_instance_path)
url_params = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url]
api_path = url_params[:api_path]
path = url_params[:path]
url_prefix =
if String.length(path) > 0 && path != "/" do
set_path = false
blockscout_url(set_path)
else
if String.length(api_path) > 0 && api_path != "/" do
is_api = true
set_path = true
blockscout_url(set_path, is_api)
else
set_path = false
blockscout_url(set_path)
end
end
url = Path.join(url_prefix, token_instance_path)
url
|> QRCode.to_png()

@ -898,7 +898,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7
#: lib/block_scout_web/views/address_view.ex:308
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:73
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:90
#: lib/block_scout_web/views/tokens/overview_view.ex:35
#: lib/block_scout_web/views/transaction_view.ex:314
msgid "Token Transfers"
@ -1774,7 +1774,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18
#: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:74
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:91
msgid "Metadata"
msgstr ""

@ -898,7 +898,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7
#: lib/block_scout_web/views/address_view.ex:308
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:73
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:90
#: lib/block_scout_web/views/tokens/overview_view.ex:35
#: lib/block_scout_web/views/transaction_view.ex:314
msgid "Token Transfers"
@ -1774,7 +1774,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18
#: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:74
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:91
msgid "Metadata"
msgstr ""

@ -3,10 +3,26 @@ defmodule BlockScoutWeb.AddressControllerTest do
# ETS tables are shared in `Explorer.Counters.*`
async: false
import Mox
alias Explorer.Chain.Address
alias Explorer.Counters.AddressesCounter
describe "GET index/2" do
setup :set_mox_global
setup do
# Use TestSource mock for this test set
configuration = Application.get_env(:block_scout_web, :show_percentage)
Application.put_env(:block_scout_web, :show_percentage, false)
:ok
on_exit(fn ->
Application.put_env(:block_scout_web, :show_percentage, configuration)
end)
end
test "returns top addresses", %{conn: conn} do
address_hashes =
4..1
@ -38,8 +54,21 @@ defmodule BlockScoutWeb.AddressControllerTest do
end
describe "GET show/3" do
setup :set_mox_global
setup do
configuration = Application.get_env(:explorer, :checksum_function)
Application.put_env(:explorer, :checksum_function, :eth)
:ok
on_exit(fn ->
Application.put_env(:explorer, :checksum_function, configuration)
end)
end
test "redirects to address/:address_id/transactions", %{conn: conn} do
insert(:address, hash: "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed")
insert(:address, hash: "0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed")
conn = get(conn, "/address/0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed")
@ -48,7 +77,7 @@ defmodule BlockScoutWeb.AddressControllerTest do
end
describe "GET address_counters/2" do
test "returns address counters" do
test "returns address counters", %{conn: conn} do
address = insert(:address)
conn = get(conn, "/address_counters", %{"id" => Address.checksum(address.hash)})

@ -4,7 +4,22 @@ defmodule BlockScoutWeb.AddressReadContractControllerTest do
alias Explorer.ExchangeRates.Token
alias Explorer.Chain.Address
import Mox
describe "GET index/3" do
setup :set_mox_global
setup do
configuration = Application.get_env(:explorer, :checksum_function)
Application.put_env(:explorer, :checksum_function, :eth)
:ok
on_exit(fn ->
Application.put_env(:explorer, :checksum_function, configuration)
end)
end
test "with invalid address hash", %{conn: conn} do
conn = get(conn, address_read_contract_path(BlockScoutWeb.Endpoint, :index, "invalid_address"))

@ -2,10 +2,24 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
use BlockScoutWeb.ConnCase, async: true
import BlockScoutWeb.WebRouter.Helpers, only: [address_token_path: 3]
import Mox
alias Explorer.Chain.{Address, Token}
describe "GET index/2" do
setup :set_mox_global
setup do
configuration = Application.get_env(:explorer, :checksum_function)
Application.put_env(:explorer, :checksum_function, :eth)
:ok
on_exit(fn ->
Application.put_env(:explorer, :checksum_function, configuration)
end)
end
test "with invalid address hash", %{conn: conn} do
conn = get(conn, address_token_path(conn, :index, "invalid_address"))

@ -2,11 +2,25 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
use BlockScoutWeb.ConnCase, async: true
import BlockScoutWeb.WebRouter.Helpers, only: [address_transaction_path: 3, address_transaction_path: 4]
import Mox
alias Explorer.Chain.{Address, Transaction}
alias Explorer.ExchangeRates.Token
describe "GET index/2" do
setup :set_mox_global
setup do
configuration = Application.get_env(:explorer, :checksum_function)
Application.put_env(:explorer, :checksum_function, :eth)
:ok
on_exit(fn ->
Application.put_env(:explorer, :checksum_function, configuration)
end)
end
test "with invalid address hash", %{conn: conn} do
conn = get(conn, address_transaction_path(conn, :index, "invalid_address"))

@ -1,9 +1,23 @@
defmodule BlockScoutWeb.Schema.Subscription.TokenTransfersTest do
use BlockScoutWeb.SubscriptionCase
import Mox
alias BlockScoutWeb.Notifier
describe "token_transfers field" do
setup :set_mox_global
setup do
configuration = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint, pubsub: [name: BlockScoutWeb.PubSub])
:ok
on_exit(fn ->
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint, configuration)
end)
end
test "with valid argument, returns all expected fields", %{socket: socket} do
transaction = insert(:transaction)
token_transfer = insert(:token_transfer, transaction: transaction)

@ -38,6 +38,40 @@ defmodule BlockScoutWeb.ApiDocsViewTest do
end
end
describe "blockscout_url/2" do
test "set_path = true returns url with path" do
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint,
url: [scheme: "https", host: "blockscout.com", api_path: "/eth/mainnet", path: "/eth/mainnet"]
)
assert APIDocsView.blockscout_url(true, true) == "https://blockscout.com/eth/mainnet"
end
test "set_path = false returns url w/out path" do
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint,
url: [scheme: "https", host: "blockscout.com", api_path: "/eth/mainnet", path: "/eth/mainnet"]
)
assert APIDocsView.blockscout_url(false) == "https://blockscout.com"
end
test "set_path = true is_api returns url with api_path" do
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint,
url: [scheme: "https", host: "blockscout.com", api_path: "/eth/mainnet", path: "/"]
)
assert APIDocsView.blockscout_url(true, true) == "https://blockscout.com/eth/mainnet"
end
test "set_path = true is_api returns url with path" do
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint,
url: [scheme: "https", host: "blockscout.com", api_path: "/eth/mainnet", path: "/eth/mainnet2"]
)
assert APIDocsView.blockscout_url(true, false) == "https://blockscout.com/eth/mainnet2"
end
end
describe "eth_rpc_api_url/1" do
setup do
original = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)

Loading…
Cancel
Save