From 568f3f83f27d3f4fee190d7d400ab07d9061d4e1 Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Wed, 31 Aug 2022 12:48:02 +1000 Subject: [PATCH] fix: use new js-waku API --- store-reactjs-chat/src/App.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/store-reactjs-chat/src/App.js b/store-reactjs-chat/src/App.js index fbe0981..9de7bbc 100644 --- a/store-reactjs-chat/src/App.js +++ b/store-reactjs-chat/src/App.js @@ -1,6 +1,7 @@ -import { Waku } from "js-waku"; +import { waitForRemotePeer, utils } from "js-waku"; import * as React from "react"; import protons from "protons"; +import { createWaku } from "js-waku/lib/create_waku"; const ContentTopic = "/toy-chat/2/huilong/proto"; @@ -22,9 +23,11 @@ function App() { setWakuStatus("Starting"); - Waku.create({ bootstrap: { default: true } }).then((waku) => { - setWaku(waku); - setWakuStatus("Connecting"); + createWaku({ defaultBootstrap: true }).then((waku) => { + waku.start().then(() => { + setWaku(waku); + setWakuStatus("Connecting"); + }); }); }, [waku, wakuStatus]); @@ -34,7 +37,7 @@ function App() { // We do not handle disconnection/re-connection in this example if (wakuStatus === "Connected") return; - waku.waitForRemotePeer().then(() => { + waitForRemotePeer(waku, ["store"]).then(() => { // We are now connected to a store node setWakuStatus("Connected"); }); @@ -62,6 +65,7 @@ function App() { }) .catch((e) => { console.log("Failed to retrieve messages", e); + setWakuStatus("Error Encountered"); }); }, [waku, wakuStatus]); @@ -92,15 +96,20 @@ function decodeMessage(wakuMessage) { const time = new Date(); time.setTime(timestamp); - const utf8Text = Buffer.from(text).toString("utf-8"); + const utf8Text = utils.bytesToUtf8(text); - return { text: utf8Text, timestamp: time, nick }; + return { + text: utf8Text, + timestamp: time, + nick, + timestampInt: wakuMessage.timestamp, + }; } function Messages(props) { - return props.messages.map(({ text, timestamp, nick }) => { + return props.messages.map(({ text, timestamp, nick, timestampInt }) => { return ( -
  • +
  • ({formatDate(timestamp)}) {nick}: {text}
  • );