Skip to content
This repository was archived by the owner on Jul 5, 2026. It is now read-only.
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
5 changes: 5 additions & 0 deletions src/components/metagraphed/nav-mega-menu-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export const MEGA_PANELS: MegaPanel[] = [
blurb: "Recent blocks indexed directly from the chain.",
apiPath: "/api/v1/blocks",
browse: [
{
to: "/explorer",
label: "Chain explorer",
hint: "Network at a glance — activity, fees, top accounts",
},
{ to: "/blocks", label: "Recent blocks", hint: "Newest first" },
{ to: "/blocks", search: { limit: "100" }, label: "100 per page" },
{ to: "/extrinsics", label: "Extrinsics", hint: "Transactions, newest first" },
Expand Down
111 changes: 111 additions & 0 deletions src/lib/metagraphed/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import type {
AccountRegistration,
AccountSummary,
Block,
ChainActivity,
ChainCalls,
ChainFees,
ChainSigners,
Extrinsic,
ExtrinsicCallArg,
Transfer,
Expand Down Expand Up @@ -1363,6 +1367,113 @@ export const accountTransfersQuery = (ss58: string, params?: QueryParams) =>
staleTime: STALE_SHORT,
});

// ---- Chain analytics dashboard (#266, epic #1986) -------------------------
// Display-only views over the live /api/v1/chain/* aggregates. Each guards only
// the array containers + the window stamp; the row shapes are our own backend's.

type ChainWindow = "7d" | "30d";

export const chainActivityQuery = (window: ChainWindow = "7d") =>
queryOptions({
queryKey: k("chain-activity", window),
queryFn: async ({ signal }) => {
const res = await apiFetch<unknown>("/api/v1/chain/activity", {
params: { window },
signal,
});
const d = isRecord(res.data) ? res.data : {};
return {
data: {
schema_version: 1,
window,
observed_at: firstString(d.observed_at) ?? null,
day_count: firstFiniteNumber(d.day_count) ?? 0,
days: Array.isArray(d.days) ? (d.days as ChainActivity["days"]) : [],
} as ChainActivity,
meta: res.meta,
url: res.url,
} as ApiResult<ChainActivity>;
},
staleTime: STALE_SHORT,
});

export const chainCallsQuery = (window: ChainWindow = "7d") =>
queryOptions({
queryKey: k("chain-calls", window),
queryFn: async ({ signal }) => {
const res = await apiFetch<unknown>("/api/v1/chain/calls", {
params: { window, limit: 12 },
signal,
});
const d = isRecord(res.data) ? res.data : {};
return {
data: {
schema_version: 1,
window,
group_by: firstString(d.group_by) ?? "module",
observed_at: firstString(d.observed_at) ?? null,
total_extrinsics: firstFiniteNumber(d.total_extrinsics) ?? 0,
call_count: firstFiniteNumber(d.call_count) ?? 0,
calls: Array.isArray(d.calls) ? (d.calls as ChainCalls["calls"]) : [],
} as ChainCalls,
meta: res.meta,
url: res.url,
} as ApiResult<ChainCalls>;
},
staleTime: STALE_SHORT,
});

export const chainSignersQuery = (window: ChainWindow = "7d") =>
queryOptions({
queryKey: k("chain-signers", window),
queryFn: async ({ signal }) => {
const res = await apiFetch<unknown>("/api/v1/chain/signers", {
params: { window, limit: 20 },
signal,
});
const d = isRecord(res.data) ? res.data : {};
return {
data: {
schema_version: 1,
window,
observed_at: firstString(d.observed_at) ?? null,
signer_count: firstFiniteNumber(d.signer_count) ?? 0,
signers: Array.isArray(d.signers) ? (d.signers as ChainSigners["signers"]) : [],
} as ChainSigners,
meta: res.meta,
url: res.url,
} as ApiResult<ChainSigners>;
},
staleTime: STALE_SHORT,
});

export const chainFeesQuery = (window: ChainWindow = "7d") =>
queryOptions({
queryKey: k("chain-fees", window),
queryFn: async ({ signal }) => {
const res = await apiFetch<unknown>("/api/v1/chain/fees", {
params: { window, limit: 12 },
signal,
});
const d = isRecord(res.data) ? res.data : {};
return {
data: {
schema_version: 1,
window,
observed_at: firstString(d.observed_at) ?? null,
day_count: firstFiniteNumber(d.day_count) ?? 0,
daily: Array.isArray(d.daily) ? (d.daily as ChainFees["daily"]) : [],
top_fee_payers: Array.isArray(d.top_fee_payers)
? (d.top_fee_payers as ChainFees["top_fee_payers"])
: [],
} as ChainFees,
meta: res.meta,
url: res.url,
} as ApiResult<ChainFees>;
},
staleTime: STALE_SHORT,
});

const READINESS_COMPONENT_KEYS = [
"has_callable_api",
"callable_now",
Expand Down
70 changes: 70 additions & 0 deletions src/lib/metagraphed/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,3 +1082,73 @@ export const __contractAssertions = {
surfaceWireHasAuthority: true as _SurfaceWireHasAuthority,
healthSurfaceStatusIsHealthStatus: true as _HealthSurfaceStatusIsHealthStatus,
} satisfies Record<string, true>;

// ---- Chain analytics dashboard (epic #1986) -------------------------------

export interface ChainActivityDay {
day: string;
block_count: number;
extrinsic_count: number;
event_count: number;
successful_extrinsics: number;
success_rate: number | null;
unique_signers: number;
}
export interface ChainActivity {
schema_version: number;
window: string;
observed_at: string | null;
day_count: number;
days: ChainActivityDay[];
}
export interface ChainCallEntry {
call_module: string;
call_function: string | null;
count: number;
share: number | null;
}
export interface ChainCalls {
schema_version: number;
window: string;
group_by: string;
observed_at: string | null;
total_extrinsics: number;
call_count: number;
calls: ChainCallEntry[];
}
export interface ChainSignerEntry {
signer: string;
tx_count: number;
total_fee_tao: number;
total_tip_tao: number;
last_tx_block: number | null;
}
export interface ChainSigners {
schema_version: number;
window: string;
observed_at: string | null;
signer_count: number;
signers: ChainSignerEntry[];
}
export interface ChainFeeDay {
day: string;
extrinsic_count: number;
total_fee_tao: number;
avg_fee_tao: number | null;
total_tip_tao: number;
avg_tip_tao: number | null;
}
export interface ChainFeePayer {
signer: string;
total_fee_tao: number;
total_tip_tao: number;
extrinsic_count: number;
}
export interface ChainFees {
schema_version: number;
window: string;
observed_at: string | null;
day_count: number;
daily: ChainFeeDay[];
top_fee_payers: ChainFeePayer[];
}
31 changes: 21 additions & 10 deletions src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Route as StatusRouteImport } from './routes/status'
import { Route as SchemasRouteImport } from './routes/schemas'
import { Route as HealthRouteImport } from './routes/health'
import { Route as GapsRouteImport } from './routes/gaps'
import { Route as ExplorerRouteImport } from './routes/explorer'
import { Route as EndpointsRouteImport } from './routes/endpoints'
import { Route as AgentsRouteImport } from './routes/agents'
import { Route as AboutRouteImport } from './routes/about'
Expand Down Expand Up @@ -54,6 +55,11 @@ const GapsRoute = GapsRouteImport.update({
path: '/gaps',
getParentRoute: () => rootRouteImport,
} as any)
const ExplorerRoute = ExplorerRouteImport.update({
id: '/explorer',
path: '/explorer',
getParentRoute: () => rootRouteImport,
} as any)
const EndpointsRoute = EndpointsRouteImport.update({
id: '/endpoints',
path: '/endpoints',
Expand Down Expand Up @@ -130,6 +136,7 @@ export interface FileRoutesByFullPath {
'/about': typeof AboutRoute
'/agents': typeof AgentsRoute
'/endpoints': typeof EndpointsRoute
'/explorer': typeof ExplorerRoute
'/gaps': typeof GapsRoute
'/health': typeof HealthRoute
'/schemas': typeof SchemasRoute
Expand All @@ -151,6 +158,7 @@ export interface FileRoutesByTo {
'/about': typeof AboutRoute
'/agents': typeof AgentsRoute
'/endpoints': typeof EndpointsRoute
'/explorer': typeof ExplorerRoute
'/gaps': typeof GapsRoute
'/health': typeof HealthRoute
'/schemas': typeof SchemasRoute
Expand All @@ -173,6 +181,7 @@ export interface FileRoutesById {
'/about': typeof AboutRoute
'/agents': typeof AgentsRoute
'/endpoints': typeof EndpointsRoute
'/explorer': typeof ExplorerRoute
'/gaps': typeof GapsRoute
'/health': typeof HealthRoute
'/schemas': typeof SchemasRoute
Expand All @@ -196,6 +205,7 @@ export interface FileRouteTypes {
| '/about'
| '/agents'
| '/endpoints'
| '/explorer'
| '/gaps'
| '/health'
| '/schemas'
Expand All @@ -217,6 +227,7 @@ export interface FileRouteTypes {
| '/about'
| '/agents'
| '/endpoints'
| '/explorer'
| '/gaps'
| '/health'
| '/schemas'
Expand All @@ -238,6 +249,7 @@ export interface FileRouteTypes {
| '/about'
| '/agents'
| '/endpoints'
| '/explorer'
| '/gaps'
| '/health'
| '/schemas'
Expand All @@ -260,6 +272,7 @@ export interface RootRouteChildren {
AboutRoute: typeof AboutRoute
AgentsRoute: typeof AgentsRoute
EndpointsRoute: typeof EndpointsRoute
ExplorerRoute: typeof ExplorerRoute
GapsRoute: typeof GapsRoute
HealthRoute: typeof HealthRoute
SchemasRoute: typeof SchemasRoute
Expand Down Expand Up @@ -314,6 +327,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof GapsRouteImport
parentRoute: typeof rootRouteImport
}
'/explorer': {
id: '/explorer'
path: '/explorer'
fullPath: '/explorer'
preLoaderRoute: typeof ExplorerRouteImport
parentRoute: typeof rootRouteImport
}
'/endpoints': {
id: '/endpoints'
path: '/endpoints'
Expand Down Expand Up @@ -420,6 +440,7 @@ const rootRouteChildren: RootRouteChildren = {
AboutRoute: AboutRoute,
AgentsRoute: AgentsRoute,
EndpointsRoute: EndpointsRoute,
ExplorerRoute: ExplorerRoute,
GapsRoute: GapsRoute,
HealthRoute: HealthRoute,
SchemasRoute: SchemasRoute,
Expand All @@ -439,13 +460,3 @@ const rootRouteChildren: RootRouteChildren = {
export const routeTree = rootRouteImport
._addFileChildren(rootRouteChildren)
._addFileTypes<FileRouteTypes>()

import type { getRouter } from './router.tsx'
import type { startInstance } from './start.ts'
declare module '@tanstack/react-start' {
interface Register {
ssr: true
router: Awaited<ReturnType<typeof getRouter>>
config: Awaited<ReturnType<typeof startInstance.getOptions>>
}
}
Loading
Loading