diff --git a/eth-pm/src/App.tsx b/eth-pm/src/App.tsx index fd87c2d..db56527 100644 --- a/eth-pm/src/App.tsx +++ b/eth-pm/src/App.tsx @@ -163,15 +163,12 @@ function App() { if (!waku) return; const interval = setInterval(async () => { - let lightPushPeers = 0; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - for await (const _peer of waku.store.peers) { - lightPushPeers++; - } + const lightPushPeers = await waku.store.peers(); + const relayPeers = waku.relay.getMeshPeers(); setPeerStats({ - relayPeers: waku.relay.getPeers().size, - lightPushPeers, + relayPeers: relayPeers.length, + lightPushPeers: lightPushPeers.length, }); }, 1000); return () => clearInterval(interval); diff --git a/eth-pm/src/messaging/SendMessage.tsx b/eth-pm/src/messaging/SendMessage.tsx index 76985b2..21a385f 100644 --- a/eth-pm/src/messaging/SendMessage.tsx +++ b/eth-pm/src/messaging/SendMessage.tsx @@ -133,7 +133,7 @@ function sendMessage( .push(msg) .then((res) => { console.log("Message sent", res); - callback(res ? res.isSuccess : false); + callback(res?.isSuccess ?? false); }) .catch((e) => { console.error("Failed to send message", e); diff --git a/eth-pm/src/waku.ts b/eth-pm/src/waku.ts index 1860898..d202228 100644 --- a/eth-pm/src/waku.ts +++ b/eth-pm/src/waku.ts @@ -4,12 +4,13 @@ import { PrivateMessage, PublicKeyMessage } from "./messaging/wire"; import { validatePublicKeyMessage } from "./crypto"; import { Message } from "./messaging/Messages"; import { equals } from "uint8arrays/equals"; +import { createWaku } from "js-waku/lib/create_waku"; export const PublicKeyContentTopic = "/eth-pm/1/public-key/proto"; export const PrivateMessageContentTopic = "/eth-pm/1/private-message/proto"; export async function initWaku(): Promise { - const waku = await Waku.create({ bootstrap: { default: true } }); + const waku = await createWaku({ defaultBootstrap: true }); // Wait to be connected to at least one peer await new Promise((resolve, reject) => { @@ -17,7 +18,7 @@ export async function initWaku(): Promise { // As we are not implementing connection management in this example setTimeout(reject, 10000); - waku.libp2p.connectionManager.on("peer:connect", () => { + waku.libp2p.connectionManager.addEventListener("peer:connect", () => { resolve(null); }); });