2023-07-27 22:20:20 +00:00
|
|
|
import "./Network.scss";
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import classNames from "classnames";
|
2023-07-29 04:01:10 +00:00
|
|
|
import { callModule, getNetworkModuleStatus } from "@lumeweb/libkernel";
|
2023-07-27 22:20:20 +00:00
|
|
|
|
|
|
|
export default function Network({ module }) {
|
|
|
|
let [ready, setReady] = useState(false);
|
|
|
|
let [sync, setSync] = useState(null);
|
|
|
|
let [peers, setPeers] = useState(0);
|
2023-07-29 04:01:10 +00:00
|
|
|
let [name, setName] = useState();
|
2023-07-27 22:20:20 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const destroy = getNetworkModuleStatus((data) => {
|
|
|
|
setReady(data.ready);
|
|
|
|
setSync(data.sync);
|
|
|
|
setPeers(data.peers);
|
|
|
|
}, module);
|
|
|
|
|
2023-07-29 04:01:10 +00:00
|
|
|
callModule(module, "name").then((value) => {
|
|
|
|
setName(value);
|
|
|
|
});
|
|
|
|
|
2023-07-27 22:20:20 +00:00
|
|
|
return () => destroy?.();
|
|
|
|
}, [module]);
|
|
|
|
|
|
|
|
return (
|
2023-07-28 00:52:18 +00:00
|
|
|
<li
|
|
|
|
className={classNames({ success: ready, loading: !ready })}
|
|
|
|
title={sync ? `${sync}% Synced` : ""}>
|
2023-07-27 22:20:20 +00:00
|
|
|
<div className="network">
|
|
|
|
<span
|
|
|
|
className={classNames("icon", {
|
|
|
|
"icon-success": ready,
|
|
|
|
"icon-wait": !ready,
|
|
|
|
})}
|
|
|
|
/>
|
2023-07-29 04:01:10 +00:00
|
|
|
{name} Network
|
2023-07-27 22:20:20 +00:00
|
|
|
</div>
|
|
|
|
{ready ? (
|
|
|
|
<div className="status">Synced</div>
|
|
|
|
) : (
|
|
|
|
<div className="status">Syncing</div>
|
|
|
|
)}
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|