Skip to content

Commit

Permalink
react test comp added 7
Browse files Browse the repository at this point in the history
  • Loading branch information
vasylcode authored Sep 6, 2023
1 parent 8448028 commit aaecaa0
Showing 1 changed file with 6 additions and 27 deletions.
33 changes: 6 additions & 27 deletions src/components/LivePeers.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,27 @@
import React, { useEffect, useState } from "react";

type Peer = {
id: string;
ip: string;
port: string;
};

const LivePeers: React.FC = () => {
const [peers, setPeers] = useState<Peer[]>([]);
const LivePeers = () => {
const [peers, setPeers] = useState([]);

useEffect(() => {
const fetchLivePeers = async () => {
try {
const response = await fetch("https://zetachain-rpc.f5nodes.com/net_info");
const data = await response.json();

const extractedPeers = data.result.peers.map((peer: any) => {
const port = peer.node_info.listen_addr.split(":").pop();
return {
id: peer.node_info.id,
ip: peer.remote_ip,
port: port,
};
});

setPeers(extractedPeers);
console.log(data);
setPeers(data);
} catch (error) {
console.error("Failed to fetch peers info:", error);
}
};

fetchPeersInfo();
fetchLivePeers();
}, []);

return (
<div>
<h2>Peers Information</h2>
<ul>
{peers.map((peer) => (
<li key={peer.id}>
ID: {peer.id}, IP: {peer.ip}, Port: {peer.port}
</li>
))}
</ul>
{data}
</div>
);
};
Expand Down

0 comments on commit aaecaa0

Please sign in to comment.