Small cleanup

This commit is contained in:
Franck Royer 2021-09-03 17:04:25 +10:00
parent d6d52b72dd
commit f6aa758712
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 13 additions and 14 deletions

View File

@ -32,13 +32,24 @@ function App() {
React.useEffect(() => { React.useEffect(() => {
if (!waku) return; if (!waku) return;
if (wakuStatus !== 'Connected to Store') return;
// We do not handle disconnection/re-connection in this example
if (wakuStatus === 'Connected') return;
waku.waitForConnectedPeer().then(() => {
// We are now connected to a store node
setWakuStatus('Connected');
});
}, [waku, wakuStatus]);
React.useEffect(() => {
if (!waku) return;
if (wakuStatus !== 'Connected') return;
const interval = setInterval(() => { const interval = setInterval(() => {
waku.store waku.store
.queryHistory([ContentTopic]) .queryHistory([ContentTopic])
.catch((e) => { .catch((e) => {
// We may not be connected to a store node just yet
console.log('Failed to retrieve messages', e); console.log('Failed to retrieve messages', e);
}) })
.then((retrievedMessages) => { .then((retrievedMessages) => {
@ -51,18 +62,6 @@ function App() {
return () => clearInterval(interval); return () => clearInterval(interval);
}, [waku, wakuStatus]); }, [waku, wakuStatus]);
React.useEffect(() => {
if (!waku) return;
// We do not handle disconnection/re-connection in this example
if (wakuStatus === 'Connected to Store') return;
waku.waitForConnectedPeer().then(() => {
// We are now connected to a store node
setWakuStatus('Connected to Store');
});
}, [waku, wakuStatus]);
return ( return (
<div className="App"> <div className="App">
<header className="App-header"> <header className="App-header">