Merge pull request #1777 from poanetwork/ab-token-transfer-on-transaction-page

optionally show ERC-20 token transfer info
pull/1770/head
Ayrat Badykov 6 years ago committed by GitHub
commit a1773103fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 42
      apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex
  3. 43
      apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex
  4. 46
      apps/block_scout_web/priv/gettext/default.pot
  5. 46
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po

@ -5,6 +5,7 @@
- [#1739](https://github.com/poanetwork/blockscout/pull/1739) - highlight decompiled source code - [#1739](https://github.com/poanetwork/blockscout/pull/1739) - highlight decompiled source code
- [#1696](https://github.com/poanetwork/blockscout/pull/1696) - full-text search by tokens - [#1696](https://github.com/poanetwork/blockscout/pull/1696) - full-text search by tokens
- [#1742](https://github.com/poanetwork/blockscout/pull/1742) - Support RSK - [#1742](https://github.com/poanetwork/blockscout/pull/1742) - Support RSK
- [#1777](https://github.com/poanetwork/blockscout/pull/1777) - show ERC-20 token transfer info on transaction page
### Fixes ### Fixes

@ -138,20 +138,38 @@
</div> </div>
</div> </div>
<div class="col-md-12 col-lg-4 d-flex flex-column flex-md-row flex-lg-column"> <% token_transfer = assigns[:token_transfers] && erc20_token_transfer(@transaction, @token_transfers) %>
<!-- Value --> <%= if token_transfer do %>
<div class="card card-primary flex-grow-1"> <div class="col-md-12 col-lg-4 d-flex flex-column flex-md-row flex-lg-column">
<div class="card-body"> <!-- Value -->
<h2 class="card-title text-white"><%= gettext "Ether" %> <%= gettext "Value" %></h2> <div class="card card-primary flex-grow-1">
<div class="text-right"> <div class="card-body">
<h3 class="text-white"> <h2 class="card-title text-white"><%= gettext "ERC-20" %> <%= gettext "Token Transfer" %></h2>
<%= value(@transaction) %> <div class="text-right">
</h3> <h3 class="text-white">
<span class="text-white text-faded" data-wei-value=<%= @transaction.value.value %> data-usd-exchange-rate=<%= @exchange_rate.usd_value %>></span> <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>
</div>
</div> </div>
</div>
</div> </div>
<% else %>
<div class="col-md-12 col-lg-4 d-flex flex-column flex-md-row flex-lg-column">
<!-- Value -->
<div class="card card-primary flex-grow-1">
<div class="card-body">
<h2 class="card-title text-white"><%= gettext "Ether" %> <%= gettext "Value" %></h2>
<div class="text-right">
<h3 class="text-white">
<%= value(@transaction) %>
</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>
<% end %>
<!-- Gas --> <!-- Gas -->
<div class="card flex-grow-1 ml-0 ml-md-5 ml-lg-0"> <div class="card flex-grow-1 ml-0 ml-md-5 ml-lg-0">
<div class="card-body"> <div class="card-body">

@ -1,15 +1,17 @@
defmodule BlockScoutWeb.TransactionView do defmodule BlockScoutWeb.TransactionView do
use BlockScoutWeb, :view use BlockScoutWeb, :view
alias ABI.TypeDecoder
alias BlockScoutWeb.{AddressView, BlockView, TabHelpers} alias BlockScoutWeb.{AddressView, BlockView, TabHelpers}
alias Cldr.Number alias Cldr.Number
alias Explorer.Chain alias Explorer.Chain
alias Explorer.Chain.Block.Reward alias Explorer.Chain.Block.Reward
alias Explorer.Chain.{Address, Block, InternalTransaction, Transaction, Wei} alias Explorer.Chain.{Address, Block, InternalTransaction, TokenTransfer, Transaction, Wei}
alias Explorer.ExchangeRates.Token alias Explorer.ExchangeRates.Token
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"]
@ -31,6 +33,45 @@ defmodule BlockScoutWeb.TransactionView do
def value_transfer?(_), do: false def value_transfer?(_), do: false
def erc20_token_transfer(
%Transaction{
status: :ok,
created_contract_address_hash: nil,
input: input,
value: value
},
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}]
try do
[address, value] =
params
|> Base.decode16!(case: :mixed)
|> TypeDecoder.decode_raw(types)
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
_ -> nil
end
_ ->
nil
end
end
def erc20_token_transfer(_, _) do
nil
end
def processing_time_duration(%Transaction{block: nil}) do def processing_time_duration(%Transaction{block: nil}) do
:pending :pending
end end

@ -49,7 +49,7 @@ msgid "%{subnetwork} Explorer - BlockScout"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:128 #: lib/block_scout_web/views/transaction_view.ex:169
msgid "(Awaiting internal transactions for status)" msgid "(Awaiting internal transactions for status)"
msgstr "" msgstr ""
@ -165,7 +165,7 @@ msgid "Block Number"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:20 #: lib/block_scout_web/views/transaction_view.ex:22
msgid "Block Pending" msgid "Block Pending"
msgstr "" msgstr ""
@ -278,12 +278,12 @@ msgid "Contract Address Pending"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:205 #: lib/block_scout_web/views/transaction_view.ex:246
msgid "Contract Call" msgid "Contract Call"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:204 #: lib/block_scout_web/views/transaction_view.ex:245
msgid "Contract Creation" msgid "Contract Creation"
msgstr "" msgstr ""
@ -377,12 +377,12 @@ msgid "Error trying to fetch balances."
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:132 #: lib/block_scout_web/views/transaction_view.ex:173
msgid "Error: %{reason}" msgid "Error: %{reason}"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:130 #: lib/block_scout_web/views/transaction_view.ex:171
msgid "Error: (Awaiting internal transactions for reason)" msgid "Error: (Awaiting internal transactions for reason)"
msgstr "" msgstr ""
@ -392,7 +392,7 @@ msgstr ""
#: lib/block_scout_web/templates/layout/app.html.eex:66 #: lib/block_scout_web/templates/layout/app.html.eex:66
#: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20
#: lib/block_scout_web/templates/transaction/_tile.html.eex:27 #: lib/block_scout_web/templates/transaction/_tile.html.eex:27
#: lib/block_scout_web/templates/transaction/overview.html.eex:145 #: lib/block_scout_web/templates/transaction/overview.html.eex:163
#: lib/block_scout_web/views/wei_helpers.ex:72 #: lib/block_scout_web/views/wei_helpers.ex:72
msgid "Ether" msgid "Ether"
msgstr "" msgstr ""
@ -431,7 +431,7 @@ msgid "GET"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:158 #: lib/block_scout_web/templates/transaction/overview.html.eex:176
msgid "Gas" msgid "Gas"
msgstr "" msgstr ""
@ -495,7 +495,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:43 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:43
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:10 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:10
#: lib/block_scout_web/views/address_view.ex:295 #: lib/block_scout_web/views/address_view.ex:295
#: lib/block_scout_web/views/transaction_view.ex:258 #: lib/block_scout_web/views/transaction_view.ex:299
msgid "Internal Transactions" msgid "Internal Transactions"
msgstr "" msgstr ""
@ -513,7 +513,7 @@ msgid "Less than"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:170 #: lib/block_scout_web/templates/transaction/overview.html.eex:188
msgid "Limit" msgid "Limit"
msgstr "" msgstr ""
@ -521,7 +521,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:21 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:21
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:48 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:48
#: lib/block_scout_web/templates/transaction_log/index.html.eex:10 #: lib/block_scout_web/templates/transaction_log/index.html.eex:10
#: lib/block_scout_web/views/transaction_view.ex:259 #: lib/block_scout_web/views/transaction_view.ex:300
msgid "Logs" msgid "Logs"
msgstr "" msgstr ""
@ -533,7 +533,7 @@ msgid "Market Cap"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:113 #: lib/block_scout_web/views/transaction_view.ex:154
msgid "Max of" msgid "Max of"
msgstr "" msgstr ""
@ -661,8 +661,8 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:44 #: lib/block_scout_web/templates/layout/_topnav.html.eex:44
#: lib/block_scout_web/views/transaction_view.ex:127 #: lib/block_scout_web/views/transaction_view.ex:168
#: lib/block_scout_web/views/transaction_view.ex:161 #: lib/block_scout_web/views/transaction_view.ex:202
msgid "Pending" msgid "Pending"
msgstr "" msgstr ""
@ -762,7 +762,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8
#: lib/block_scout_web/views/transaction_view.ex:129 #: lib/block_scout_web/views/transaction_view.ex:170
msgid "Success" msgid "Success"
msgstr "" msgstr ""
@ -872,8 +872,9 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:4 #: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:4
#: lib/block_scout_web/templates/transaction/overview.html.eex:147
#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4
#: lib/block_scout_web/views/transaction_view.ex:203 #: lib/block_scout_web/views/transaction_view.ex:244
msgid "Token Transfer" msgid "Token Transfer"
msgstr "" msgstr ""
@ -885,7 +886,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:36 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:36
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:10 #: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:10
#: lib/block_scout_web/views/tokens/overview_view.ex:35 #: lib/block_scout_web/views/tokens/overview_view.ex:35
#: lib/block_scout_web/views/transaction_view.ex:257 #: lib/block_scout_web/views/transaction_view.ex:298
msgid "Token Transfers" msgid "Token Transfers"
msgstr "" msgstr ""
@ -926,7 +927,7 @@ msgid "Total transactions"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:206 #: lib/block_scout_web/views/transaction_view.ex:247
msgid "Transaction" msgid "Transaction"
msgstr "" msgstr ""
@ -993,7 +994,7 @@ msgid "Unique Token"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:163 #: lib/block_scout_web/templates/transaction/overview.html.eex:181
msgid "Used" msgid "Used"
msgstr "" msgstr ""
@ -1014,7 +1015,7 @@ msgid "Validations"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:145 #: lib/block_scout_web/templates/transaction/overview.html.eex:163
msgid "Value" msgid "Value"
msgstr "" msgstr ""
@ -1732,3 +1733,8 @@ msgstr ""
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:52 #: lib/block_scout_web/templates/address_contract_verification/new.html.eex:52
msgid "Optimization runs" msgid "Optimization runs"
msgstr "" msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:147
msgid "ERC-20"
msgstr ""

@ -49,7 +49,7 @@ msgid "%{subnetwork} Explorer - BlockScout"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:128 #: lib/block_scout_web/views/transaction_view.ex:169
msgid "(Awaiting internal transactions for status)" msgid "(Awaiting internal transactions for status)"
msgstr "" msgstr ""
@ -165,7 +165,7 @@ msgid "Block Number"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:20 #: lib/block_scout_web/views/transaction_view.ex:22
msgid "Block Pending" msgid "Block Pending"
msgstr "" msgstr ""
@ -278,12 +278,12 @@ msgid "Contract Address Pending"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:205 #: lib/block_scout_web/views/transaction_view.ex:246
msgid "Contract Call" msgid "Contract Call"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:204 #: lib/block_scout_web/views/transaction_view.ex:245
msgid "Contract Creation" msgid "Contract Creation"
msgstr "" msgstr ""
@ -377,12 +377,12 @@ msgid "Error trying to fetch balances."
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:132 #: lib/block_scout_web/views/transaction_view.ex:173
msgid "Error: %{reason}" msgid "Error: %{reason}"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:130 #: lib/block_scout_web/views/transaction_view.ex:171
msgid "Error: (Awaiting internal transactions for reason)" msgid "Error: (Awaiting internal transactions for reason)"
msgstr "" msgstr ""
@ -392,7 +392,7 @@ msgstr ""
#: lib/block_scout_web/templates/layout/app.html.eex:66 #: lib/block_scout_web/templates/layout/app.html.eex:66
#: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20
#: lib/block_scout_web/templates/transaction/_tile.html.eex:27 #: lib/block_scout_web/templates/transaction/_tile.html.eex:27
#: lib/block_scout_web/templates/transaction/overview.html.eex:145 #: lib/block_scout_web/templates/transaction/overview.html.eex:163
#: lib/block_scout_web/views/wei_helpers.ex:72 #: lib/block_scout_web/views/wei_helpers.ex:72
msgid "Ether" msgid "Ether"
msgstr "POA" msgstr "POA"
@ -431,7 +431,7 @@ msgid "GET"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:158 #: lib/block_scout_web/templates/transaction/overview.html.eex:176
msgid "Gas" msgid "Gas"
msgstr "" msgstr ""
@ -495,7 +495,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:43 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:43
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:10 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:10
#: lib/block_scout_web/views/address_view.ex:295 #: lib/block_scout_web/views/address_view.ex:295
#: lib/block_scout_web/views/transaction_view.ex:258 #: lib/block_scout_web/views/transaction_view.ex:299
msgid "Internal Transactions" msgid "Internal Transactions"
msgstr "" msgstr ""
@ -513,7 +513,7 @@ msgid "Less than"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:170 #: lib/block_scout_web/templates/transaction/overview.html.eex:188
msgid "Limit" msgid "Limit"
msgstr "" msgstr ""
@ -521,7 +521,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:21 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:21
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:48 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:48
#: lib/block_scout_web/templates/transaction_log/index.html.eex:10 #: lib/block_scout_web/templates/transaction_log/index.html.eex:10
#: lib/block_scout_web/views/transaction_view.ex:259 #: lib/block_scout_web/views/transaction_view.ex:300
msgid "Logs" msgid "Logs"
msgstr "" msgstr ""
@ -533,7 +533,7 @@ msgid "Market Cap"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:113 #: lib/block_scout_web/views/transaction_view.ex:154
msgid "Max of" msgid "Max of"
msgstr "" msgstr ""
@ -661,8 +661,8 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:44 #: lib/block_scout_web/templates/layout/_topnav.html.eex:44
#: lib/block_scout_web/views/transaction_view.ex:127 #: lib/block_scout_web/views/transaction_view.ex:168
#: lib/block_scout_web/views/transaction_view.ex:161 #: lib/block_scout_web/views/transaction_view.ex:202
msgid "Pending" msgid "Pending"
msgstr "" msgstr ""
@ -762,7 +762,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8
#: lib/block_scout_web/views/transaction_view.ex:129 #: lib/block_scout_web/views/transaction_view.ex:170
msgid "Success" msgid "Success"
msgstr "" msgstr ""
@ -872,8 +872,9 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:4 #: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:4
#: lib/block_scout_web/templates/transaction/overview.html.eex:147
#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4
#: lib/block_scout_web/views/transaction_view.ex:203 #: lib/block_scout_web/views/transaction_view.ex:244
msgid "Token Transfer" msgid "Token Transfer"
msgstr "" msgstr ""
@ -885,7 +886,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:36 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:36
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:10 #: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:10
#: lib/block_scout_web/views/tokens/overview_view.ex:35 #: lib/block_scout_web/views/tokens/overview_view.ex:35
#: lib/block_scout_web/views/transaction_view.ex:257 #: lib/block_scout_web/views/transaction_view.ex:298
msgid "Token Transfers" msgid "Token Transfers"
msgstr "" msgstr ""
@ -926,7 +927,7 @@ msgid "Total transactions"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:206 #: lib/block_scout_web/views/transaction_view.ex:247
msgid "Transaction" msgid "Transaction"
msgstr "" msgstr ""
@ -993,7 +994,7 @@ msgid "Unique Token"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:163 #: lib/block_scout_web/templates/transaction/overview.html.eex:181
msgid "Used" msgid "Used"
msgstr "" msgstr ""
@ -1014,7 +1015,7 @@ msgid "Validations"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:145 #: lib/block_scout_web/templates/transaction/overview.html.eex:163
msgid "Value" msgid "Value"
msgstr "" msgstr ""
@ -1732,3 +1733,8 @@ msgstr ""
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:52 #: lib/block_scout_web/templates/address_contract_verification/new.html.eex:52
msgid "Optimization runs" msgid "Optimization runs"
msgstr "" msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:147
msgid "ERC-20"
msgstr ""

Loading…
Cancel
Save