Skip to content

Commit afc61b7

Browse files
glpecileuri-99
andauthored
feat(explorer): add operator version via tracker api (#879)
Co-authored-by: Urix <[email protected]>
1 parent 42cc5f5 commit afc61b7

File tree

19 files changed

+346
-120
lines changed

19 files changed

+346
-120
lines changed

docs/3_guides/6_setup_aligned.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ The `.env` file needs to contain the following variables:
668668
| `DB_HOST` | The host URL where the postgres database will be running. |
669669
| `ELIXIR_HOSTNAME` | The hostname of your running elixir. |
670670
| `DEBUG_ERRORS` | If you want to enable phoenix errors on your browser instead of a 500 page, set this to `true`. |
671+
| `TRACKER_API_URL` | The URL of the aligned version each operator is running. |
671672
672673
Then you can run the explorer with this env file config by entering the following command:
673674

explorer/.env.dev

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ ALIGNED_CONFIG_FILE="../contracts/script/output/devnet/alignedlayer_deployment_o
1717

1818
# Debug
1919
DEBUG_ERRORS=true
20+
21+
# Operator version tracker API
22+
TRACKER_API_URL=http://localhost:3030

explorer/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ ALIGNED_CONFIG_FILE="<aligned_config_file>"
1717

1818
# Debug
1919
DEBUG_ERRORS=<true|false>
20+
21+
# Tracker API
22+
TRACKER_API_URL=<tracker_api_url>

explorer/config/config.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import Config
99

1010
config :explorer,
11-
generators: [timestamp_type: :utc_datetime]
11+
generators: [timestamp_type: :utc_datetime],
12+
tracker_api_url: System.get_env("TRACKER_API_URL")
1213

1314
host = System.get_env("PHX_HOST") || "localhost"
1415

explorer/lib/abi/AlignedLayerServiceManager.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

explorer/lib/explorer/contract_managers/aligned_layer_service_manager.ex

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,14 @@ defmodule AlignedLayerServiceManager do
6060
|> Ethers.get_logs(fromBlock: fromBlock, toBlock: toBlock)
6161

6262
case events do
63-
{:ok, []} -> []
64-
{:ok, list} -> Enum.map(list, &extract_new_batch_event_info/1)
65-
{:error, reason} -> raise("Error fetching events: #{Map.get(reason, "message")}")
63+
{:ok, []} ->
64+
[]
65+
66+
{:ok, list} ->
67+
Enum.map(list, &extract_new_batch_event_info/1)
68+
69+
{:error, reason} ->
70+
raise("Error fetching events: #{Map.get(reason, "message")}")
6671
end
6772
end
6873

@@ -94,8 +99,9 @@ defmodule AlignedLayerServiceManager do
9499

95100
def is_batch_responded(merkle_root) do
96101
event =
97-
AlignedLayerServiceManager.EventFilters.batch_verified(Utils.string_to_bytes32(merkle_root))
98-
|> Ethers.get_logs(fromBlock: @first_block)
102+
Utils.string_to_bytes32(merkle_root)
103+
|> AlignedLayerServiceManager.EventFilters.batch_verified()
104+
|> Ethers.get_logs(fromBlock: @first_block)
99105

100106
case event do
101107
{:error, reason} -> {:error, reason}
@@ -189,7 +195,6 @@ defmodule AlignedLayerServiceManager do
189195
batch_merkle_root = event |> Map.get(:topics_raw) |> Enum.at(1)
190196
sender_address = event |> Map.get(:data) |> Enum.at(0)
191197

192-
193198
{:ok,
194199
%BatchVerifiedInfo{
195200
address: event |> Map.get(:address),
@@ -228,5 +233,4 @@ defmodule AlignedLayerServiceManager do
228233
raise("Error fetching restakeable strategies: #{error}")
229234
end
230235
end
231-
232236
end

explorer/lib/explorer/models/restakings.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ defmodule Restakings do
8585
query = from r in Restakings,
8686
join: s in Strategies, on: r.strategy_address == s.strategy_address,
8787
where: r.operator_id == ^operator_id,
88+
order_by: [desc: r.stake],
8889
select: %{
8990
restaking: r,
9091
strategy: %{

explorer/lib/explorer_web/components/assets_cta.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule AssetsCTAComponent do
1414
<.link navigate={~p"/operators"} class="flex flex-col justify-start gap-0.5 group">
1515
<div class="text-muted-foreground font-semibold flex gap-2 items-center">
1616
<h2>
17-
Total Active Operators
17+
Registered Active Operators
1818
</h2>
1919
<.right_arrow />
2020
</div>

explorer/lib/explorer_web/components/core_components.ex

Lines changed: 79 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -388,32 +388,64 @@ defmodule ExplorerWeb.CoreComponents do
388388
end
389389

390390
@doc """
391-
Renders a dynamic badge compoent.
391+
Renders a badge component.
392392
"""
393393
attr :class, :string, default: nil
394-
attr :status, :boolean, default: true
395-
attr :falsy_text, :string, default: "Pending"
396-
attr :truthy_text, :string, default: "Verified"
394+
attr :variant, :string, default: "accent"
397395
slot :inner_block, default: nil
398396

399-
def dynamic_badge(assigns) do
397+
def badge(assigns) do
400398
~H"""
401399
<span class={
402400
classes([
403-
"px-3 py-1 rounded-full",
404-
case @status do
405-
true -> "text-accent-foreground bg-accent group-hover:bg-primary/80"
406-
false -> "text-background bg-foreground group-hover:bg-foreground/80"
401+
"px-3 py-1 rounded-full font-semibold",
402+
case @variant do
403+
"accent" -> "text-accent-foreground bg-accent group-hover:bg-accent/80"
404+
"primary" -> "text-primary-foreground bg-primary group-hover:bg-primary/80"
405+
"secondary" -> "text-secondary-foreground bg-secondary group-hover:bg-secondary/80"
406+
"destructive" -> "text-destructive-foreground bg-destructive group-hover:bg-destructive/80"
407+
"foreground" -> "text-background bg-foreground group-hover:bg-foreground/80"
408+
"card" -> "text-card-foreground bg-card group-hover:bg-card/80"
409+
_ -> "text-accent-foreground bg-accent group-hover:bg-accent/80"
407410
end,
408411
@class
409412
])
410413
}>
414+
<%= render_slot(@inner_block) %>
415+
</span>
416+
"""
417+
end
418+
419+
@doc """
420+
Renders a dynamic badge compoent.
421+
"""
422+
attr :class, :string, default: nil
423+
attr :status, :boolean, default: true
424+
attr :falsy_text, :string, default: "Pending"
425+
attr :truthy_text, :string, default: "Verified"
426+
slot :inner_block, default: nil
427+
428+
def dynamic_badge(assigns) do
429+
~H"""
430+
<.badge
431+
variant={
432+
case @status do
433+
true -> "accent"
434+
false -> "foreground"
435+
end
436+
}
437+
class={
438+
classes([
439+
@class
440+
])
441+
}
442+
>
411443
<%= case @status do
412444
true -> @truthy_text
413445
false -> @falsy_text
414446
end %>
415447
<%= render_slot(@inner_block) %>
416-
</span>
448+
</.badge>
417449
"""
418450
end
419451

@@ -708,6 +740,43 @@ defmodule ExplorerWeb.CoreComponents do
708740
"""
709741
end
710742

743+
@doc """
744+
Renders an empty card background.
745+
746+
## Examples
747+
748+
<.empty_card_background text="No users found" />
749+
750+
"""
751+
attr :class, :string, default: nil
752+
attr :inner_text_class, :string, default: nil
753+
attr :text, :string, default: nil
754+
slot :inner_block
755+
756+
def empty_card_background(assigns) do
757+
~H"""
758+
<.card_background class={
759+
classes([
760+
"overflow-x-auto min-h-[38.45rem] flex flex-col items-center justify-center gap-2",
761+
@class
762+
])
763+
}>
764+
<p
765+
:if={@text != nil}
766+
class={
767+
classes([
768+
"text-lg text-muted-foreground",
769+
@inner_text_class
770+
])
771+
}
772+
>
773+
<%= @text %>
774+
</p>
775+
<%= render_slot(@inner_block) %>
776+
</.card_background>
777+
"""
778+
end
779+
711780
@doc """
712781
Renders a data list.
713782
@@ -735,30 +804,6 @@ defmodule ExplorerWeb.CoreComponents do
735804
"""
736805
end
737806

738-
@doc """
739-
Renders a back navigation link.
740-
741-
## Examples
742-
743-
<.back navigate={~p"/posts"}>Back to posts</.back>
744-
"""
745-
attr :navigate, :any, required: true
746-
slot :inner_block, required: true
747-
748-
def back(assigns) do
749-
~H"""
750-
<div class="mt-16">
751-
<.link
752-
navigate={@navigate}
753-
class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700"
754-
>
755-
<.icon name="hero-arrow-left-solid" class="h-3 w-3" />
756-
<%= render_slot(@inner_block) %>
757-
</.link>
758-
</div>
759-
"""
760-
end
761-
762807
@doc """
763808
Renders a [Heroicon](https://heroicons.com).
764809

explorer/lib/explorer_web/components/nav.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
defmodule NavComponent do
22
use ExplorerWeb, :live_component
33

4+
@impl true
5+
def mount(socket) do
6+
{:ok, assign(socket, latest_release: ReleasesHelper.get_latest_release())}
7+
end
8+
49
@impl true
510
def render(assigns) do
611
~H"""
@@ -46,6 +51,12 @@ defmodule NavComponent do
4651
GitHub
4752
</.link>
4853
<DarkMode.button />
54+
<.badge :if={@latest_release != nil} class="hidden md:inline">
55+
<%= @latest_release %>
56+
<.tooltip>
57+
Latest Aligned version
58+
</.tooltip>
59+
</.badge>
4960
<button
5061
class="md:hidden z-50"
5162
id="menu-toggle"
@@ -61,6 +72,9 @@ defmodule NavComponent do
6172
phx-click={toggle_menu()}
6273
>
6374
<div class="h-full flex flex-col gap-y-10 text-2xl justify-end items-center p-12">
75+
<.badge :if={@latest_release != nil}>
76+
<%= @latest_release %>
77+
</.badge>
6478
<.link
6579
class="text-foreground/80 hover:text-foreground font-semibold"
6680
navigate={~p"/batches"}

0 commit comments

Comments
 (0)