Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: explorer missing vars throw 500 #1676

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion explorer/lib/explorer_web/live/numbers.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Numbers do
def format_number(number) when is_nil(number) do
def format_number(number) when is_nil(number) or number == :empty do
nil
end

Expand Down
41 changes: 25 additions & 16 deletions explorer/lib/explorer_web/live/pages/home/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ defmodule ExplorerWeb.Home.Index do
require Logger
use ExplorerWeb, :live_view

defp set_empty_values(socket) do
Logger.info("Setting empty values")
socket |> assign(
verified_batches: :empty,
operators_registered: :empty,
latest_batches: :empty,
verified_proofs: :empty,
restaked_amount_eth: :empty,
restaked_amount_usd: :empty
)
end

@impl true
def handle_info(_, socket) do
verified_batches = Batches.get_amount_of_verified_batches()
Expand Down Expand Up @@ -62,44 +74,41 @@ defmodule ExplorerWeb.Home.Index do
)}
rescue
e in Mint.TransportError ->
Logger.error("Error: Mint.TransportError: #{inspect(e)}")
case e do
%Mint.TransportError{reason: :econnrefused} ->
{
:ok,
assign(socket,
verified_batches: :empty,
operators_registered: :empty,
latest_batches: :empty,
verified_proofs: :empty
)
set_empty_values(socket)
|> put_flash(:error, "Could not connect to the backend, please try again later.")
}

_ ->
"Other transport error: #{inspect(e)}" |> Logger.error()
{:ok, socket |> put_flash(:error, "Something went wrong, please try again later.")}
{
:ok,
set_empty_values(socket)
|> put_flash(:error, "Something went wrong, please try again later.")}
end

e in FunctionClauseError ->
Logger.error("Error: FunctionClauseError: #{inspect(e)}")
case e do
%FunctionClauseError{
module: ExplorerWeb.Home.Index
} ->
{
:ok,
assign(socket,
verified_batches: :empty,
operators_registered: :empty,
latest_batches: :empty,
verified_proofs: :empty
)
set_empty_values(socket)
|> put_flash(:error, "Something went wrong with the RPC, please try again later.")
}
end

e ->
Logger.error("Other error: #{inspect(e)}")
{:ok, socket |> put_flash(:error, "Something went wrong, please try again later.")}
Logger.error("Error: other error: #{inspect(e)}")
{
:ok,
set_empty_values(socket)
|> put_flash(:error, "Something went wrong, please try again later.")}
end

embed_templates("*")
Expand Down
26 changes: 11 additions & 15 deletions explorer/lib/explorer_web/live/pages/home/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,29 @@
>
<%= if @operators_registered != :empty do %>
<%= @operators_registered %>
<% else %>
0
<% end %>
</.card_link>
<.card_link
icon="hero-arrow-right-solid"
navigate={~p"/restake"}
title="Total Restaked"
subtitle={"(#{@restaked_amount_eth |> Helpers.format_number()} ETH)"}>
<%= if @restaked_amount_eth != :nil do %>
<%= @restaked_amount_usd |> Helpers.format_number() %> USD
<% else %>
0
<% end %>
icon="hero-arrow-right-solid"
navigate={~p"/restake"}
title="Total Restaked"
subtitle={
if @restaked_amount_eth |> Helpers.format_number() != nil do
"(#{@restaked_amount_eth |> Helpers.format_number()} ETH)"
end
}>
<%= if @restaked_amount_usd |> Helpers.format_number() != nil do %>
JuArce marked this conversation as resolved.
Show resolved Hide resolved
<%= @restaked_amount_usd |> Helpers.format_number() %> USD
<% end %>
</.card_link>
<.card title="verified batches">
<%= if @verified_batches != :empty do %>
<%= @verified_batches |> Helpers.format_number() %>
<% else %>
0
<% end %>
</.card>
<.card title="Verified Proofs" class="-mt-0.5 md:mt-0">
<%= if @verified_proofs != :empty do %>
<%= @verified_proofs |> Helpers.format_number() %>
<% else %>
0
<% end %>
</.card>
<.live_component module={ContractsComponent} id="contracts_card" class="sm:col-span-2" />
Expand Down