diff --git a/apps/staking/app/stake/node/[nodeId]/BlockExplorerLink.tsx b/apps/staking/app/stake/node/[nodeId]/BlockExplorerLink.tsx new file mode 100644 index 00000000..aa265d19 --- /dev/null +++ b/apps/staking/app/stake/node/[nodeId]/BlockExplorerLink.tsx @@ -0,0 +1,42 @@ +'use client'; + +import { OpenNode } from '@session/sent-staking-js/client'; +import { LoadingText } from '@session/ui/components/loading-text'; +import { LinkOutIcon } from '@session/ui/icons/LinkOutIcon'; +import { useTranslations } from 'next-intl'; +import Link from 'next/link'; +import { useEffect, useMemo, useState } from 'react'; + +export const BlockExplorerLink = ({ nodeId }: { nodeId: string }) => { + const [loading, setLoading] = useState(true); + const [nodes, setNodes] = useState>([]); + const dictionary = useTranslations('actionModules.node'); + + useEffect(() => { + fetch('/api/sent/nodes/open') + .then((res) => res.json()) + .then((data) => setNodes(data.nodes)) + .catch(console.error) + .finally(() => setLoading(false)); + }, []); + + const node = useMemo(() => { + /* if (showMockNodes) { + return generateOpenNodes({ userAddress: address })[0]; + } else if (showNoNodes) { + return {} as OpenNode; + } */ + return nodes?.find((node) => node.service_node_pubkey === nodeId); + }, [nodes]); + + return loading ? ( + + ) : node?.contract ? ( + + + {dictionary('viewOnExplorer')} + + + + ) : null; +}; diff --git a/apps/staking/app/stake/node/[nodeId]/page.tsx b/apps/staking/app/stake/node/[nodeId]/page.tsx index 9271a0f2..c79a1627 100644 --- a/apps/staking/app/stake/node/[nodeId]/page.tsx +++ b/apps/staking/app/stake/node/[nodeId]/page.tsx @@ -1,7 +1,6 @@ -import { LinkOutIcon } from '@session/ui/icons/LinkOutIcon'; import { useTranslations } from 'next-intl'; -import Link from 'next/link'; import ActionModule from '../../ActionModule'; +import { BlockExplorerLink } from './BlockExplorerLink'; import NodeStaking from './NodeStaking'; interface NodePageParams { @@ -17,14 +16,7 @@ export default function NodePage({ params }: NodePageParams) { - - {dictionary('viewOnExplorer')} - - - - } + headerAction={} >