Merge pull request #3515 from poanetwork/vb-crc-total-balance

CRC total balance
pull/3517/head
Victor Baranov 4 years ago committed by GitHub
commit c936e5c459
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 39
      apps/block_scout_web/lib/block_scout_web/controllers/address_token_balance_controller.ex
  3. 3
      apps/block_scout_web/lib/block_scout_web/templates/address_token_balance/_token_balances.html.eex
  4. 2
      apps/block_scout_web/priv/gettext/default.pot
  5. 2
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po

@ -1,6 +1,7 @@
## Current ## Current
### Features ### Features
- [#3515](https://github.com/poanetwork/blockscout/pull/3515) - CRC total balance
- [#3513](https://github.com/poanetwork/blockscout/pull/3513) - Allow square brackets for an array input data in contracts interaction - [#3513](https://github.com/poanetwork/blockscout/pull/3513) - Allow square brackets for an array input data in contracts interaction
- [#3480](https://github.com/poanetwork/blockscout/pull/3480) - Add support of Autonity client - [#3480](https://github.com/poanetwork/blockscout/pull/3480) - Add support of Autonity client
- [#3470](https://github.com/poanetwork/blockscout/pull/3470) - Display sum of tokens' USD value at tokens holder's address page - [#3470](https://github.com/poanetwork/blockscout/pull/3470) - Display sum of tokens' USD value at tokens holder's address page

@ -1,7 +1,8 @@
defmodule BlockScoutWeb.AddressTokenBalanceController do defmodule BlockScoutWeb.AddressTokenBalanceController do
use BlockScoutWeb, :controller use BlockScoutWeb, :controller
alias BlockScoutWeb.AccessHelpers import BlockScoutWeb.AddressView, only: [from_address_hash: 1]
alias BlockScoutWeb.{AccessHelpers, CustomContractsHelpers}
alias Explorer.{Chain, Market} alias Explorer.{Chain, Market}
def index(conn, %{"address_id" => address_hash_string} = params) do def index(conn, %{"address_id" => address_hash_string} = params) do
@ -12,18 +13,50 @@ defmodule BlockScoutWeb.AddressTokenBalanceController do
|> Chain.fetch_last_token_balances() |> Chain.fetch_last_token_balances()
|> Market.add_price() |> Market.add_price()
circles_addresses_list = CustomContractsHelpers.get_custom_addresses_list(:circles_addresses)
circles_total_balance =
if Enum.count(circles_addresses_list) > 0 do
token_balances
|> Enum.reduce(Decimal.new(0), fn token_balance, acc_balance ->
{:ok, token_address} = Chain.hash_to_address(token_balance.address_hash)
created_from_address_hash =
if from_address_hash(token_address),
do: "0x" <> Base.encode16(from_address_hash(token_address).bytes, case: :lower),
else: nil
if Enum.member?(circles_addresses_list, created_from_address_hash) && token_balance.token.name == "Circles" &&
token_balance.token.symbol == "CRC" do
Decimal.add(acc_balance, token_balance.value)
else
acc_balance
end
end)
else
Decimal.new(0)
end
case AccessHelpers.restricted_access?(address_hash_string, params) do case AccessHelpers.restricted_access?(address_hash_string, params) do
{:ok, false} -> {:ok, false} ->
conn conn
|> put_status(200) |> put_status(200)
|> put_layout(false) |> put_layout(false)
|> render("_token_balances.html", address_hash: address_hash, token_balances: token_balances) |> render("_token_balances.html",
address_hash: address_hash,
token_balances: token_balances,
circles_total_balance: circles_total_balance
)
_ -> _ ->
conn conn
|> put_status(200) |> put_status(200)
|> put_layout(false) |> put_layout(false)
|> render("_token_balances.html", address_hash: address_hash, token_balances: []) |> render("_token_balances.html",
address_hash: address_hash,
token_balances: [],
circles_total_balance: Decimal.new(0)
)
end end
else else
_ -> _ ->

@ -1,3 +1,6 @@
<%= if Decimal.cmp(@circles_total_balance, 0) == :gt do %>
<p class="address-current-balance"><%= format_according_to_decimals(@circles_total_balance, Decimal.new(18)) %> CRC</p>
<% end %>
<%= if Enum.any?(@token_balances) do %> <%= if Enum.any?(@token_balances) do %>
<a <a
href="#" href="#"

@ -1262,7 +1262,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: #:
#: lib/block_scout_web/templates/address_token_balance/_token_balances.html.eex:33 #: lib/block_scout_web/templates/address_token_balance/_token_balances.html.eex:36
msgid "Search tokens" msgid "Search tokens"
msgstr "" msgstr ""

@ -1262,7 +1262,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: #:
#: lib/block_scout_web/templates/address_token_balance/_token_balances.html.eex:33 #: lib/block_scout_web/templates/address_token_balance/_token_balances.html.eex:36
msgid "Search tokens" msgid "Search tokens"
msgstr "" msgstr ""

Loading…
Cancel
Save