mirror of https://github.com/status-im/js-waku.git
Bootstrap
This commit is contained in:
parent
2ae9a6ca00
commit
3f6497634f
|
@ -1,24 +1,25 @@
|
|||
import './App.css';
|
||||
import { Waku } from 'js-waku';
|
||||
import { getStatusFleetNodes, Waku } from 'js-waku';
|
||||
import * as React from 'react';
|
||||
|
||||
function App() {
|
||||
const [waku, setWaku] = React.useState(undefined);
|
||||
const [wakuStarting, setWakuStarting] = React.useState(false);
|
||||
const [wakuStatus, setWakuStatus] = React.useState('NotStarted');
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!!waku) return;
|
||||
if (wakuStarting) return;
|
||||
if (wakuStatus !== 'NotStarted') return;
|
||||
|
||||
setWakuStarting(true);
|
||||
setWakuStatus('Starting');
|
||||
|
||||
Waku.create().then((waku) => {
|
||||
setWaku(waku);
|
||||
setWakuStarting(false);
|
||||
setWakuStatus('Connecting');
|
||||
bootstrapWaku(waku).then(() => {
|
||||
setWakuStatus('Ready');
|
||||
});
|
||||
});
|
||||
}, [waku, wakuStarting]);
|
||||
|
||||
const wakuStatus = !!waku ? 'Started' : wakuStarting ? 'Loading' : 'Error';
|
||||
}, [waku, wakuStatus]);
|
||||
|
||||
return (
|
||||
<div className="App">
|
||||
|
@ -30,3 +31,8 @@ function 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();
|
||||
```
|
||||
|
||||
# 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…
Reference in New Issue