From 24d202a2ba39f26605ae67fa2c31aeb5bddbbb5e Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Tue, 4 Oct 2022 15:18:26 +1100 Subject: [PATCH] feat: add dial button --- rln-js/index.html | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/rln-js/index.html b/rln-js/index.html index c0e9183..0307296 100644 --- a/rln-js/index.html +++ b/rln-js/index.html @@ -16,7 +16,7 @@

RLN

- +

You can either generate new credentials:


@@ -50,6 +50,13 @@

Waku


+ + + + +
@@ -66,12 +73,6 @@ import {utils} from 'https://unpkg.com/js-waku@0.29.0-29436ea/bundle/index.js'; import {createLightNode} from 'https://unpkg.com/js-waku@0.29.0-29436ea/bundle/lib/create_waku.js' import {waitForRemotePeer} from 'https://unpkg.com/js-waku@0.29.0-29436ea/bundle/lib/wait_for_remote_peer.js' - import { - PeerDiscoveryStaticPeers - } from "https://unpkg.com/js-waku@0.29.0-29436ea/bundle/lib/peer_discovery_static_list"; - import { - getPredefinedBootstrapNodes - } from "https://unpkg.com/js-waku@0.29.0-29436ea/bundle/lib/predefined_bootstrap_nodes"; import {EncoderV0, DecoderV0} from 'https://unpkg.com/js-waku@0.29.0-29436ea/bundle/lib/waku_message/version_0.js' import {protobuf} from "https://taisukef.github.io/protobuf-es.js/dist/protobuf-es.js"; @@ -96,6 +97,9 @@ // Waku Elements const statusDiv = document.getElementById('status'); + const dialButton = document.getElementById('dial') + const remoteMultiAddrInput = document.getElementById('remote-multiaddr') + const nicknameInput = document.getElementById('nick-input') const setNickButton = document.getElementById('set-nick') @@ -196,8 +200,6 @@ const provider = new ethers.providers.Web3Provider(window.ethereum, "any"); - checkCurrentChain(); - let accounts; let rlnContract; @@ -315,23 +317,29 @@ let node; (async () => { statusDiv.innerHTML = '

Creating Waku node.

'; - node = await createLightNode({ - libp2p: { - peerDiscovery: [ - new PeerDiscoveryStaticPeers(getPredefinedBootstrapNodes("test")), - ], - }, - }); + node = await createLightNode(); statusDiv.innerHTML = '

Starting Waku node.

'; await node.start(); statusDiv.innerHTML = '

Waku node started.

'; + dialButton.disabled = false; + updateFields() + })() + + dialButton.onclick = async () => { + const ma = remoteMultiAddrInput.value + if (!ma) { + statusDiv.innerHTML = '

Error: No multiaddr provided.

'; + return; + } + statusDiv.innerHTML = '

Dialing peer.

'; + await node.dial(ma, ["filter", "lightpush"]) await waitForRemotePeer(node, ["filter", "lightpush"]); statusDiv.innerHTML = '

Waku node connected.

'; await node.filter.subscribe([decoder], callback) + statusDiv.innerHTML = '

Waku node subscribed.

'; nodeConnected = true; - updateFields() - })() + } sendButton.onclick = async () => { const text = utils.utf8ToBytes(textInput.value);