Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
otobongfp committed Mar 25, 2024
1 parent d94c2f1 commit f2a12d1
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 97 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"homepage": "https://ltonetwork.github.io/tools-app/",
"name": "lto-tools-app",
"private": true,
"version": "0.0.0",
Expand Down
194 changes: 97 additions & 97 deletions src/pages/Nodes2.jsx
Original file line number Diff line number Diff line change
@@ -1,105 +1,105 @@
import React, { useState, useEffect } from "react";
import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell";
import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import Paper from "@mui/material/Paper";
import axios from "axios";
import { BASE_URL } from "../utils/config";
// import React, { useState, useEffect } from "react";
// import Table from "@mui/material/Table";
// import TableBody from "@mui/material/TableBody";
// import TableCell from "@mui/material/TableCell";
// import TableContainer from "@mui/material/TableContainer";
// import TableHead from "@mui/material/TableHead";
// import TableRow from "@mui/material/TableRow";
// import Paper from "@mui/material/Paper";
// import axios from "axios";
// import { BASE_URL } from "../utils/config";

const Nodes = () => {
const [data, setData] = useState([]);
const [ipInfo, setIpInfo] = useState({});
// const Nodes = () => {
// const [data, setData] = useState([]);
// const [ipInfo, setIpInfo] = useState({});

useEffect(() => {
axios
.get(`${BASE_URL}peers/connected`)
.then((res) => {
const nodes = res.data.peers;
setData(nodes);
console.log(nodes);
// useEffect(() => {
// axios
// .get(`${BASE_URL}peers/connected`)
// .then((res) => {
// const nodes = res.data.peers;
// setData(nodes);
// console.log(nodes);

// Fetch IP information for all nodes
const fetchIpInfoPromises = nodes.map((node) =>
fetchIpInfo(getIP(node.declaredAddress))
);
// // Fetch IP information for all nodes
// const fetchIpInfoPromises = nodes.map((node) =>
// fetchIpInfo(getIP(node.declaredAddress))
// );

// Wait for all IP information requests to complete
Promise.all(fetchIpInfoPromises)
.then((ipInfos) => {
const ipInfoMap = {};
ipInfos.forEach((ipInfo, index) => {
const ip = nodes[index].declaredAddress.split(":")[0];
ipInfoMap[ip] = ipInfo;
});
setIpInfo(ipInfoMap);
})
.catch((error) => console.error(error));
})
.catch((error) => {
console.error("Errors fetching the node data", error);
});
}, []);
// // Wait for all IP information requests to complete
// Promise.all(fetchIpInfoPromises)
// .then((ipInfos) => {
// const ipInfoMap = {};
// ipInfos.forEach((ipInfo, index) => {
// const ip = nodes[index].declaredAddress.split(":")[0];
// ipInfoMap[ip] = ipInfo;
// });
// setIpInfo(ipInfoMap);
// })
// .catch((error) => console.error(error));
// })
// .catch((error) => {
// console.error("Errors fetching the node data", error);
// });
// }, []);

const getIP = (address) => {
const ip = address.split(":");
return ip[0];
};
// const getIP = (address) => {
// const ip = address.split(":");
// return ip[0];
// };

const fetchIpInfo = async (ipAddress) => {
try {
const res = await axios.get(`http://ip-api.com/json/${ipAddress}`);
const ipinfo = res.data;
return { countryCode: ipinfo.countryCode, isp: ipinfo.isp };
} catch (error) {
console.error(error);
return { countryCode: "", isp: "" };
}
};
// const fetchIpInfo = async (ipAddress) => {
// try {
// const res = await axios.get(`http://ip-api.com/json/${ipAddress}`);
// const ipinfo = res.data;
// return { countryCode: ipinfo.countryCode, isp: ipinfo.isp };
// } catch (error) {
// console.error(error);
// return { countryCode: "", isp: "" };
// }
// };

return (
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} size="small" aria-label="a dense table">
<TableHead>
<TableRow>
<TableCell>#</TableCell>
<TableCell>Node name</TableCell>
<TableCell align="center">IP address</TableCell>
<TableCell align="center">Country</TableCell>
<TableCell align="center">ISP</TableCell>
<TableCell align="center">Version</TableCell>
</TableRow>
</TableHead>
<TableBody>
{data.map((node, index) => (
<TableRow
key={node.peerName}
sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
>
<TableCell component="th" scope="row">
{index + 1}
</TableCell>
<TableCell component="th" scope="row">
{node.peerName}
</TableCell>
<TableCell align="center">
{getIP(node.declaredAddress)}
</TableCell>
<TableCell align="center">
{ipInfo[getIP(node.declaredAddress)]?.countryCode}
</TableCell>
<TableCell align="center">
{ipInfo[getIP(node.declaredAddress)]?.isp}
</TableCell>
<TableCell align="center">{node.applicationVersion}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
);
};
// return (
// <TableContainer component={Paper}>
// <Table sx={{ minWidth: 650 }} size="small" aria-label="a dense table">
// <TableHead>
// <TableRow>
// <TableCell>#</TableCell>
// <TableCell>Node name</TableCell>
// <TableCell align="center">IP address</TableCell>
// <TableCell align="center">Country</TableCell>
// <TableCell align="center">ISP</TableCell>
// <TableCell align="center">Version</TableCell>
// </TableRow>
// </TableHead>
// <TableBody>
// {data.map((node, index) => (
// <TableRow
// key={node.peerName}
// sx={{ "&:last-child td, &:last-child th": { border: 0 } }}
// >
// <TableCell component="th" scope="row">
// {index + 1}
// </TableCell>
// <TableCell component="th" scope="row">
// {node.peerName}
// </TableCell>
// <TableCell align="center">
// {getIP(node.declaredAddress)}
// </TableCell>
// <TableCell align="center">
// {ipInfo[getIP(node.declaredAddress)]?.countryCode}
// </TableCell>
// <TableCell align="center">
// {ipInfo[getIP(node.declaredAddress)]?.isp}
// </TableCell>
// <TableCell align="center">{node.applicationVersion}</TableCell>
// </TableRow>
// ))}
// </TableBody>
// </Table>
// </TableContainer>
// );
// };

export default Nodes;
// export default Nodes;

0 comments on commit f2a12d1

Please sign in to comment.