Merge pull request #8354 from blockscout/np-change-actb-query

Hotfix for proper addresses' tokens displaying
pull/8358/head
Victor Baranov 1 year ago committed by GitHub
commit 08ab6ef835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 16
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs
  3. 2
      apps/explorer/lib/explorer/chain/address/current_token_balance.ex
  4. 18
      apps/explorer/test/support/factory.ex

@ -13,6 +13,7 @@
### Fixes ### Fixes
- [#8354](https://github.com/blockscout/blockscout/pull/8354) - Hotfix for proper addresses' tokens displaying
- [#8350](https://github.com/blockscout/blockscout/pull/8350) - Add Base Mainnet support for tx actions - [#8350](https://github.com/blockscout/blockscout/pull/8350) - Add Base Mainnet support for tx actions
- [#8282](https://github.com/blockscout/blockscout/pull/8282) - NFT fetcher improvements - [#8282](https://github.com/blockscout/blockscout/pull/8282) - NFT fetcher improvements
- [#8287](https://github.com/blockscout/blockscout/pull/8287) - Add separate hackney pool for TokenInstance fetchers - [#8287](https://github.com/blockscout/blockscout/pull/8287) - Add separate hackney pool for TokenInstance fetchers

@ -1535,21 +1535,29 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
ctbs_erc_20 = ctbs_erc_20 =
for _ <- 0..50 do for _ <- 0..50 do
insert(:address_current_token_balance_with_token_id, address: address, token_type: "ERC-20", token_id: nil) insert(:address_current_token_balance_with_token_id_and_fixed_token_type,
address: address,
token_type: "ERC-20",
token_id: nil
)
|> Repo.preload([:token]) |> Repo.preload([:token])
end end
|> Enum.sort_by(fn x -> x.value end, :asc) |> Enum.sort_by(fn x -> Decimal.to_float(Decimal.mult(x.value, x.token.fiat_value)) end, :asc)
ctbs_erc_721 = ctbs_erc_721 =
for _ <- 0..50 do for _ <- 0..50 do
insert(:address_current_token_balance_with_token_id, address: address, token_type: "ERC-721", token_id: nil) insert(:address_current_token_balance_with_token_id_and_fixed_token_type,
address: address,
token_type: "ERC-721",
token_id: nil
)
|> Repo.preload([:token]) |> Repo.preload([:token])
end end
|> Enum.sort_by(fn x -> x.value end, :asc) |> Enum.sort_by(fn x -> x.value end, :asc)
ctbs_erc_1155 = ctbs_erc_1155 =
for _ <- 0..50 do for _ <- 0..50 do
insert(:address_current_token_balance_with_token_id, insert(:address_current_token_balance_with_token_id_and_fixed_token_type,
address: address, address: address,
token_type: "ERC-1155", token_type: "ERC-1155",
token_id: Enum.random(1..100_000) token_id: Enum.random(1..100_000)

@ -188,10 +188,10 @@ defmodule Explorer.Chain.Address.CurrentTokenBalance do
ctb in __MODULE__, ctb in __MODULE__,
where: ctb.address_hash == ^address_hash, where: ctb.address_hash == ^address_hash,
where: ctb.value > 0, where: ctb.value > 0,
where: ctb.token_type == ^type,
left_join: t in assoc(ctb, :token), left_join: t in assoc(ctb, :token),
on: ctb.token_contract_address_hash == t.contract_address_hash, on: ctb.token_contract_address_hash == t.contract_address_hash,
preload: [token: t], preload: [token: t],
where: t.type == ^type,
select: ctb, select: ctb,
select_merge: ^%{fiat_value: fiat_balance}, select_merge: ^%{fiat_value: fiat_balance},
order_by: ^[desc_nulls_last: fiat_balance], order_by: ^[desc_nulls_last: fiat_balance],

@ -898,7 +898,23 @@ defmodule Explorer.Factory do
%CurrentTokenBalance{ %CurrentTokenBalance{
address: build(:address), address: build(:address),
token_contract_address_hash: insert(:token).contract_address_hash, token_contract_address_hash: insert(:token, type: token_type).contract_address_hash,
block_number: block_number(),
value: Enum.random(1_000_000_000_000_000_000..10_000_000_000_000_000_000),
value_fetched_at: DateTime.utc_now(),
token_id: token_id,
token_type: token_type
}
end
def address_current_token_balance_with_token_id_and_fixed_token_type_factory(%{
token_type: token_type,
address: address,
token_id: token_id
}) do
%CurrentTokenBalance{
address: address,
token_contract_address_hash: insert(:token, type: token_type).contract_address_hash,
block_number: block_number(), block_number: block_number(),
value: Enum.random(1_000_000_000_000_000_000..10_000_000_000_000_000_000), value: Enum.random(1_000_000_000_000_000_000..10_000_000_000_000_000_000),
value_fetched_at: DateTime.utc_now(), value_fetched_at: DateTime.utc_now(),

Loading…
Cancel
Save