diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index ef59afd7bb..9ed13b9e0d 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -3630,7 +3630,7 @@ defmodule Explorer.Chain do ] def transaction_to_token_transfers(transaction_hash, options \\ []) when is_list(options) do necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) - paging_options = Keyword.get(options, :paging_options, @default_paging_options) + paging_options = options |> Keyword.get(:paging_options, @default_paging_options) |> Map.put(:asc_order, true) TokenTransfer |> join(:inner, [token_transfer], transaction in assoc(token_transfer, :transaction)) @@ -3641,7 +3641,7 @@ defmodule Explorer.Chain do ) |> TokenTransfer.page_token_transfer(paging_options) |> limit(^paging_options.page_size) - |> order_by([token_transfer], asc: token_transfer.inserted_at) + |> order_by([token_transfer], asc: token_transfer.log_index) |> join_associations(necessity_by_association) |> Repo.all() end diff --git a/apps/explorer/lib/explorer/chain/token_transfer.ex b/apps/explorer/lib/explorer/chain/token_transfer.ex index 2eb7af5f16..fe17971fb5 100644 --- a/apps/explorer/lib/explorer/chain/token_transfer.ex +++ b/apps/explorer/lib/explorer/chain/token_transfer.ex @@ -215,6 +215,10 @@ defmodule Explorer.Chain.TokenTransfer do def page_token_transfer(query, %PagingOptions{key: nil}), do: query + def page_token_transfer(query, %PagingOptions{key: {token_id}, asc_order: true}) do + where(query, [tt], tt.token_id > ^token_id) + end + def page_token_transfer(query, %PagingOptions{key: {token_id}}) do where(query, [tt], tt.token_id < ^token_id) end diff --git a/apps/explorer/lib/explorer/chain/transaction.ex b/apps/explorer/lib/explorer/chain/transaction.ex index 08cd9b8c2c..88696c91c3 100644 --- a/apps/explorer/lib/explorer/chain/transaction.ex +++ b/apps/explorer/lib/explorer/chain/transaction.ex @@ -431,6 +431,7 @@ defmodule Explorer.Chain.Transaction do where: tt.token_contract_address_hash == ^address_hash or tt.to_address_hash == ^address_hash or tt.from_address_hash == ^address_hash, + order_by: [asc: tt.log_index], preload: [:token, [from_address: :names], [to_address: :names]] )