From 089bc39fe414781dbedfa5a30632025e74baed28 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 13 Mar 2019 12:26:35 +0300 Subject: [PATCH 01/14] allow to search by token symbol --- .../block_scout_web/lib/block_scout_web/chain.ex | 16 ++++++++++++---- .../templates/layout/_topnav.html.eex | 2 +- apps/block_scout_web/priv/gettext/default.pot | 10 +++++----- .../priv/gettext/en/LC_MESSAGES/default.po | 10 +++++----- .../test/block_scout_web/chain_test.exs | 7 +++++++ apps/explorer/lib/explorer/chain.ex | 16 ++++++++++++++++ ...20190313085740_add_index_symobl_in_tokens.exs | 7 +++++++ apps/explorer/test/explorer/chain_test.exs | 15 +++++++++++++++ 8 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 apps/explorer/priv/repo/migrations/20190313085740_add_index_symobl_in_tokens.exs diff --git a/apps/block_scout_web/lib/block_scout_web/chain.ex b/apps/block_scout_web/lib/block_scout_web/chain.ex index ed47963856..56f573f85f 100644 --- a/apps/block_scout_web/lib/block_scout_web/chain.ex +++ b/apps/block_scout_web/lib/block_scout_web/chain.ex @@ -11,7 +11,8 @@ defmodule BlockScoutWeb.Chain do number_to_block: 1, string_to_address_hash: 1, string_to_block_hash: 1, - string_to_transaction_hash: 1 + string_to_transaction_hash: 1, + token_contract_address_from_token_name: 1 ] alias Explorer.Chain.Block.Reward @@ -67,10 +68,10 @@ defmodule BlockScoutWeb.Chain do end end - def from_param(formatted_number) when is_binary(formatted_number) do - case param_to_block_number(formatted_number) do + def from_param(string) when is_binary(string) do + case param_to_block_number(string) do {:ok, number} -> number_to_block(number) - {:error, :invalid} -> {:error, :not_found} + _ -> token_address_from_name(string) end end @@ -159,6 +160,13 @@ defmodule BlockScoutWeb.Chain do end end + defp token_address_from_name(name) do + case token_contract_address_from_token_name(name) do + {:ok, hash} -> find_or_insert_address_from_hash(hash) + _ -> {:error, :not_found} + end + end + defp paging_params({%Reward{block: %{number: number}}, _}) do %{"block_number" => number, "index" => 0} end diff --git a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex index 9b298f214b..1eaffa3834 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex @@ -80,7 +80,7 @@
<%= form_for @conn, chain_path(@conn, :search), [class: "form-inline my-2 my-lg-0", method: :get, enforce_utf8: false], fn f -> %>
- <%= search_input f, :q, class: 'form-control mr-auto', placeholder: gettext("Search by address, transaction hash, or block number"), "aria-describedby": "search-icon", "aria-label": gettext("Search"), "data-test": "search_input" %> + <%= search_input f, :q, class: 'form-control mr-auto', placeholder: gettext("Search by address, token symbol name, transaction hash, or block number"), "aria-describedby": "search-icon", "aria-label": gettext("Search"), "data-test": "search_input" %>