np-search-api
Никита Поздняков 2 years ago
parent cf41a579b7
commit 0aa7393742
No known key found for this signature in database
GPG Key ID: F344106F9804FE5F
  1. 24
      apps/block_scout_web/lib/block_scout_web/views/search_view.ex

@ -26,25 +26,41 @@ defmodule BlockScoutWeb.SearchView do
"type" => search_result.type, "type" => search_result.type,
"name" => search_result.name, "name" => search_result.name,
"symbol" => search_result.symbol, "symbol" => search_result.symbol,
"address" => search_result.address_hash "address" => search_result.address_hash,
"token_url" => token_path(BlockScoutWeb.Endpoint, :show, search_result.address_hash),
"address_url" => address_path(BlockScoutWeb.Endpoint, :show, search_result.address_hash)
} }
end end
def prepare_search_result(%{type: address_or_contract} = search_result) def prepare_search_result(%{type: address_or_contract} = search_result)
when address_or_contract in ["address", "contract"] do when address_or_contract in ["address", "contract"] do
%{"type" => search_result.type, "name" => search_result.name, "address" => search_result.address_hash} %{
"type" => search_result.type,
"name" => search_result.name,
"address" => search_result.address_hash,
"url" => address_path(BlockScoutWeb.Endpoint, :show, search_result.address_hash)
}
end end
def prepare_search_result(%{type: "block"} = search_result) do def prepare_search_result(%{type: "block"} = search_result) do
block_hash = hash_to_string(search_result.block_hash)
%{ %{
"type" => search_result.type, "type" => search_result.type,
"block_number" => search_result.block_number, "block_number" => search_result.block_number,
"block_hash" => hash_to_string(search_result.block_hash) "block_hash" => block_hash,
"url" => block_path(BlockScoutWeb.Endpoint, :show, block_hash)
} }
end end
def prepare_search_result(%{type: "transaction"} = search_result) do def prepare_search_result(%{type: "transaction"} = search_result) do
%{"type" => search_result.type, "tx_hash" => hash_to_string(search_result.tx_hash)} tx_hash = hash_to_string(search_result.tx_hash)
%{
"type" => search_result.type,
"tx_hash" => tx_hash,
"url" => transaction_path(BlockScoutWeb.Endpoint, :show, tx_hash)
}
end end
defp hash_to_string(hash), do: "0x" <> Base.encode16(hash, case: :lower) defp hash_to_string(hash), do: "0x" <> Base.encode16(hash, case: :lower)

Loading…
Cancel
Save