From 25015da6e56e0293b88b51164f2c3e5804545568 Mon Sep 17 00:00:00 2001 From: Juan De Luca Date: Fri, 27 Dec 2024 06:26:37 -0300 Subject: [PATCH] feat: fetch p2p stats only while mining --- .../floating/Settings/sections/p2p/P2PoolStats.tsx | 12 +++++++++--- .../floating/Settings/sections/p2p/PeerTable.tsx | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/containers/floating/Settings/sections/p2p/P2PoolStats.tsx b/src/containers/floating/Settings/sections/p2p/P2PoolStats.tsx index 65ab3f762..ebb27343d 100644 --- a/src/containers/floating/Settings/sections/p2p/P2PoolStats.tsx +++ b/src/containers/floating/Settings/sections/p2p/P2PoolStats.tsx @@ -13,6 +13,7 @@ import { Divider } from '@app/components/elements/Divider.tsx'; import { ConnectedPeerInfo } from '@app/types/app-status.ts'; import P2PConnectionData from './P2PConnectionData.tsx'; import { timeAgo } from '@app/utils/getTimeAgo.ts'; +import { useMiningStore } from '@app/store/useMiningStore.ts'; export type ConnectedPeerInfoExtended = ConnectedPeerInfo & { sha3Diff?: number; @@ -27,19 +28,24 @@ const P2PoolStats = () => { const peers = useP2poolStatsStore((s) => s?.peers); const fetchP2pStats = useP2poolStatsStore((s) => s?.fetchP2poolStats); const fetchP2poolConnections = useP2poolStatsStore((s) => s?.fetchP2poolConnections); + const isCPUMining = useMiningStore((s) => s.cpu.mining.is_mining); + const isGPUMining = useMiningStore((s) => s.gpu.mining.is_mining); useEffect(() => { + if (!(isCPUMining || isGPUMining)) return; + const handleFetchP2pStats = async () => { - await fetchP2pStats?.(); - await fetchP2poolConnections?.(); + fetchP2pStats(); + fetchP2poolConnections(); }; + handleFetchP2pStats(); const fetchP2pStatsInterval = setInterval(handleFetchP2pStats, 5000); return () => { clearInterval(fetchP2pStatsInterval); }; // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [isCPUMining, isGPUMining]); const displayPeers = useMemo(() => { const sha3Height = sha3Stats?.height; diff --git a/src/containers/floating/Settings/sections/p2p/PeerTable.tsx b/src/containers/floating/Settings/sections/p2p/PeerTable.tsx index 750e7367b..f42697ca3 100644 --- a/src/containers/floating/Settings/sections/p2p/PeerTable.tsx +++ b/src/containers/floating/Settings/sections/p2p/PeerTable.tsx @@ -14,7 +14,7 @@ export default function PeerTable({ peers }: { peers: ConnectedPeerInfoExtended[ const sha3Height = sha3Stats?.height; const randomXHeight = randomXStats?.height; - const headingMarkup = headings.map((heading, idx) => { + const headingMarkup = headings?.map((heading, idx) => { const alignment = idx === 1 ? 'start' : 'end'; return ( @@ -22,7 +22,7 @@ export default function PeerTable({ peers }: { peers: ConnectedPeerInfoExtended[ ); }); - const peerMarkup = peers.map(({ peer_id, peer_info, last_ping, randomxDiff, sha3Diff }, idx) => { + const peerMarkup = peers?.map(({ peer_id, peer_info, last_ping, randomxDiff, sha3Diff }, idx) => { const count = idx + 2; const displayId = truncateMiddle(peer_id, 9); const { current_sha3x_height: sha3x_height, current_random_x_height: random_x_height } = peer_info || {};