finish erc20 info

pull/1777/head
Ayrat Badykov 6 years ago
parent 57d5a0adbf
commit 48f257013a
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 9
      apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex
  2. 49
      apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex

@ -138,7 +138,8 @@
</div> </div>
</div> </div>
<%= if erc20_token_transfer?(@transaction) do %> <% token_transfer = erc20_token_transfer(@transaction, @token_transfers) %>
<%= if token_transfer do %>
<div class="col-md-12 col-lg-4 d-flex flex-column flex-md-row flex-lg-column"> <div class="col-md-12 col-lg-4 d-flex flex-column flex-md-row flex-lg-column">
<!-- Value --> <!-- Value -->
<div class="card card-primary flex-grow-1"> <div class="card card-primary flex-grow-1">
@ -146,9 +147,11 @@
<h2 class="card-title text-white"><%= gettext "ERC-20" %> <%= gettext "Token Transfer" %></h2> <h2 class="card-title text-white"><%= gettext "ERC-20" %> <%= gettext "Token Transfer" %></h2>
<div class="text-right"> <div class="text-right">
<h3 class="text-white"> <h3 class="text-white">
<%= erc20_token_transfer_params(@transaction, @token_transfers) %> <span class="col-12 col-md-7 ml-3 ml-sm-0">
<%= token_transfer_amount(token_transfer) %>
<%= link(token_symbol(token_transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, token_transfer.token.contract_address_hash)) %>
</span>
</h3> </h3>
<span class="text-white text-faded" data-wei-value=<%= @transaction.value.value %> data-usd-exchange-rate=<%= @exchange_rate.usd_value %>></span>
</div> </div>
</div> </div>
</div> </div>

@ -11,6 +11,7 @@ defmodule BlockScoutWeb.TransactionView do
alias Timex.Duration alias Timex.Duration
import BlockScoutWeb.Gettext import BlockScoutWeb.Gettext
import BlockScoutWeb.Tokens.Helpers
@tabs ["token_transfers", "internal_transactions", "logs"] @tabs ["token_transfers", "internal_transactions", "logs"]
@ -32,45 +33,43 @@ defmodule BlockScoutWeb.TransactionView do
def value_transfer?(_), do: false def value_transfer?(_), do: false
def erc20_token_transfer?(%Transaction{ def erc20_token_transfer(
status: :ok, %Transaction{
created_contract_address_hash: nil, status: :ok,
input: input created_contract_address_hash: nil,
}) do input: input,
case to_string(input) do value: value
unquote(TokenTransfer.transfer_function_signature()) <> params -> },
token_transfers
) do
zero_wei = %Wei{value: Decimal.new(0)}
case {to_string(input), value} do
{unquote(TokenTransfer.transfer_function_signature()) <> params, ^zero_wei} ->
types = [:address, {:uint, 256}] types = [:address, {:uint, 256}]
try do try do
[_address, _value] = [address, value] =
params params
|> Base.decode16!(case: :mixed) |> Base.decode16!(case: :mixed)
|> TypeDecoder.decode_raw(types) |> TypeDecoder.decode_raw(types)
true decimal_value = Decimal.new(value)
Enum.find(token_transfers, fn token_transfer ->
token_transfer.to_address_hash.bytes == address && token_transfer.amount == decimal_value
end)
rescue rescue
_ -> false _ -> nil
end end
_ -> _ ->
false nil
end end
end end
def erc20_token_transfer?(_) do def erc20_token_transfer(_, _) do
false nil
end
def erc20_token_transfer_params(transaction, _token_transfers) do
types = [:address, {:uint, 256}]
unquote(TokenTransfer.transfer_function_signature()) <> params = to_string(transaction.input)
[_address, value] =
params
|> Base.decode16!(case: :mixed)
|> TypeDecoder.decode_raw(types)
Wei.to(%Wei{value: Decimal.new(value)}, :ether)
end end
def processing_time_duration(%Transaction{block: nil}) do def processing_time_duration(%Transaction{block: nil}) do

Loading…
Cancel
Save