Skip to content

Commit f473f6d

Browse files
Oppenuri-99
andauthored
fix: periodic updates for batcher page (#1666)
Co-authored-by: Urix <[email protected]>
1 parent db4247c commit f473f6d

File tree

8 files changed

+39
-14
lines changed

8 files changed

+39
-14
lines changed

explorer/lib/explorer/periodically.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ defmodule Explorer.Periodically do
5050
Task.start(&process_unverified_batches/0)
5151
end
5252

53+
PubSub.broadcast(Explorer.PubSub, "update_views", :block_age)
54+
5355
{:noreply, %{state | batches_count: new_count}}
5456
end
5557

explorer/lib/explorer_web/live/pages/batch/index.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ defmodule ExplorerWeb.Batch.Index do
1818
batch
1919
| fee_per_proof: EthConverter.wei_to_eth(fee_per_proof)
2020
}
21-
|> Map.put(:fee_per_proof_usd, fee_per_proof_usd)
21+
|> Map.merge(%{
22+
fee_per_proof_usd: fee_per_proof_usd,
23+
status: batch |> Helpers.get_batch_status
24+
})
2225
end
2326

2427
{
@@ -61,7 +64,10 @@ defmodule ExplorerWeb.Batch.Index do
6164
batch
6265
| fee_per_proof: EthConverter.wei_to_eth(fee_per_proof)
6366
}
64-
|> Map.put(:fee_per_proof_usd, fee_per_proof_usd)
67+
|> Map.merge(%{
68+
fee_per_proof_usd: fee_per_proof_usd,
69+
status: batch |> Helpers.get_batch_status
70+
})
6571

6672
end
6773

explorer/lib/explorer_web/live/pages/batch/index.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<h3>
2626
Status:
2727
</h3>
28-
<.dynamic_badge_for_batcher class="w-fit" status={Helpers.get_batch_status(@current_batch)} />
28+
<.dynamic_badge_for_batcher class="w-fit" status={@current_batch.status} />
2929
</div>
3030
<div>
3131
<h3>

explorer/lib/explorer_web/live/pages/batches/index.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ defmodule ExplorerWeb.Batches.Index do
1010
current_page = get_current_page(params)
1111

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

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

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

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

3133
{:noreply, assign(socket, batches: batches, last_page: Batches.get_last_page(@page_size))}
3234
end

explorer/lib/explorer_web/live/pages/batches/index.html.heex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
</.link>
1515
</:col>
1616
<:col :let={batch} label="Status">
17-
<.dynamic_badge_for_batcher status={Helpers.get_batch_status(batch)} />
17+
<.dynamic_badge_for_batcher status={batch.status} />
1818
</:col>
1919
<:col :let={batch} label="Age">
2020
<span class="md:px-0" title={batch.submission_timestamp}>
21-
<%= batch.submission_timestamp |> Helpers.parse_timeago() %>
21+
<%= batch.age %>
2222
</span>
2323
</:col>
2424
<:col :let={batch} label="Submission Block Number">

explorer/lib/explorer_web/live/pages/home/index.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ defmodule ExplorerWeb.Home.Index do
5555

5656
operators_registered = Operators.get_amount_of_operators()
5757

58-
latest_batches = Batches.get_latest_batches(%{amount: 5, order_by: :desc})
58+
latest_batches =
59+
Batches.get_latest_batches(%{amount: 10, order_by: :desc})
60+
|> Helpers.enrich_batches()
5961

6062
verified_proofs = Batches.get_amount_of_verified_proofs()
6163

@@ -81,7 +83,9 @@ defmodule ExplorerWeb.Home.Index do
8183

8284
operators_registered = Operators.get_amount_of_operators()
8385

84-
latest_batches = Batches.get_latest_batches(%{amount: 10, order_by: :desc})
86+
latest_batches =
87+
Batches.get_latest_batches(%{amount: 10, order_by: :desc})
88+
|> Helpers.enrich_batches()
8589

8690
verified_proofs = Batches.get_amount_of_verified_proofs()
8791

explorer/lib/explorer_web/live/pages/home/index.html.heex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
<%= @operators_registered %>
1313
<% end %>
1414
</.card_link>
15-
<.card_link
16-
icon="hero-arrow-right-solid"
17-
navigate={~p"/restake"}
18-
title="Total Restaked"
15+
<.card_link
16+
icon="hero-arrow-right-solid"
17+
navigate={~p"/restakes"}
18+
title="Total Restaked"
1919
subtitle={
2020
if @restaked_amount_eth |> Helpers.format_number() != nil do
2121
"(#{@restaked_amount_eth |> Helpers.format_number()} ETH)"
@@ -64,18 +64,18 @@
6464
</.link>
6565
</:col>
6666
<:col :let={latest_batch} label="Status">
67-
<.dynamic_badge_for_batcher status={Helpers.get_batch_status(latest_batch)} />
67+
<.dynamic_badge_for_batcher status={latest_batch.status} />
6868
</:col>
6969
<:col :let={latest_batch} label="Age">
7070
<span class="md:px-0" title={latest_batch.submission_timestamp}>
71-
<%= latest_batch.submission_timestamp |> Helpers.parse_timeago() %>
71+
<%= latest_batch.age %>
7272
</span>
7373
</:col>
7474
<:col :let={latest_batch} label="Submission Block Number">
7575
<%= latest_batch.submission_block_number |> Helpers.format_number() %>
7676
</:col>
7777
<:footer>
78-
<div class="flex justify-center py-3">
78+
<div class="flex justify-center py-3">
7979
<.link navigate={~p"/batches"} class="absolute hover:underline font-medium text-muted-foreground capitalize text-sm">
8080
View All <.icon name="hero-arrow-top-right-on-square-solid" class="size-3.5 mb-1" />
8181
</.link>

explorer/lib/explorer_web/live/utils.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ defmodule ExplorerWeb.Helpers do
154154
true -> :pending
155155
end
156156
end
157+
158+
def enrich_batches(batches) do
159+
batches
160+
|> Enum.map(
161+
fn batch -> batch
162+
|> Map.merge(%{
163+
age: batch.submission_timestamp |> parse_timeago(),
164+
status: batch |> get_batch_status
165+
})
166+
end)
167+
end
157168
end
158169

159170
# Backend utils

0 commit comments

Comments
 (0)