Skip to content
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: 2 additions & 0 deletions apps/api/src/routes/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export async function specRoutes(app: FastifyInstance) {
delegation: p.delegate_total?.amount ?? "0",
delegateCommission: p.delegate_commission,
geolocation: p.geolocation,
addons: p.addons,
extensions: p.extensions,
cuSum30d: relay?.cu ?? null,
relaySum30d: relay?.relays ?? null,
health: healthMap.get(p.address) ?? null,
Expand Down
321 changes: 260 additions & 61 deletions apps/web/src/app/chain/[specid]/page.tsx

Large diffs are not rendered by default.

66 changes: 63 additions & 3 deletions apps/web/src/app/chains/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { useMemo, useState } from "react";
import Link from "next/link";
import {
useReactTable,
getCoreRowModel,
Expand All @@ -14,6 +15,7 @@ import { useApi } from "@/hooks/use-api";
import { Loading } from "@/components/data/Loading";
import { ChainLink } from "@/components/data/ChainLink";
import { formatNumberKMB } from "@/lib/format";
import { getChainIcon } from "@/lib/chain-icons";

interface Spec { specId: string; name: string; providerCount: number; relays30d: string; cu30d: string; }

Expand Down Expand Up @@ -55,6 +57,26 @@ const columns: ColumnDef<Spec, unknown>[] = [
},
];

function ChainIconImg({ chainId }: { chainId: string }) {
const [failed, setFailed] = useState(false);
if (failed) {
return (
<span className="w-9 h-9 rounded-md shrink-0 bg-muted flex items-center justify-center text-sm font-medium text-muted-foreground">
{chainId.charAt(0).toUpperCase()}
</span>
);
}
return (
<img
src={getChainIcon(chainId)}
alt=""
className="w-9 h-9 rounded-md shrink-0"
loading="lazy"
onError={() => setFailed(true)}
/>
);
}

export default function ChainsPage() {
const { data: specsResp, isLoading, error } = useApi<{ data: Spec[] }>("/specs");
const specs = useMemo(() => specsResp?.data ?? [], [specsResp]);
Expand All @@ -63,6 +85,16 @@ export default function ChainsPage() {
{ id: "relays30d", desc: true },
]);

// Mobile: pre-sorted by relays (30d) desc
const mobileList = useMemo(
() => [...specs].sort((a, b) => {
const av = toBigInt(a.relays30d);
const bv = toBigInt(b.relays30d);
return av > bv ? -1 : av < bv ? 1 : 0;
}),
[specs],
);

const table = useReactTable({
data: specs,
columns,
Expand All @@ -77,13 +109,41 @@ export default function ChainsPage() {

return (
<div className="space-y-6">
<div className="rounded-xl border border-border bg-card shadow">
<div className="p-6 border-b border-border">
<div className="rounded-xl border border-border bg-card shadow">
<div className="p-4 md:p-6 border-b border-border">
<h2 className="text-lg font-semibold">
Active Chains ({specs.length})
</h2>
</div>
<div className="p-4">

{/* Mobile: compact card list */}
<ul className="md:hidden divide-y divide-border/60">
{mobileList.map((s) => {
const hasFullName = s.name && s.name !== s.specId;
return (
<li key={s.specId}>
<Link href={`/chain/${s.specId}`} className="flex items-center gap-3 px-4 py-3 active:bg-muted/60 transition-colors">
<ChainIconImg chainId={s.specId} />
<div className="min-w-0 flex-1">
<div className="text-sm font-medium text-accent truncate">{hasFullName ? s.name : s.specId}</div>
{hasFullName && <div className="text-[11px] text-muted-foreground truncate">{s.specId}</div>}
<div className="text-[11px] text-muted-foreground mt-0.5">
{s.providerCount} providers
{s.cu30d && ` · ${formatNumberKMB(s.cu30d)} CU (30d)`}
</div>
</div>
<div className="text-sm font-medium shrink-0 text-right">
{formatNumberKMB(s.relays30d)}
<div className="text-[11px] text-muted-foreground font-normal">relays (30d)</div>
</div>
</Link>
</li>
);
})}
</ul>

{/* Desktop: table */}
<div className="hidden md:block p-4">
<div className="overflow-x-auto rounded-lg border border-border">
<table className="w-full text-sm">
<thead>
Expand Down
128 changes: 125 additions & 3 deletions apps/web/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useState, useMemo, useEffect } from "react";
import dynamic from "next/dynamic";
import Link from "next/link";
import { useApi } from "@/hooks/use-api";
import { useChainNames } from "@/hooks/use-chain-names";
import { getChainIcon } from "@/lib/chain-icons";
import { Loading } from "@/components/data/Loading";
import { StatCard } from "@/components/data/StatCard";

Expand Down Expand Up @@ -125,6 +127,7 @@ export default function DashboardPage() {

const providers = useMemo(() => providersResp?.data?.slice(0, 10) ?? [], [providersResp]);
const chains = useMemo(() => topChains?.data?.slice(0, 10) ?? [], [topChains]);
const { getName } = useChainNames();

const providerCols: ColumnDef<Provider, unknown>[] = useMemo(() => [
{
Expand Down Expand Up @@ -167,25 +170,62 @@ export default function DashboardPage() {
return (
<>
{/* Stat Cards */}
<div className="grid gap-4 grid-cols-1 md:grid-cols-2 md:gap-8 xl:grid-cols-5">
<div className="grid gap-4 grid-cols-1 md:grid-cols-2 md:gap-8 xl:grid-cols-6">
{/* Mobile: consolidated Relays (total + 30d) */}
<StatCard
className="md:hidden"
label="Relays"
icon={<Activity className="h-4 w-4 text-muted-foreground" />}
value={
<div>
<div>{formatNumberKMB(stats?.totalRelays ?? 0)}</div>
<div className="text-xs text-muted-foreground font-normal mt-1">{formatNumberKMB(stats?.relays30d ?? 0)} in 30d</div>
</div>
}
/>
{/* Mobile: consolidated CU (total + 30d) */}
<StatCard
className="md:hidden"
label="CU"
icon={<ArrowUpNarrowWide className="h-4 w-4 text-muted-foreground" />}
value={
<div>
<div>{formatNumberKMB(stats?.totalCu ?? 0)}</div>
<div className="text-xs text-muted-foreground font-normal mt-1">{formatNumberKMB(stats?.cu30d ?? 0)} in 30d</div>
</div>
}
/>

{/* Desktop: split totals + 30d */}
<StatCard
className="hidden md:block"
label="Total Relays"
value={formatNumberKMB(stats?.totalRelays ?? 0)}
fullValue={formatNumber(stats?.totalRelays ?? 0)}
icon={<Activity className="h-4 w-4 text-muted-foreground" />}
/>
<StatCard
className="hidden md:block"
label="Total CU"
value={formatNumberKMB(stats?.totalCu ?? 0)}
fullValue={formatNumber(stats?.totalCu ?? 0)}
icon={<ArrowUpNarrowWide className="h-4 w-4 text-muted-foreground" />}
/>
<StatCard
className="hidden md:block"
label="Relays (30 days)"
value={formatNumberKMB(stats?.relays30d ?? 0)}
fullValue={formatNumber(stats?.relays30d ?? 0)}
icon={<CalendarArrowUp className="h-4 w-4 text-muted-foreground" />}
/>
<StatCard
className="hidden md:block"
label="CU (30 days)"
value={formatNumberKMB(stats?.cu30d ?? 0)}
fullValue={formatNumber(stats?.cu30d ?? 0)}
icon={<ArrowUpNarrowWide className="h-4 w-4 text-muted-foreground" />}
/>

<StatCard
label="Total Stake"
value={`${formatLavaKMB(stats?.totalStake ?? "0")} LAVA`}
Expand Down Expand Up @@ -223,7 +263,31 @@ export default function DashboardPage() {
</Button>
</CardHeader>
<CardContent>
<SortableTable data={providers} columns={providerCols} defaultSort={[{ id: "totalStake", desc: true }]} />
{/* Mobile: compact card list */}
<ul className="md:hidden divide-y divide-border/60">
{providers.slice(0, 5).map((p) => {
const label = p.moniker || `${p.provider.slice(0, 12)}...`;
return (
<li key={p.provider}>
<Link href={`/provider/${p.provider}`} className="flex items-center gap-3 py-3 -mx-2 px-2 rounded-lg hover:bg-muted/40 active:bg-muted/60 transition-colors">
<ProviderAvatarImg address={p.provider} moniker={p.moniker} identity={p.identity} />
<div className="min-w-0 flex-1">
<div className="text-sm font-medium text-accent truncate">{label}</div>
{p.moniker && <div className="text-[11px] text-muted-foreground font-mono truncate">{p.provider}</div>}
</div>
<div className="flex flex-col items-end gap-0.5 shrink-0">
<span className="text-sm font-medium"><LavaAmount amount={p.totalStake} /></span>
<span className="text-[11px] text-muted-foreground">{p.activeServices} services</span>
</div>
</Link>
</li>
);
})}
</ul>
{/* Desktop: sortable table */}
<div className="hidden md:block">
<SortableTable data={providers} columns={providerCols} defaultSort={[{ id: "totalStake", desc: true }]} />
</div>
</CardContent>
</Card>

Expand All @@ -242,10 +306,68 @@ export default function DashboardPage() {
</Button>
</CardHeader>
<CardContent>
<SortableTable data={chains} columns={chainCols} defaultSort={[{ id: "totalRelays", desc: true }]} />
{/* Mobile: compact card list */}
<ul className="md:hidden divide-y divide-border/60">
{chains.slice(0, 5).map((c) => {
const fullName = getName(c.specId);
const hasFullName = fullName && fullName !== c.specId;
return (
<li key={c.specId}>
<Link href={`/chain/${c.specId}`} className="flex items-center gap-3 py-3 -mx-2 px-2 rounded-lg hover:bg-muted/40 active:bg-muted/60 transition-colors">
<ChainIconImg chainId={c.specId} />
<div className="min-w-0 flex-1">
<div className="text-sm font-medium text-accent truncate">{hasFullName ? fullName : c.specId}</div>
{hasFullName && <div className="text-[11px] text-muted-foreground truncate">{c.specId}</div>}
</div>
<div className="flex flex-col items-end gap-0.5 shrink-0">
<span className="text-sm font-medium">{formatNumberKMB(c.totalRelays)} relays</span>
<span className="text-[11px] text-muted-foreground">{formatNumberKMB(c.totalCu)} CU</span>
</div>
</Link>
</li>
);
})}
</ul>
{/* Desktop: sortable table */}
<div className="hidden md:block">
<SortableTable data={chains} columns={chainCols} defaultSort={[{ id: "totalRelays", desc: true }]} />
</div>
</CardContent>
</Card>
</div>
</>
);
}

function ProviderAvatarImg({ address, moniker, identity }: { address: string; moniker?: string; identity?: string }) {
const avatarUrl = identity ? `/providers/${address}/avatar?identity=${identity}` : null;
const { data: avatarResp } = useApi<{ url: string | null }>(avatarUrl);
if (avatarResp?.url) {
return <img src={avatarResp.url} alt="" className="w-8 h-8 rounded-full shrink-0" loading="lazy" />;
}
return (
<span className="w-8 h-8 rounded-full shrink-0 bg-muted flex items-center justify-center text-sm font-medium text-muted-foreground">
{(moniker || address).charAt(0).toUpperCase()}
</span>
);
}

function ChainIconImg({ chainId }: { chainId: string }) {
const [failed, setFailed] = useState(false);
if (failed) {
return (
<span className="w-8 h-8 rounded-md shrink-0 bg-muted flex items-center justify-center text-sm font-medium text-muted-foreground">
{chainId.charAt(0).toUpperCase()}
</span>
);
}
return (
<img
src={getChainIcon(chainId)}
alt=""
className="w-8 h-8 rounded-md shrink-0"
loading="lazy"
onError={() => setFailed(true)}
/>
);
}
Loading
Loading