diff --git a/examples/eth-dm/src/App.tsx b/examples/eth-dm/src/App.tsx index b684bea712..3be1f410a3 100644 --- a/examples/eth-dm/src/App.tsx +++ b/examples/eth-dm/src/App.tsx @@ -76,6 +76,13 @@ function App() { ); const [messages, setMessages] = useState([]); const [address, setAddress] = useState(); + const [peerStats, setPeerStats] = useState<{ + relayPeers: number; + lightPushPeers: number; + }>({ + relayPeers: 0, + lightPushPeers: 0, + }); const classes = useStyles(); @@ -148,12 +155,17 @@ function App() { }; }, [waku, address, EncryptionKeyPair]); - let relayPeers = 0; - let lightPushPeers = 0; - if (waku) { - relayPeers = waku.relay.getPeers().size; - lightPushPeers = waku.lightPush.peers.length; - } + useEffect(() => { + if (!waku) return; + + const interval = setInterval(() => { + setPeerStats({ + relayPeers: waku.relay.getPeers().size, + lightPushPeers: waku.lightPush.peers.length, + }); + }, 1000); + return () => clearInterval(interval); + }, [waku]); let addressDisplay = ''; if (address) { @@ -177,7 +189,8 @@ function App() { /> - Peers: {relayPeers} relay, {lightPushPeers} light push + Peers: {peerStats.relayPeers} relay, {peerStats.lightPushPeers}{' '} + light push Ethereum Direct Message