From d5e25c4ab2174eb2330ea9e4ebd5301b9415cc33 Mon Sep 17 00:00:00 2001 From: igamigo Date: Tue, 19 Sep 2023 18:14:25 -0300 Subject: [PATCH] Upgrade Message details (#176) * polish message details * remove warning * fee fix * remove unused function * readd search bar * fix case --- lib/starknet_explorer/block/block_utils.ex | 7 - .../live/message_live.ex | 150 +++++++++++++++--- .../live/pages/block_detail.ex | 2 +- .../live/transaction_live.ex | 36 +++-- 4 files changed, 153 insertions(+), 42 deletions(-) diff --git a/lib/starknet_explorer/block/block_utils.ex b/lib/starknet_explorer/block/block_utils.ex index 2863a40f..954ec61d 100644 --- a/lib/starknet_explorer/block/block_utils.ex +++ b/lib/starknet_explorer/block/block_utils.ex @@ -73,13 +73,6 @@ defmodule StarknetExplorer.BlockUtils do end end - def format_hex_for_display(hex) do - case Integer.parse(hex |> String.replace_prefix("0x", ""), 16) do - {decimal, _} -> (decimal / :math.pow(10, 18)) |> :erlang.float_to_binary([{:decimals, 18}]) - :error -> "Wrong number formatting" - end - end - def calculate_gateway_block_steps(_gateway_block = %{"transaction_receipts" => receipts}) do receipts |> get_steps_from_gateway_receipts diff --git a/lib/starknet_explorer_web/live/message_live.ex b/lib/starknet_explorer_web/live/message_live.ex index b23c6636..5b26c964 100644 --- a/lib/starknet_explorer_web/live/message_live.ex +++ b/lib/starknet_explorer_web/live/message_live.ex @@ -10,18 +10,62 @@ defmodule StarknetExplorerWeb.MessageDetailLive do flash: @flash, session: %{"network" => @network} ) %> +
+ <%= render_info(assigns) %> +
+ """ + end + def render_info(assigns) do + ~H""" + +
-
-

Message

+
- <%= @message.message_hash %> +

Message <%= @message.message_hash %>

+
+
+ <%= @message.timestamp + |> DateTime.from_unix() + |> then(fn {:ok, time} -> time end) + |> Calendar.strftime("%c") %> UTC
+
Message Hash
-
- <%= @message.message_hash |> Utils.shorten_block_hash() %> +
+
+
+ <%= @message.message_hash %> +
+
+ + +
+
+
+
@@ -40,37 +84,88 @@ defmodule StarknetExplorerWeb.MessageDetailLive do
Transaction Hash
-
- <%= @message.transaction_hash %> +
+
+
+ <%= live_redirect(@message.transaction_hash, + to: ~p"/#{@network}/transactions/#{@message.transaction_hash}" + ) %> +
+
+ + +
+
+
+
Timestamp
<%= Utils.get_block_age_from_timestamp(@message.timestamp) %>
+ <%= if !Message.is_l2_to_l1(@message.type) do %> +
+
+
L2 Selector
+
+
+ <%= @message.selector %> +
+
+
+
+
Nonce
+
+
+ + <%= @message.nonce %> + +
+
+ <% end %>
Message Details
-
From Contract Address
-
+ <%= if Message.is_l2_to_l1(@message.type) do %> +
From L2 Contract Address
+ <% else %> +
From L1 Contract Address
+ <% end %> + +
<%= @message.from_address %>
-
- - -
-
To Contract Address
-
+
+ <%= if Message.is_l2_to_l1(@message.type) do %> +
To L1 Contract Address
+ <% else %> +
To L2 Contract Address
+ <% end %> +
+
<%= @message.to_address %>
@@ -108,6 +203,17 @@ defmodule StarknetExplorerWeb.MessageDetailLive do def mount(_params = %{"identifier" => hash}, _session, socket) do message = Message.get_by_hash(hash, socket.assigns.network) + message = + case Message.is_l2_to_l1(message) do + false -> + tx = StarknetExplorer.Transaction.get_by_hash(message.transaction_hash) + decimal_nonce = tx.nonce |> String.replace("0x", "") |> String.to_integer(16) + message |> Map.put(:selector, tx.entry_point_selector) |> Map.put(:nonce, decimal_nonce) + + _ -> + message + end + assigns = [ message: message ] diff --git a/lib/starknet_explorer_web/live/pages/block_detail.ex b/lib/starknet_explorer_web/live/pages/block_detail.ex index 9e85039b..5b4262f3 100644 --- a/lib/starknet_explorer_web/live/pages/block_detail.ex +++ b/lib/starknet_explorer_web/live/pages/block_detail.ex @@ -162,7 +162,7 @@ defmodule StarknetExplorerWeb.BlockDetailLive do case Gateway.fetch_block(socket.assigns.block.number, socket.assigns.network) do {:ok, block = %{"gas_price" => gas_price}} -> execution_resources = BlockUtils.calculate_gateway_block_steps(block) - gas_price = BlockUtils.format_hex_for_display(gas_price) + gas_price = Utils.hex_wei_to_eth(gas_price) {gas_price, execution_resources} diff --git a/lib/starknet_explorer_web/live/transaction_live.ex b/lib/starknet_explorer_web/live/transaction_live.ex index d8789855..43b9aa2e 100644 --- a/lib/starknet_explorer_web/live/transaction_live.ex +++ b/lib/starknet_explorer_web/live/transaction_live.ex @@ -1,5 +1,4 @@ defmodule StarknetExplorerWeb.TransactionLive do - alias StarknetExplorer.BlockUtils use StarknetExplorerWeb, :live_view alias StarknetExplorerWeb.Utils alias StarknetExplorer.Data @@ -457,17 +456,22 @@ defmodule StarknetExplorerWeb.TransactionLive do
-
-
Max Fee
-
- - <%= @transaction.max_fee %> ETH - + <%= if @transaction.sender_address do %> +
+
Max Fee
+
+ + <%= @transaction.max_fee %> ETH + +
-
+ <% end %> +
Nonce
-
<%= @transaction.nonce %>
+
+ <%= @transaction.nonce |> String.replace("0x", "") |> String.to_integer(16) %> +
@@ -582,11 +586,19 @@ defmodule StarknetExplorerWeb.TransactionLive do |> Enum.reject(&is_nil/1) # change fee formatting - actual_fee = BlockUtils.format_hex_for_display(transaction.receipt.actual_fee) - max_fee = BlockUtils.format_hex_for_display(transaction.max_fee) + actual_fee = Utils.hex_wei_to_eth(transaction.receipt.actual_fee) + + transaction = + case transaction.type do + "L1_HANDLER" -> + max_fee = Utils.hex_wei_to_eth(transaction.max_fee) + transaction |> Map.put(:max_fee, max_fee) + + _ -> + transaction + end receipt = transaction.receipt |> Map.put(:actual_fee, actual_fee) - transaction = transaction |> Map.put(:max_fee, max_fee) assigns = [ transaction: transaction,