diff --git a/explorer-v2/src/components/nymNodePageComponents/NodeRoleCard.tsx b/explorer-v2/src/components/nymNodePageComponents/NodeRoleCard.tsx index d399703efd..571712634b 100644 --- a/explorer-v2/src/components/nymNodePageComponents/NodeRoleCard.tsx +++ b/explorer-v2/src/components/nymNodePageComponents/NodeRoleCard.tsx @@ -171,6 +171,28 @@ export const NodeRoleCard = ({ id }: INodeRoleCardProps) => { }); + const nodeInfo = nymNodes?.find((node) => node.node_id === id); + // Extract node roles once `nodeInfo` is available + const nodeRoles = nodeInfo + ? getNodeRoles(nodeInfo.description.declared_role) + : []; + + // Define whether to fetch gateway status + const shouldFetchGatewayStatus = nodeRoles.some((role) => + ["Entry Node", "Exit IPR Node", "Exit NR Node"].includes(role), + ); + + + // Fetch gateway status only if `shouldFetchGatewayStatus` is true + const { data: gatewayStatus } = useQuery({ + queryKey: ["gatewayStatus", nodeInfo?.identity_key], + queryFn: () => fetchGatewayStatus(nodeInfo?.identity_key || ""), + enabled: !!nodeInfo?.identity_key && shouldFetchGatewayStatus, // ✅ Only fetch if needed + staleTime: 10 * 60 * 1000, // 10 minutes + refetchOnWindowFocus: false, // Prevents unnecessary refetching + refetchOnReconnect: false, + }); + if (isLoading || isEpochLoading) { return ( @@ -191,30 +213,6 @@ export const NodeRoleCard = ({ id }: INodeRoleCardProps) => { ); } - const nodeInfo = nymNodes.find((node) => node.node_id === id); - - - // Extract node roles once `nodeInfo` is available - const nodeRoles = nodeInfo - ? getNodeRoles(nodeInfo.description.declared_role) - : []; - - // Define whether to fetch gateway status - const shouldFetchGatewayStatus = nodeRoles.some((role) => - ["Entry Node", "Exit IPR Node", "Exit NR Node"].includes(role), - ); - - // Fetch gateway status only if `shouldFetchGatewayStatus` is true - const { data: gatewayStatus } = useQuery({ - queryKey: ["gatewayStatus", nodeInfo?.identity_key], - queryFn: () => fetchGatewayStatus(nodeInfo?.identity_key || ""), - enabled: !!nodeInfo?.identity_key && shouldFetchGatewayStatus, // ✅ Only fetch if needed - staleTime: 10 * 60 * 1000, // 10 minutes - refetchOnWindowFocus: false, // Prevents unnecessary refetching - refetchOnReconnect: false, - }); - - const NodeRoles = nodeRoles.map((role) => (