add identity_key params possibility to node-page

This commit is contained in:
Yana
2025-02-25 15:14:21 +02:00
parent 327ad7982e
commit 9c949988e2
2 changed files with 19 additions and 2 deletions
@@ -1,4 +1,4 @@
import { fetchNodeInfo } from "@/app/api";
import { fetchNodeIdByIdentityKey, fetchNodeInfo } from "@/app/api";
import { ContentLayout } from "@/components/contentLayout/ContentLayout";
import SectionHeading from "@/components/headings/SectionHeading";
import { BasicInfoCard } from "@/components/nymNodePageComponents/BasicInfoCard";
@@ -18,7 +18,16 @@ export default async function NymNode({
params: Promise<{ id: string }>;
}) {
try {
const id = Number((await params).id);
let id: string | number;
const paramsId = (await params).id;
// check if the params id is a node_id or identity_key
if (paramsId.length > 10) {
id = await fetchNodeIdByIdentityKey(paramsId);
} else {
id = Number(paramsId);
}
const observatoryNymNode = await fetchNodeInfo(id);
+8
View File
@@ -64,6 +64,14 @@ export const fetchNodeInfo = async (
return nodes?.find((node) => node.node_id === id);
};
export const fetchNodeIdByIdentityKey = async (
identity_key: string,
): Promise<number> => {
const nodes = await fetchObservatoryNodes();
const node = nodes?.find((node) => node.identity_key === identity_key);
return node?.node_id || 0;
};
export const fetchNodeDelegations = async (
id: number,
): Promise<NodeRewardDetails[]> => {