Get peer based on environment (#294)

* get peer based on environment

* add changeset

* default to prod
This commit is contained in:
Felicio Mununga 2022-07-19 10:19:46 +02:00 committed by GitHub
parent c4f052f71a
commit 82625fe6db
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
4 changed files with 30 additions and 7 deletions

View File

@ -0,0 +1,5 @@
---
'@status-im/js': patch
---
get peer based on environment

View File

@ -1 +1,2 @@
PUBLIC_KEY="" PUBLIC_KEY=""
ENVIRONMENT=""

View File

@ -10,6 +10,10 @@ if (!publicKey) {
) )
} }
const environment = process.env.ENVIRONMENT
export const App = () => { export const App = () => {
return <Community publicKey={publicKey} theme="light" /> return (
<Community publicKey={publicKey} environment={environment} theme="light" />
)
} }

View File

@ -3,7 +3,12 @@
*/ */
import { hexToBytes } from 'ethereum-cryptography/utils' import { hexToBytes } from 'ethereum-cryptography/utils'
import { Waku, WakuMessage } from 'js-waku' import {
discovery,
getPredefinedBootstrapNodes,
Waku,
WakuMessage,
} from 'js-waku'
import { ApplicationMetadataMessage } from '../protos/application-metadata-message' import { ApplicationMetadataMessage } from '../protos/application-metadata-message'
import { Account } from './account' import { Account } from './account'
@ -12,7 +17,7 @@ import { handleWakuMessage } from './community/handle-waku-message'
export interface ClientOptions { export interface ClientOptions {
publicKey: string publicKey: string
env?: 'production' | 'test' environment?: 'production' | 'test'
} }
class Client { class Client {
@ -51,13 +56,21 @@ class Client {
static async start(options: ClientOptions) { static async start(options: ClientOptions) {
// Waku // Waku
const fleet =
options.environment === 'test'
? discovery.predefined.Fleet.Test
: discovery.predefined.Fleet.Prod
/**
* >only connects to 1 remote node because of the limited number of nodes
* >run by Status and the limited number of connections provided by these nodes
* >
* >@see https://forum.vac.dev/t/waku-v2-scalability-studies/142/2
*/
const peers = getPredefinedBootstrapNodes(fleet)
const waku = await Waku.create({ const waku = await Waku.create({
bootstrap: { bootstrap: {
default: false, default: false,
peers: [ peers,
'/dns4/node-01.gc-us-central1-a.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS',
// '/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ',
],
}, },
relayKeepAlive: 15, relayKeepAlive: 15,
libp2p: { config: { pubsub: { enabled: true, emitSelf: true } } }, libp2p: { config: { pubsub: { enabled: true, emitSelf: true } } },