diff --git a/apps/guardian-ui/src/admin/FederationAdmin.tsx b/apps/guardian-ui/src/admin/FederationAdmin.tsx index c406306b1..2bcc47024 100644 --- a/apps/guardian-ui/src/admin/FederationAdmin.tsx +++ b/apps/guardian-ui/src/admin/FederationAdmin.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useMemo } from 'react'; import { Flex, Card, @@ -18,9 +18,7 @@ import { CopyInput } from '@fedimint/ui'; import { useTranslation } from '@fedimint/utils'; import { useAdminContext } from '../hooks'; import { - ClientConfig, ConfigResponse, - FederationStatus, Gateway, PeerStatus, StatusResponse, @@ -38,27 +36,6 @@ interface PeerData { status: PeerStatus; } -function generatePeerData( - config: ClientConfig, - federationStatus: FederationStatus -): PeerData[] { - const peerDataArray: PeerData[] = []; - for (const [id, status] of Object.entries(federationStatus.status_by_peer)) { - const numericId = parseInt(id, 10); - if (Object.prototype.hasOwnProperty.call(config.api_endpoints, numericId)) { - const endpoint = config.api_endpoints[numericId]; - if (endpoint) { - peerDataArray.push({ - id: numericId, - name: endpoint.name, - status, - }); - } - } - } - return peerDataArray; -} - export const FederationAdmin: React.FC = () => { const { api } = useAdminContext(); const [versions, setVersions] = useState(); @@ -68,7 +45,6 @@ export const FederationAdmin: React.FC = () => { const [config, setConfig] = useState(); const [gateways, setGateways] = useState([]); const [guardians, setGuardians] = useState(); - const [peerData, setPeerData] = useState(); const { t } = useTranslation(); useEffect(() => { @@ -108,10 +84,23 @@ export const FederationAdmin: React.FC = () => { setGuardians(`${online} / ${totalPeers}`); }, [status]); - useEffect(() => { + const data = useMemo(() => { if (status && status.federation && config) { - const data = generatePeerData(config.client_config, status.federation); - setPeerData(data); + const peerDataArray: PeerData[] = []; + for (const [id, federationStatus] of Object.entries( + status.federation.status_by_peer + )) { + const numericId = parseInt(id, 10); + const endpoint = config.client_config.api_endpoints[numericId]; + if (endpoint) { + peerDataArray.push({ + id: numericId, + name: endpoint.name, + status: federationStatus, + }); + } + } + return peerDataArray; } }, [status, config]); @@ -208,8 +197,8 @@ export const FederationAdmin: React.FC = () => { - {peerData && - peerData?.map((x) => ( + {data && + data?.map((x) => ( {x.id} {x.name}