Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetch p2p stats only while mining #1315

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading