diff --git a/lib/starknet_explorer_web/live/pages/block_detail.ex b/lib/starknet_explorer_web/live/pages/block_detail.ex
index 3d828da8..23fb6b7e 100644
--- a/lib/starknet_explorer_web/live/pages/block_detail.ex
+++ b/lib/starknet_explorer_web/live/pages/block_detail.ex
@@ -1,10 +1,34 @@
defmodule StarknetExplorerWeb.BlockDetailLive do
use StarknetExplorerWeb, :live_view
alias StarknetExplorer.Rpc
-
+ alias StarknetExplorerWeb.Utils
defp num_or_hash(<<"0x", _rest::binary>>), do: :hash
defp num_or_hash(_num), do: :num
+ defp block_detail_header(assigns) do
+ ~H"""
+
+
Block detail
+
+
+ Overview
+
+
+ Transactions
+
+ """
+ end
+
def mount(_params = %{"number_or_hash" => param}, _session, socket) do
{:ok, block} =
case num_or_hash(param) do
@@ -16,22 +40,67 @@ defmodule StarknetExplorerWeb.BlockDetailLive do
Rpc.get_block_by_number(num)
end
- {:ok, assign(socket, :block, block)}
+ assigns = [
+ block: block,
+ view: "overview"
+ ]
+
+ {:ok, assign(socket, assigns)}
end
- def render(assigns = %{block: _block}) do
+ @impl true
+ def render(assigns) do
+ ~H"""
+ <%= block_detail_header(assigns) %>
+ <%= render_info(assigns) %>
+ """
+ end
+
+ def render_info(assigns = %{block: block, view: "transactions"}) do
+ ~H"""
+
+
+ Block Transactions
+ <%= for _transaction = %{"transaction_hash" => hash, "type" => type, "version" => version} <- @block["transactions"] do %>
+
+
+
+ Type
+ Version
+ Hash
+
+
+
+ <%= type %>
+ <%= version %>
+ <%= hash |> Utils.shorten_block_hash() %>
+
+
+
+
+ <% end %>
+
+
+ """
+ end
+
+ # TODO:
+ # Do not hardcode:
+ # - Total Execeution Resources
+ # - Gas Price
+ def render_info(assigns = %{block: _block, view: "overview"}) do
~H"""
-
-
Block detail
-
Block Number <%= @block["block_number"] %>
- New Root <%= @block["new_root"] %>
- Parent Hash <%= @block["parent_hash"] %>
+ Block Hash <%= @block["block_hash"] |> Utils.shorten_block_hash() %>
+ Block Status <%= @block["status"] %>
+ State Root <%= @block["new_root"] |> Utils.shorten_block_hash() %>
+ Parent Hash <%= @block["parent_hash"] |> Utils.shorten_block_hash() %>
Sequencer Address <%= @block["sequencer_address"] %>
- Status <%= @block["status"] %>
+ Gas Price <%= "0.000000017333948464 ETH" %>
+ Total execution resources <%= 543_910 %>
Timestamp <%= @block["timestamp"]
|> DateTime.from_unix()
@@ -39,13 +108,12 @@ defmodule StarknetExplorerWeb.BlockDetailLive do
-
- Block Transactions
- <%= for _transaction = %{"transaction_hash" => hash, "type" => type, "version" => version} <- @block["transactions"] do %>
- Type: <%= hash %> Hash: <%= type %> Version: <%= version %>
- <% end %>
-
"""
end
+
+ def handle_event("select-view", %{"view" => view}, socket) do
+ socket = assign(socket, :view, view)
+ {:noreply, socket}
+ end
end
diff --git a/lib/starknet_explorer_web/live/transaction_index_live.ex b/lib/starknet_explorer_web/live/transaction_index_live.ex
index e31c7363..e888a125 100644
--- a/lib/starknet_explorer_web/live/transaction_index_live.ex
+++ b/lib/starknet_explorer_web/live/transaction_index_live.ex
@@ -57,7 +57,6 @@ defmodule StarknetExplorerWeb.TransactionIndexLive do
{:ok,
assign(socket,
- blocks: [],
latest_block: []
)}
end
@@ -66,7 +65,6 @@ defmodule StarknetExplorerWeb.TransactionIndexLive do
def handle_info(:load_blocks, socket) do
{:noreply,
assign(socket,
- blocks: Utils.list_blocks(),
latest_block: Utils.get_latest_block_with_transactions()
)}
end
diff --git a/lib/starknet_explorer_web/live/transaction_live.ex b/lib/starknet_explorer_web/live/transaction_live.ex
index d7a7fb54..3658329a 100644
--- a/lib/starknet_explorer_web/live/transaction_live.ex
+++ b/lib/starknet_explorer_web/live/transaction_live.ex
@@ -1,6 +1,7 @@
defmodule StarknetExplorerWeb.TransactionLive do
use StarknetExplorerWeb, :live_view
alias StarknetExplorer.Rpc
+ alias StarknetExplorerWeb.Utils
defp transaction_header(assigns) do
~H"""
@@ -43,35 +44,49 @@ defmodule StarknetExplorerWeb.TransactionLive do
end
@impl true
- def render(%{transaction: nil, transaction_receipt: nil} = assigns) do
+ def render(assigns) do
~H"""
-
+ <%= transaction_header(assigns) %>
+ <%= render_info(assigns) %>
"""
end
- def render(%{transaction_view: "events"} = assigns) do
+ def render_info(%{transaction: nil, transaction_receipt: nil} = assigns) do
~H"""
<%= transaction_header(assigns) %>
+ """
+ end
+
+ # TODO:
+ # Do not hardcode the following:
+ # Identifier
+ # Name
+ # Age
+ def render_info(%{transaction_view: "events"} = assigns) do
+ ~H"""
- Identifier(TODO)
+ Identifier
Block Number
Transaction Hash
- Name(TODO)
+ Name
From Address
- Age(TODO)
+ Age
<%= for signature <- @transaction_receipt["events"] do %>
- TODO
+
+ <%= "0x008e571d599345e12730f53df66cf74bea8ad238d68844b71ebadb567eae7a1d_4"
+ |> Utils.shorten_block_hash() %>
+
<%= @transaction_receipt["block_number"] %>
- <%= @transaction["transaction_hash"] %>
- TODO
- <%= @transaction["sender_address"] %>
- TODO
+ <%= @transaction["transaction_hash"] |> Utils.shorten_block_hash() %>
+ Transfer
+ <%= @transaction["sender_address"] |> Utils.shorten_block_hash() %>
+ Age: 1h
<% end %>
@@ -79,33 +94,108 @@ defmodule StarknetExplorerWeb.TransactionLive do
"""
end
- def render(%{transaction_view: "message_logs"} = assigns) do
+ # TODO:
+ # Everything here is hardcoded.
+ # I think this information comes from the block.
+ def render_info(%{transaction_view: "message_logs"} = assigns) do
~H"""
- <%= transaction_header(assigns) %>
+
+
+
+ Identifier
+ Message Hash
+ Direction
+ Type
+ From Address
+ To Address
+ Transaction Hash
+ Age
+
+
+
+
+
+ <%= "0x008e571d599345e12730f53df66cf74bea8ad238d68844b71ebadb567eae7a1d"
+ |> Utils.shorten_block_hash() %>
+
+
+ <%= "0x008e571d599345e12730f53df66cf74bea8ad238d68844b71ebadb567eae7a1d"
+ |> Utils.shorten_block_hash() %>
+
+ L2 -> L1
+ Sent On L2
+
+ <%= "0x008e571d599345e12730f53df66cf74bea8ad238d68844b71ebadb567eae7a1d"
+ |> Utils.shorten_block_hash() %>
+
+
+ <%= "0x008e571d599345e12730f53df66cf74bea8ad238d68844b71ebadb567eae7a1d"
+ |> Utils.shorten_block_hash() %>
+
+ 9min
+
+
+
"""
end
- def render(%{transaction_view: "internal_calls"} = assigns) do
+ def render_info(%{transaction_view: "internal_calls"} = assigns) do
~H"""
- <%= transaction_header(assigns) %>
+
+
+
+ Identifier
+ Transaction Hash
+ Type
+ Name
+ Contract Address
+
+
+
+
+
+ <%= "0x008e571d599345e12730f53df66cf74bea8ad238d68844b71ebadb567eae7a1d"
+ |> Utils.shorten_block_hash() %>
+
+
+ <%= "0x008e571d599345e12730f53df66cf74bea8ad238d68844b71ebadb567eae7a1d"
+ |> Utils.shorten_block_hash() %>
+
+ Call
+ __execute__
+
+ <%= "0x008e571d599345e12730f53df66cf74bea8ad238d68844b71ebadb567eae7a1d"
+ |> Utils.shorten_block_hash() %>
+
+
+
+
"""
end
- def render(%{transaction_view: "overview"} = assigns) do
+ # TODO:
+ # Do not hardcode the following:
+ # Call data
+ # Signatures
+ # Execution resources
+ def render_info(%{transaction_view: "overview"} = assigns) do
~H"""
- <%= transaction_header(assigns) %>
Transaction Hash: <%= @transaction["transaction_hash"] %>
Status: <%= @transaction_receipt["status"] %>
Block Hash: <%= @transaction_receipt["block_hash"] %>
Block Number: <%= @transaction_receipt["block_number"] %>
- TODO Transaction Type: <%= @transaction["type"] %>
+ Transaction Type: <%= @transaction["type"] %>
Sender Address: <%= @transaction["sender_address"] %>
Actual Fee: <%= @transaction["max_fee"] %>
Max Fee: <%= @transaction_receipt["actual_fee"] %>
Nonce: <%= @transaction["nonce"] %>
- Input Data (TODO)
+ Input Data
+
+ call approve(spender, amount) -> <%= "0x0219209e083275171774dab1df80982e9df2096516f06319c5c6d71ae0a8480c"
+ |> Utils.shorten_block_hash() %>
+
Input
Type
@@ -114,9 +204,12 @@ defmodule StarknetExplorerWeb.TransactionLive do
- to
+ spender
felt
- 0x11cd02208d6ed241d3fc0dba144f09b70be03003c32e56de2d19aea99b0ca76
+
+ <%= "0x11cd02208d6ed241d3fc0dba144f09b70be03003c32e56de2d19aea99b0ca76"
+ |> Utils.shorten_block_hash() %>
+
token_id
@@ -125,6 +218,40 @@ defmodule StarknetExplorerWeb.TransactionLive do
+
+
+
+ call swap(pool_id, token_from_addr, amount_from, amount_to_min) -> 0x015543c3708653cda9d418b4ccd3be11368e40636c10c44b18cfe756b6d88b29
+
+
+ Input
+ Type
+ Value
+
+
+
+
+ pool_id
+ felt
+ "0x42b8f0484674ca266ac5d08e4ac6a3fe65bd3129795def2dca5c34ecc5f96d2"
+
+
+ token_from_addr
+ felt
+ "0x42b8f0484674ca266ac5d08e4ac6a3fe65bd3129795def2dca5c34ecc5f96d2"
+
+
+ amount_from
+ Uint256
+ "71587356859985694"
+
+
+ amount_to_min
+ Uint256
+ "80225122454772041"
+
+
+
@@ -134,6 +261,7 @@ defmodule StarknetExplorerWeb.TransactionLive do
+ Signature
<%= for {index, signature} <- Enum.with_index(@transaction["signature"]) do %>
<%= index %>
@@ -142,7 +270,14 @@ defmodule StarknetExplorerWeb.TransactionLive do
<% end %>
- Execution Resources (TODO)
+
+
+ Execution Resources
+ STEPS 5083
+ MEMORY 224
+ PEDERSEN_BUILTIN 21
+ RANGE_CHECK_BUILTIN 224
+
"""
end
@@ -164,11 +299,9 @@ defmodule StarknetExplorerWeb.TransactionLive do
:load_transaction,
%{assigns: %{transaction_hash: transaction_hash}} = socket
) do
- {:ok, transaction} =
- Rpc.get_transaction(transaction_hash)
+ {:ok, transaction} = Rpc.get_transaction(transaction_hash)
- {:ok, transaction_receipt} =
- Rpc.get_transaction_receipt(transaction_hash)
+ {:ok, transaction_receipt} = Rpc.get_transaction_receipt(transaction_hash)
assigns = [
transaction: transaction,