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

fix: periodic updates for batcher page #1666

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 0 deletions explorer/lib/explorer/periodically.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ defmodule Explorer.Periodically do
Task.start(&process_unverified_batches/0)
end

PubSub.broadcast(Explorer.PubSub, "update_views", :block_age)

{:noreply, %{state | batches_count: new_count}}
end

Expand Down
10 changes: 8 additions & 2 deletions explorer/lib/explorer_web/live/pages/batch/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ defmodule ExplorerWeb.Batch.Index do
batch
| fee_per_proof: EthConverter.wei_to_eth(fee_per_proof)
}
|> Map.put(:fee_per_proof_usd, fee_per_proof_usd)
|> Map.merge(%{
fee_per_proof_usd: fee_per_proof_usd,
status: batch |> Helpers.get_batch_status
})
end

{
Expand Down Expand Up @@ -61,7 +64,10 @@ defmodule ExplorerWeb.Batch.Index do
batch
| fee_per_proof: EthConverter.wei_to_eth(fee_per_proof)
}
|> Map.put(:fee_per_proof_usd, fee_per_proof_usd)
|> Map.merge(%{
fee_per_proof_usd: fee_per_proof_usd,
status: batch |> Helpers.get_batch_status
})

end

Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer_web/live/pages/batch/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<h3>
Status:
</h3>
<.dynamic_badge_for_batcher class="w-fit" status={Helpers.get_batch_status(@current_batch)} />
<.dynamic_badge_for_batcher class="w-fit" status={@current_batch.status} />
</div>
<div>
<h3>
Expand Down
2 changes: 2 additions & 0 deletions explorer/lib/explorer_web/live/pages/batches/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule ExplorerWeb.Batches.Index do
current_page = get_current_page(params)

batches = Batches.get_paginated_batches(%{page: current_page, page_size: @page_size})
|> Helpers.enrich_batches()

if connected?(socket), do: PubSub.subscribe(Explorer.PubSub, "update_views")

Expand All @@ -27,6 +28,7 @@ defmodule ExplorerWeb.Batches.Index do
current_page = socket.assigns.current_page

batches = Batches.get_paginated_batches(%{page: current_page, page_size: @page_size})
|> Helpers.enrich_batches()

{:noreply, assign(socket, batches: batches, last_page: Batches.get_last_page(@page_size))}
end
Expand Down
4 changes: 2 additions & 2 deletions explorer/lib/explorer_web/live/pages/batches/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
</.link>
</:col>
<:col :let={batch} label="Status">
<.dynamic_badge_for_batcher status={Helpers.get_batch_status(batch)} />
<.dynamic_badge_for_batcher status={batch.status} />
</:col>
<:col :let={batch} label="Age">
<span class="md:px-0" title={batch.submission_timestamp}>
<%= batch.submission_timestamp |> Helpers.parse_timeago() %>
<%= batch.age %>
</span>
</:col>
<:col :let={batch} label="Submission Block Number">
Expand Down
2 changes: 2 additions & 0 deletions explorer/lib/explorer_web/live/pages/home/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule ExplorerWeb.Home.Index do

latest_batches =
Batches.get_latest_batches(%{amount: 10})
|> Helpers.enrich_batches()

verified_proofs = Batches.get_amount_of_verified_proofs()

Expand All @@ -36,6 +37,7 @@ defmodule ExplorerWeb.Home.Index do

latest_batches =
Batches.get_latest_batches(%{amount: 10})
|> Helpers.enrich_batches()

verified_proofs = Batches.get_amount_of_verified_proofs()

Expand Down
14 changes: 7 additions & 7 deletions explorer/lib/explorer_web/live/pages/home/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
0
<% end %>
</.card_link>
<.card_link
icon="hero-arrow-right-solid"
navigate={~p"/restakes"}
title="Total Restaked"
<.card_link
icon="hero-arrow-right-solid"
navigate={~p"/restakes"}
title="Total Restaked"
subtitle={"(#{@restaked_amount_eth |> Helpers.format_number()} ETH)"}>
<%= if @restaked_amount_eth != :nil do %>
<%= @restaked_amount_usd |> Helpers.format_number() %> USD
Expand Down Expand Up @@ -59,18 +59,18 @@
</.link>
</:col>
<:col :let={latest_batch} label="Status">
<.dynamic_badge_for_batcher status={Helpers.get_batch_status(latest_batch)} />
<.dynamic_badge_for_batcher status={latest_batch.status} />
</:col>
<:col :let={latest_batch} label="Age">
<span class="md:px-0" title={latest_batch.submission_timestamp}>
<%= latest_batch.submission_timestamp |> Helpers.parse_timeago() %>
<%= latest_batch.age %>
</span>
</:col>
<:col :let={latest_batch} label="Submission Block Number">
<%= latest_batch.submission_block_number |> Helpers.format_number() %>
</:col>
<:footer>
<div class="flex justify-center py-3">
<div class="flex justify-center py-3">
<.link navigate={~p"/batches"} class="absolute hover:underline font-medium text-muted-foreground capitalize text-sm">
View All <.icon name="hero-arrow-top-right-on-square-solid" class="size-3.5 mb-1" />
</.link>
Expand Down
11 changes: 11 additions & 0 deletions explorer/lib/explorer_web/live/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ defmodule ExplorerWeb.Helpers do
true -> :pending
end
end

def enrich_batches(batches) do
batches
|> Enum.map(
fn batch -> batch
|> Map.merge(%{
age: batch.submission_timestamp |> parse_timeago(),
status: batch |> get_batch_status
})
end)
end
end

# Backend utils
Expand Down