diff --git a/lib/starknet_explorer/transaction.ex b/lib/starknet_explorer/transaction.ex index 07d22b84..02de7acc 100644 --- a/lib/starknet_explorer/transaction.ex +++ b/lib/starknet_explorer/transaction.ex @@ -191,7 +191,9 @@ defmodule StarknetExplorer.Transaction do |> Repo.paginate(params) end - def paginate_transactions_for_index(params, network) do + def paginate_transactions_for_index(params, network, filter \\ "ALL") + + def paginate_transactions_for_index(params, network, "ALL") do query = from t in Transaction, where: t.network == ^network, @@ -209,6 +211,24 @@ defmodule StarknetExplorer.Transaction do query |> Repo.paginate(Map.put(params, :options, %{total_entries: total_rows})) end + def paginate_transactions_for_index(params, network, filter) do + query = + from t in Transaction, + where: t.network == ^network and t.type == ^filter, + join: b in Block, + on: t.block_number == b.number and t.network == b.network, + select: %{hash: t.hash, type: t.type, timestamp: b.timestamp, status: b.status}, + order_by: [desc: b.timestamp] + + total_rows = + case StarknetExplorer.Counts.get(network) do + nil -> get_total_count(network) + entities_count -> entities_count.transactions + end + + query |> Repo.paginate(Map.put(params, :options, %{total_entries: total_rows})) + end + @spec rename_rpc_fields(map) :: map def rename_rpc_fields(rpc_tx = %{"transaction_hash" => th}) do rpc_tx diff --git a/lib/starknet_explorer_web/live/pages/block_detail.ex b/lib/starknet_explorer_web/live/pages/block_detail.ex index 55190831..569df15b 100644 --- a/lib/starknet_explorer_web/live/pages/block_detail.ex +++ b/lib/starknet_explorer_web/live/pages/block_detail.ex @@ -496,7 +496,7 @@ defmodule StarknetExplorerWeb.BlockDetailLive do class="dropdown relative bg-[#232331] p-5 mb-2 rounded-md lg:hidden" phx-hook="Dropdown" > - <%= assigns.view %> + <%= assigns.tx_filter %> diff --git a/lib/starknet_explorer_web/live/transaction_index_live.ex b/lib/starknet_explorer_web/live/transaction_index_live.ex index 111083c9..6c06720f 100644 --- a/lib/starknet_explorer_web/live/transaction_index_live.ex +++ b/lib/starknet_explorer_web/live/transaction_index_live.ex @@ -11,6 +11,7 @@ defmodule StarknetExplorerWeb.TransactionIndexLive do

Transactions

+ <%= render_tx_filter(assigns) %> +
+ +
+ +
+
+
+ """ + end + @impl true def mount(_params, _session, socket) do page = Transaction.paginate_transactions_for_index(%{}, socket.assigns.network) @@ -92,7 +166,8 @@ defmodule StarknetExplorerWeb.TransactionIndexLive do {:ok, assign(socket, page: page, - active_pagination_id: "" + active_pagination_id: "", + tx_filter: "ALL" )} end @@ -104,15 +179,20 @@ defmodule StarknetExplorerWeb.TransactionIndexLive do )} end + @impl true + def handle_event("select-filter", %{"filter" => filter}, socket) do + pagination(socket, 1, filter) + end + @impl true def handle_event("inc_txs", _value, socket) do new_page_number = socket.assigns.page.page_number + 1 - pagination(socket, new_page_number) + pagination(socket, new_page_number, Map.get(socket.assigns, :tx_filter, "ALL")) end def handle_event("dec_txs", _value, socket) do new_page_number = socket.assigns.page.page_number - 1 - pagination(socket, new_page_number) + pagination(socket, new_page_number, Map.get(socket.assigns, :tx_filter, "ALL")) end @impl true @@ -122,7 +202,7 @@ defmodule StarknetExplorerWeb.TransactionIndexLive do socket ) do new_page_number = String.to_integer(page_number) - pagination(socket, new_page_number) + pagination(socket, new_page_number, Map.get(socket.assigns, :tx_filter, "ALL")) end def handle_event("toggle-page-edit", %{"target" => target}, socket) do @@ -130,13 +210,14 @@ defmodule StarknetExplorerWeb.TransactionIndexLive do {:noreply, push_event(socket, "focus", %{id: target})} end - def pagination(socket, new_page_number) do + def pagination(socket, new_page_number, filter \\ "ALL") do page = Transaction.paginate_transactions_for_index( %{page: new_page_number}, - socket.assigns.network + socket.assigns.network, + filter ) - {:noreply, assign(socket, page: page)} + {:noreply, assign(socket, page: page, tx_filter: filter)} end end