redirect to token instance transfers page

pull/2642/head
Ayrat Badykov 5 years ago
parent e5f127c06e
commit 97dc5adbad
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 6
      apps/block_scout_web/lib/block_scout_web/controllers/tokens/instance/transfer_controller.ex
  2. 8
      apps/block_scout_web/lib/block_scout_web/controllers/tokens/instance_controller.ex
  3. 4
      apps/block_scout_web/lib/block_scout_web/controllers/tokens/inventory_controller.ex
  4. 38
      apps/block_scout_web/lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex
  5. 2
      apps/block_scout_web/lib/block_scout_web/templates/tokens/inventory/_token.html.eex
  6. 21
      apps/block_scout_web/lib/block_scout_web/views/tokens/instance/overview_view.ex
  7. 2
      apps/block_scout_web/lib/block_scout_web/views/tokens/instance/transfer_view.ex
  8. 6
      apps/block_scout_web/test/block_scout_web/controllers/tokens/instance_controller_test.exs

@ -3,9 +3,11 @@ defmodule BlockScoutWeb.Tokens.Instance.TransferController do
alias Explorer.{Chain, Market}
def show(conn, %{"token_id" => token_id, "id" => token_address_hash}) do
def index(conn, %{"token_id" => token_id, "instance_id" => token_address_hash}) do
options = [necessity_by_association: %{[contract_address: :smart_contract] => :optional}]
with {:ok, hash} <- Chain.string_to_address_hash(token_address_hash),
{:ok, token} <- Chain.token_from_address_hash(hash),
{:ok, token} <- Chain.token_from_address_hash(hash, options),
{:ok, token_transfer} <-
Chain.erc721_token_instance_from_token_id_and_token_address(token_id, hash) do
render(

@ -5,10 +5,10 @@ defmodule BlockScoutWeb.Tokens.InstanceController do
def show(conn, %{"token_id" => token_id, "id" => token_address_hash}) do
with {:ok, hash} <- Chain.string_to_address_hash(token_address_hash),
{:ok, token_address} <- Chain.hash_to_address(hash, []),
{:ok, token_transfer} <-
Chain.erc721_token_instance_from_token_id_and_token_address(token_id, token_address.hash) do
json(conn, token_transfer)
{:ok, _token_address} <- Chain.token_from_address_hash(hash, []),
{:ok, _token_transfer} <-
Chain.erc721_token_instance_from_token_id_and_token_address(token_id, hash) |> IO.inspect() do
redirect(conn, to: token_instance_transfer_path(conn, :index, token_id, token_address_hash))
else
_ ->
not_found(conn)

@ -39,7 +39,9 @@ defmodule BlockScoutWeb.Tokens.InventoryController do
View.render_to_string(
InventoryView,
"_token.html",
token_transfer: token_transfer
token_transfer: token_transfer,
token: token,
conn: conn
)
end)

@ -0,0 +1,38 @@
<section class="container">
<%= render(
OverviewView,
"_details.html",
token: @token,
total_token_transfers: @total_token_transfers,
token_id: @token_instance.token_id,
conn: @conn
) %>
<section>
<div class="card">
<%= render OverviewView, "_tabs.html", assigns %>
<div class="card-body" data-async-load data-async-listing="<%= @current_path %>">
<h2 class="card-title"><%= gettext "Token Transfers" %></h2>
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %>
<button data-error-message class="alert alert-danger col-12 text-left" style="display: none;">
<span href="#" class="alert-link"><%= gettext("Something went wrong, click to reload.") %></span>
</button>
<div data-empty-response-message class="tile tile-muted text-center" style="display: none;">
<span data-selector="empty-transactions-list">
<%= gettext "There are no transfers for this Token." %>
</span>
</div>
<div data-items>
<%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %>
</div>
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %>
</div>
</div>
</section>
</section>

@ -10,7 +10,7 @@
<span class="d-flex flex-md-row flex-column mt-3 mt-md-0">
<span class="mr-1"><%= gettext "Token ID" %>:</span>
<span class="tile-title">
<%= @token_transfer.token_id %>
<%= link(@token_transfer.token_id, to: token_instance_path(@conn, :show, to_string(@token_transfer.token_id), @token.contract_address_hash)) %>
</span>
</span>

@ -0,0 +1,21 @@
defmodule BlockScoutWeb.Tokens.Instance.OverviewView do
use BlockScoutWeb, :view
alias Explorer.Chain.Token
alias BlockScoutWeb.CurrencyHelpers
def token_name?(%Token{name: nil}), do: false
def token_name?(%Token{name: _}), do: true
def decimals?(%Token{decimals: nil}), do: false
def decimals?(%Token{decimals: _}), do: true
def total_supply?(%Token{total_supply: nil}), do: false
def total_supply?(%Token{total_supply: _}), do: true
def total_supply_usd(token) do
tokens = CurrencyHelpers.divide_decimals(token.total_supply, token.decimals)
price = token.usd_value
Decimal.mult(tokens, price)
end
end

@ -1,3 +1,5 @@
defmodule BlockScoutWeb.Tokens.Instance.TransferView do
use BlockScoutWeb, :view
alias BlockScoutWeb.Tokens.Instance.OverviewView
end

@ -2,9 +2,11 @@ defmodule BlockScoutWeb.Tokens.InstanceControllerTest do
use BlockScoutWeb.ConnCase, async: false
describe "GET show/2" do
test "returns erc721 token with valid params", %{conn: conn} do
test "redirects with valid params", %{conn: conn} do
contract_address = insert(:address)
insert(:token, contract_address: contract_address)
token_id = 10
insert(:token_transfer,
@ -15,7 +17,7 @@ defmodule BlockScoutWeb.Tokens.InstanceControllerTest do
conn = get(conn, token_instance_path(BlockScoutWeb.Endpoint, :show, token_id, to_string(contract_address.hash)))
assert conn.status == 200
assert conn.status == 302
end
end
end

Loading…
Cancel
Save