mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-12 21:44:33 +00:00
Bootstrap
This commit is contained in:
parent
2ae9a6ca00
commit
3f6497634f
@ -1,24 +1,25 @@
|
|||||||
import './App.css';
|
import './App.css';
|
||||||
import { Waku } from 'js-waku';
|
import { getStatusFleetNodes, Waku } from 'js-waku';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [waku, setWaku] = React.useState(undefined);
|
const [waku, setWaku] = React.useState(undefined);
|
||||||
const [wakuStarting, setWakuStarting] = React.useState(false);
|
const [wakuStatus, setWakuStatus] = React.useState('NotStarted');
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!!waku) return;
|
if (!!waku) return;
|
||||||
if (wakuStarting) return;
|
if (wakuStatus !== 'NotStarted') return;
|
||||||
|
|
||||||
setWakuStarting(true);
|
setWakuStatus('Starting');
|
||||||
|
|
||||||
Waku.create().then((waku) => {
|
Waku.create().then((waku) => {
|
||||||
setWaku(waku);
|
setWaku(waku);
|
||||||
setWakuStarting(false);
|
setWakuStatus('Connecting');
|
||||||
|
bootstrapWaku(waku).then(() => {
|
||||||
|
setWakuStatus('Ready');
|
||||||
});
|
});
|
||||||
}, [waku, wakuStarting]);
|
});
|
||||||
|
}, [waku, wakuStatus]);
|
||||||
const wakuStatus = !!waku ? 'Started' : wakuStarting ? 'Loading' : 'Error';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
@ -30,3 +31,8 @@ function App() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|
||||||
|
async function bootstrapWaku(waku) {
|
||||||
|
const nodes = await getStatusFleetNodes();
|
||||||
|
await Promise.all(nodes.map((addr) => waku.dial(addr)));
|
||||||
|
}
|
||||||
|
@ -25,3 +25,17 @@ import { Waku } from 'js-waku';
|
|||||||
|
|
||||||
const wakuNode = await Waku.create();
|
const wakuNode = await Waku.create();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Connect to other peers
|
||||||
|
|
||||||
|
The Waku instance needs to connect to other peers to communicate with the network.
|
||||||
|
You are free to choose any method to bootstrap and DappConnect will ship with new methods in the future.
|
||||||
|
|
||||||
|
For now, the easiest way is to connect to Status' Waku fleet:
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { getStatusFleetNodes } from 'js-waku';
|
||||||
|
|
||||||
|
const nodes = await getStatusFleetNodes();
|
||||||
|
await Promise.all(nodes.map((addr) => waku.dial(addr)));
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user