Skip to content

Commit

Permalink
feat: fetch p2p stats only while mining
Browse files Browse the repository at this point in the history
  • Loading branch information
PanchoBubble committed Dec 27, 2024
1 parent 94188ef commit 25015da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/containers/floating/Settings/sections/p2p/P2PoolStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/containers/floating/Settings/sections/p2p/PeerTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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 (
<Cell key={heading} $alignment={alignment}>
<Typography variant="h6">{heading}</Typography>
</Cell>
);
});
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 || {};
Expand Down

0 comments on commit 25015da

Please sign in to comment.