From fa9a28149997456a4046cef40d02f996439242ee Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 13 Mar 2019 14:15:34 +0300 Subject: [PATCH] add case insentive search --- apps/block_scout_web/test/block_scout_web/chain_test.exs | 7 +++++++ apps/explorer/lib/explorer/chain.ex | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/block_scout_web/test/block_scout_web/chain_test.exs b/apps/block_scout_web/test/block_scout_web/chain_test.exs index 9ca92c59ab..3d1a7312f4 100644 --- a/apps/block_scout_web/test/block_scout_web/chain_test.exs +++ b/apps/block_scout_web/test/block_scout_web/chain_test.exs @@ -51,6 +51,13 @@ defmodule BlockScoutWeb.ChainTest do assert {:ok, %Address{}} = name |> Chain.from_param() end + test "finds a token by its name even if lowercase name was passed" do + name = "ayr" + insert(:token, symbol: String.upcase(name)) + + assert {:ok, %Address{}} = name |> Chain.from_param() + end + test "returns {:error, :not_found} when garbage is passed in" do assert {:error, :not_found} = Chain.from_param("any ol' thing") end diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 74aa6ce22b..eb3b99bcbb 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -640,7 +640,7 @@ defmodule Explorer.Chain do def token_contract_address_from_token_name(name) when is_binary(name) do query = from(token in Token, - where: token.symbol == ^name, + where: ilike(token.symbol, ^name), select: token.contract_address_hash )