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
24 changes: 19 additions & 5 deletions packages/ui/src/components/ValidatorList/KeystoresDataGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { JSX } from "react";
import { DataGrid, GridAlignment, GridRowId } from "@mui/x-data-grid";
import { useEffect, useState } from "react";
import { blockExplorerUrls } from "../../params";
import { blockExplorerUrls, dashboardNetworks } from "../../params";
import {
MAINNET_ORACLE_URL,
TESTNET_ORACLE_URL,
Expand Down Expand Up @@ -61,6 +61,7 @@ export default function KeystoresDataGrid({
}): JSX.Element {
const [paginationModel, setPaginationModel] = useState({ page: 0, pageSize: 10 });
const blockExplorerUrl = blockExplorerUrls.get(network);
const hasDashboard = dashboardNetworks.has(network);

const [validatorsSubscriptionMap, setValidatorsSubscriptionMap] = useState<SmoothStatusByPubkey | null>(null);

Expand Down Expand Up @@ -475,10 +476,23 @@ export default function KeystoresDataGrid({
label={selectedRows.length ? `${selectedRows.length} selected` : `${rows.length} validators`}
/>
<Stack direction="row" spacing={0.5} useFlexGap flexWrap="wrap" alignItems="center">
<Tooltip title="Go to explorer dashboard for selected validators">
<IconButton aria-label="Open validator dashboard" disabled={!areRowsSelected} onClick={openDashboardTab}>
<LinkIcon />
</IconButton>
<Tooltip
title={
hasDashboard
? "Go to explorer dashboard for selected validators"
: "This network's explorer has no multi-validator dashboard; use each validator's explorer link"
}
>
{/* A span keeps the tooltip working while the button is disabled. */}
<span>
<IconButton
aria-label="Open validator dashboard"
disabled={!areRowsSelected || !hasDashboard}
onClick={openDashboardTab}
>
<LinkIcon />
</IconButton>
</span>
</Tooltip>

<Tooltip title="Edit validators fee recipient">
Expand Down
8 changes: 7 additions & 1 deletion packages/ui/src/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import { Network } from "@stakingbrain/common";

export const blockExplorerUrls = new Map<string, string>([
["mainnet", "https://beaconcha.in"],
["gnosis", "https://gnosischa.in"],
["gnosis", "https://beaconchain.gnosischain.com"],
["lukso", "https://explorer.consensus.mainnet.lukso.network"],
["hoodi", "https://hoodi.beaconcha.in"]
]);

/**
* Explorers that open a dashboard for several validators from `/dashboard?validators=`. The Gnosis
* explorer redirects that URL to an empty dashboard, and Lukso's (Dora) has no dashboard page.
*/
export const dashboardNetworks = new Set(["mainnet", "hoodi"]);

export interface AppParams {
network: string;
signerUrl: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/utils/buildValidatorSummaryURL.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { blockExplorerUrls } from "../params";
import { blockExplorerUrls, dashboardNetworks } from "../params";

export default function buildValidatorSummaryURL({
validatorIndexes,
Expand All @@ -12,6 +12,7 @@ export default function buildValidatorSummaryURL({
throw new Error(`Invalid network: ${network}`);
}

if (!dashboardNetworks.has(network)) return "";
if (validatorIndexes.length === 0 || validatorIndexes.some((index) => !/^\d+$/.test(index))) return "";

return baseUrl + "/dashboard?validators=" + validatorIndexes.join(",");
Expand Down
16 changes: 13 additions & 3 deletions packages/ui/test/testBuildSummaryUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { expect } from "chai";
import buildValidatorSummaryURL from "../src/utils/buildValidatorSummaryURL.js";
import { blockExplorerUrls } from "../src/params.js";

describe("Validator dashboard URLs", () => {
for (const [network, baseUrl] of [
["mainnet", "https://beaconcha.in"],
["hoodi", "https://hoodi.beaconcha.in"],
["gnosis", "https://gnosischa.in"],
["lukso", "https://explorer.consensus.mainnet.lukso.network"]
["hoodi", "https://hoodi.beaconcha.in"]
]) {
it(`builds a ${network} link from local indexes, including index zero`, () => {
expect(buildValidatorSummaryURL({ validatorIndexes: ["0", "42", "123"], network })).to.equal(
Expand All @@ -15,6 +14,17 @@ describe("Validator dashboard URLs", () => {
});
}

// Their explorers would open an empty dashboard (Gnosis) or a missing page (Lukso).
for (const network of ["gnosis", "lukso"]) {
it(`builds no dashboard link for ${network}, whose explorer has no multi-validator dashboard`, () => {
expect(buildValidatorSummaryURL({ validatorIndexes: ["0", "42"], network })).to.equal("");
});
}

it("points Gnosis explorer links at a live explorer", () => {
expect(blockExplorerUrls.get("gnosis")).to.equal("https://beaconchain.gnosischain.com");
});

it("includes selections larger than the former API batch limit", () => {
const validatorIndexes = Array.from({ length: 103 }, (_, index) => index.toString());
expect(buildValidatorSummaryURL({ validatorIndexes, network: "mainnet" })).to.equal(
Expand Down
Loading