Merge pull request #5119 from blockscout/vb-inventory-controller-refactoring

Inventory controller refactoring
pull/5126/head
Victor Baranov 3 years ago committed by GitHub
commit cae5dd5c50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 33
      apps/block_scout_web/lib/block_scout_web/controllers/tokens/inventory_controller.ex

@ -6,6 +6,7 @@
### Fixes ### Fixes
### Chore ### Chore
- [#5119](https://github.com/blockscout/blockscout/pull/5119) - Inventory controller refactoring
- [#5118](https://github.com/blockscout/blockscout/pull/5118) - Fix top navigation template - [#5118](https://github.com/blockscout/blockscout/pull/5118) - Fix top navigation template

@ -1,10 +1,10 @@
defmodule BlockScoutWeb.Tokens.InventoryController do defmodule BlockScoutWeb.Tokens.InventoryController do
use BlockScoutWeb, :controller use BlockScoutWeb, :controller
alias BlockScoutWeb.{AccessHelpers, Controller} alias BlockScoutWeb.AccessHelpers
alias BlockScoutWeb.Tokens.InventoryView alias BlockScoutWeb.Tokens.{HolderController, InventoryView}
alias Explorer.{Chain, Market} alias Explorer.Chain
alias Explorer.Chain.{Address, TokenTransfer} alias Explorer.Chain.TokenTransfer
alias Phoenix.View alias Phoenix.View
import BlockScoutWeb.Chain, only: [split_list_by_page: 1, default_paging_options: 0] import BlockScoutWeb.Chain, only: [split_list_by_page: 1, default_paging_options: 0]
@ -66,29 +66,8 @@ defmodule BlockScoutWeb.Tokens.InventoryController do
end end
end end
def index(conn, %{"token_id" => address_hash_string} = params) do def index(conn, params) do
options = [necessity_by_association: %{[contract_address: :smart_contract] => :optional}] HolderController.index(conn, params)
with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string),
{:ok, token} <- Chain.token_from_address_hash(address_hash, options),
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params) do
render(
conn,
"index.html",
current_path: Controller.current_full_path(conn),
token: Market.add_price(token),
counters_path: token_path(conn, :token_counters, %{"id" => Address.checksum(address_hash)})
)
else
{:restricted_access, _} ->
not_found(conn)
:error ->
not_found(conn)
{:error, :not_found} ->
not_found(conn)
end
end end
defp unique_tokens_paging_options(%{"unique_token" => token_id}), defp unique_tokens_paging_options(%{"unique_token" => token_id}),

Loading…
Cancel
Save