feat: add support for fetching and rendering the network name

This commit is contained in:
Derrick Hammer 2023-07-29 00:01:10 -04:00
parent 0706a61817
commit b0974c7200
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 7 additions and 2 deletions

View File

@ -1,12 +1,13 @@
import "./Network.scss"; import "./Network.scss";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import classNames from "classnames"; import classNames from "classnames";
import { getNetworkModuleStatus } from "@lumeweb/libkernel"; import { callModule, getNetworkModuleStatus } from "@lumeweb/libkernel";
export default function Network({ module }) { export default function Network({ module }) {
let [ready, setReady] = useState(false); let [ready, setReady] = useState(false);
let [sync, setSync] = useState(null); let [sync, setSync] = useState(null);
let [peers, setPeers] = useState(0); let [peers, setPeers] = useState(0);
let [name, setName] = useState();
useEffect(() => { useEffect(() => {
const destroy = getNetworkModuleStatus((data) => { const destroy = getNetworkModuleStatus((data) => {
@ -15,6 +16,10 @@ export default function Network({ module }) {
setPeers(data.peers); setPeers(data.peers);
}, module); }, module);
callModule(module, "name").then((value) => {
setName(value);
});
return () => destroy?.(); return () => destroy?.();
}, [module]); }, [module]);
@ -29,7 +34,7 @@ export default function Network({ module }) {
"icon-wait": !ready, "icon-wait": !ready,
})} })}
/> />
Network {name} Network
</div> </div>
{ready ? ( {ready ? (
<div className="status">Synced</div> <div className="status">Synced</div>