From cb9be018a2ab16473256e25a09d463c71c597a5a Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Mon, 9 Oct 2023 11:01:06 -0300 Subject: [PATCH] remove loading from block details --- .../live/pages/block_detail.ex | 207 +++++------------- 1 file changed, 60 insertions(+), 147 deletions(-) diff --git a/lib/starknet_explorer_web/live/pages/block_detail.ex b/lib/starknet_explorer_web/live/pages/block_detail.ex index a8452f16..15d50432 100644 --- a/lib/starknet_explorer_web/live/pages/block_detail.ex +++ b/lib/starknet_explorer_web/live/pages/block_detail.ex @@ -90,26 +90,26 @@ defmodule StarknetExplorerWeb.BlockDetailLive do <% end %> - <%= if @view != "loading" do %> + + """ end @@ -152,62 +152,56 @@ defmodule StarknetExplorerWeb.BlockDetailLive do {:num, num} end - assigns = - if connected?(socket) do - {:ok, block} = - case :timer.tc(fn -> - Enum.find( - StarknetExplorer.IndexCache.latest_blocks(socket.assigns.network), - fn block -> - block.number == param or block.hash == param - end - ) - end) do - {time, block} = {_, %StarknetExplorer.Block{}} -> + {:ok, block} = + case :timer.tc(fn -> + Enum.find( + StarknetExplorer.IndexCache.latest_blocks(socket.assigns.network), + fn block -> + block.number == param or block.hash == param + end + ) + end) do + {time, block} = {_, %StarknetExplorer.Block{}} -> + Logger.debug( + "[Block Detail] Found block #{block.number} in cache in #{time} microseconds" + ) + + {:ok, block} + + {time, _} -> + case type do + :hash -> + {query_time, res} = + :timer.tc(fn -> Data.block_by_hash(param, socket.assigns.network, false) end) + Logger.debug( - "[Block Detail] Found block #{block.number} in cache in #{time} microseconds" + "[Block Detail] Fetched block #{param} in #{query_time} microseconds, query took #{time} microseconds, using :hash" ) - {:ok, block} - - {time, _} -> - case type do - :hash -> - {query_time, res} = - :timer.tc(fn -> Data.block_by_hash(param, socket.assigns.network, false) end) + res - Logger.debug( - "[Block Detail] Fetched block #{param} in #{query_time} microseconds, query took #{time} microseconds, using :hash" - ) + :num -> + {query_time, res} = + :timer.tc(fn -> Data.block_by_number(param, socket.assigns.network, false) end) - res - - :num -> - {query_time, res} = - :timer.tc(fn -> Data.block_by_number(param, socket.assigns.network, false) end) - - Logger.debug( - "[Block Detail] Fetched block #{param} in #{query_time} microseconds, query took #{time} microsecond, using :num" - ) + Logger.debug( + "[Block Detail] Fetched block #{param} in #{query_time} microseconds, query took #{time} microsecond, using :num" + ) - res - end + res end - - [ - gas_price: Utils.hex_wei_to_eth(block.gas_fee_in_wei), - execution_resources: block.execution_resources, - block: block, - view: "overview", - verification: "Pending", - block_age: Utils.get_block_age(block) - ] - else - [ - view: "loading" - ] end + assigns = [ + gas_price: Utils.hex_wei_to_eth(block.gas_fee_in_wei), + execution_resources: block.execution_resources, + block: block, + view: "overview", + verification: "Pending", + block_age: Utils.get_block_age(block), + tabs?: connected?(socket) + ] + {:ok, assign(socket, assigns)} end @@ -574,87 +568,6 @@ defmodule StarknetExplorerWeb.BlockDetailLive do """ end - def render_info(assigns = %{view: "loading"}) do - ~H""" -
-
Block Number
-
- Loading -
-
-
-
Block Hash
-
-
- Loading -
-
-
-
-
Block Status
-
- - Loading - -
-
-
-
State Root
-
-
- Loading -
-
-
-
-
Parent Hash
-
-
- Loading -
-
-
-
-
- Sequencer Address -
-
-
- Loading -
-
-
- <%= if Application.get_env(:starknet_explorer, :enable_gateway_data) do %> -
-
- Gas Price -
-
-
-
- Loading -
-
-
-
-
-
- Total execution resources -
-
-
- Loading -
-
-
- <% end %> - """ - end - def render_info(assigns = %{block: _block, view: "overview"}) do ~H"""