Merge pull request #3535 from poanetwork/vb-improve-speed-tokens-dropdown

Improve speed of tokens dropdown loading at owner address page
pull/3536/head
Victor Baranov 4 years ago committed by GitHub
commit 1c926d630d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 19
      apps/block_scout_web/lib/block_scout_web/controllers/address_token_balance_controller.ex
  3. 6
      apps/explorer/lib/explorer/chain/supply/token_bridge.ex

@ -10,6 +10,7 @@
- [#3462](https://github.com/poanetwork/blockscout/pull/3462) - Display price for bridged tokens
### Fixes
- [#3535](https://github.com/poanetwork/blockscout/pull/3535) - Improve speed of tokens dropdown loading at owner address page
- [#3530](https://github.com/poanetwork/blockscout/pull/3530) - Allow trailing/leading whitespaces for inputs for contract read methods
- [#3526](https://github.com/poanetwork/blockscout/pull/3526) - Order staking pools
- [#3525](https://github.com/poanetwork/blockscout/pull/3525), [#3533](https://github.com/poanetwork/blockscout/pull/3533) - Address token balance on demand fetcher

@ -12,7 +12,6 @@ defmodule BlockScoutWeb.AddressTokenBalanceController do
token_balances =
address_hash
|> Chain.fetch_last_token_balances()
|> Market.add_price()
Task.start_link(fn ->
TokenBalanceOnDemand.trigger_fetch(address_hash, token_balances)
@ -20,15 +19,25 @@ defmodule BlockScoutWeb.AddressTokenBalanceController do
circles_addresses_list = CustomContractsHelpers.get_custom_addresses_list(:circles_addresses)
token_balances_with_price =
token_balances
|> Market.add_price()
token_balances_except_bridged =
token_balances
|> Enum.filter(fn token_balance -> !token_balance.token.bridged end)
circles_total_balance =
if Enum.count(circles_addresses_list) > 0 do
token_balances
token_balances_except_bridged
|> Enum.reduce(Decimal.new(0), fn token_balance, acc_balance ->
{:ok, token_address} = Chain.hash_to_address(token_balance.address_hash)
from_address = from_address_hash(token_address)
created_from_address_hash =
if from_address_hash(token_address),
do: "0x" <> Base.encode16(from_address_hash(token_address).bytes, case: :lower),
if from_address,
do: "0x" <> Base.encode16(from_address.bytes, case: :lower),
else: nil
if Enum.member?(circles_addresses_list, created_from_address_hash) && token_balance.token.name == "Circles" &&
@ -49,7 +58,7 @@ defmodule BlockScoutWeb.AddressTokenBalanceController do
|> put_layout(false)
|> render("_token_balances.html",
address_hash: address_hash,
token_balances: token_balances,
token_balances: token_balances_with_price,
circles_total_balance: circles_total_balance
)

@ -219,9 +219,11 @@ defmodule Explorer.Chain.Supply.TokenBridge do
bridged_mainnet_tokens_with_supply =
bridged_mainnet_tokens_list
|> Enum.map(fn {bridged_token_hash, bridged_token_symbol} ->
bridged_token_price_from_cache = TokenExchangeRateCache.fetch(bridged_token_symbol)
bridged_token_price =
if TokenExchangeRateCache.fetch(bridged_token_symbol) > 0 do
TokenExchangeRateCache.fetch(bridged_token_symbol)
if bridged_token_price_from_cache && Decimal.cmp(bridged_token_price_from_cache, 0) == :gt do
bridged_token_price_from_cache
else
TokenExchangeRateCache.fetch_token_exchange_rate(bridged_token_symbol)
end

Loading…
Cancel
Save