Install `js-waku@^0.25.0` (#307)

* install `js-waku@^0.24.0`

* install `js-waku@^0.25.0`

* resolve some breaking changes

* add timeout

* upgrade `eslint-import-resolver-typescript`

* add `process.env.VITEST` condition

* increase timeout

* fixup

* ignore `emitSelf`

* replace `parcel` with `vite`

* update `.gitignore`

* change `dev` npm script

* fix favicon href

* load `.env` files

* remove 'alias"

* add `preview`

* upgrade vite

* set `target`s in `vite.config.ts`

* upgrade `@vitejs/plugin-react`

* remove comment

* Update package.json

* Update vite.config.ts
This commit is contained in:
Felicio Mununga 2022-09-16 16:27:47 +02:00 committed by GitHub
parent 45f0c9f706
commit a951c8e95c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1572 additions and 2037 deletions

4
.gitignore vendored
View File

@ -59,8 +59,8 @@ node_modules/
# dotenv environment variables file
.env
.env.test
.env.local
.env.*
!.env.example
# parcel-bundler cache (https://parceljs.org/)
.parcel-cache

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="icon" type="image/png" href="./public/favicon.png" />
<link rel="icon" type="image/png" href="/favicon.png" />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"
rel="stylesheet"

View File

@ -5,9 +5,10 @@
"version": "0.0.0",
"browserslist": "> 0.5%, last 2 versions, not dead, not ios_saf < 13",
"scripts": {
"dev": "parcel index.html --https --no-cache --open",
"dev": "vite",
"prebuild": "rm -rf dist",
"build": "parcel build index.html --no-cache"
"build": "vite build",
"start": "vite preview"
},
"dependencies": {
"@status-im/react": "0.1.0-alpha.2",
@ -17,8 +18,9 @@
"devDependencies": {
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"parcel": "^2.6.2",
"@vitejs/plugin-react": "^2.1.0",
"process": "^0.11.10",
"typescript": "^4.0.0"
"typescript": "^4.0.0",
"vite": "^3.1.0"
}
}

View File

@ -0,0 +1,32 @@
import react from '@vitejs/plugin-react'
import { defineConfig, loadEnv } from 'vite'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
return {
optimizeDeps: {
esbuildOptions: {
target: 'es2020',
},
},
build: {
target: 'es2020',
},
plugins: [react()],
define: {
/**
* Loads `.env` files and sets `process.env` varibales.
*
* @see https://vitejs.dev/config/#environment-variables
* @see https://vitejs.dev/config/shared-options.html#define
*/
...Object.entries(loadEnv(mode, process.cwd(), '')).reduce(
(variables, [key, value]) => ({
...variables,
[`process.env.${key}`]: `'${value}'`, // notice ''
}),
{}
),
},
}
})

View File

@ -15,7 +15,7 @@
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint/.eslint-cache .",
"format": "prettier --cache --write .",
"format:check": "prettier --check .",
"clean": "turbo run clean && rm -rf node_modules .parcel-cache"
"clean": "turbo run clean && rm -rf node_modules"
},
"devDependencies": {
"@changesets/cli": "^2.23.0",
@ -25,7 +25,7 @@
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-node": "^0.3.6",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-import-resolver-typescript": "^3.5.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jsx-a11y": "^6.5.1",
@ -50,9 +50,5 @@
"prettier --write"
]
},
"packageManager": "yarn@1.22.17",
"alias": {
"protons-runtime": "./node_modules/protons-runtime/dist/src/index.js",
"uint8arraylist": "./node_modules/uint8arraylist/dist/src/index.js"
}
"packageManager": "yarn@1.22.17"
}

View File

@ -32,7 +32,7 @@
},
"dependencies": {
"ethereum-cryptography": "^1.0.3",
"js-waku": "^0.23.0",
"js-waku": "^0.25.0",
"long": "^5.2.0",
"protobufjs": "^6.11.3",
"protons-runtime": "^1.0.4"

View File

@ -3,12 +3,14 @@
*/
import { hexToBytes } from 'ethereum-cryptography/utils'
import { Protocols, WakuMessage } from 'js-waku'
import { createWaku } from 'js-waku/lib/create_waku'
import { PeerDiscoveryStaticPeers } from 'js-waku/lib/peer_discovery_static_list'
import {
discovery,
Fleet,
getPredefinedBootstrapNodes,
Waku,
WakuMessage,
} from 'js-waku'
} from 'js-waku/lib/predefined_bootstrap_nodes'
import { waitForRemotePeer } from 'js-waku/lib/wait_for_remote_peer'
import { ApplicationMetadataMessage } from '../protos/application-metadata-message'
import { Account } from './account'
@ -16,6 +18,8 @@ import { ActivityCenter } from './activityCenter'
import { Community } from './community/community'
import { handleWakuMessage } from './community/handle-waku-message'
import type { Waku } from 'js-waku'
export interface ClientOptions {
publicKey: string
environment?: 'production' | 'test'
@ -61,10 +65,7 @@ class Client {
static async start(options: ClientOptions) {
// Waku
const fleet =
options.environment === 'test'
? discovery.predefined.Fleet.Test
: discovery.predefined.Fleet.Prod
const fleet = options.environment === 'test' ? Fleet.Test : 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
@ -72,23 +73,24 @@ class Client {
* >@see https://forum.vac.dev/t/waku-v2-scalability-studies/142/2
*/
const peers = getPredefinedBootstrapNodes(fleet)
const waku = await Waku.create({
bootstrap: {
default: false,
peers,
},
const waku = await createWaku({
defaultBootstrap: false,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
emitSelf: true,
relayKeepAlive: 15,
libp2p: { config: { pubsub: { enabled: true, emitSelf: true } } },
libp2p: {
peerDiscovery: [new PeerDiscoveryStaticPeers(peers)],
},
})
await waku.waitForRemotePeer()
await waku.start()
await waitForRemotePeer(waku, [Protocols.Relay, Protocols.Store], 10 * 1000)
const wakuDisconnectionTimer = setInterval(async () => {
const connectionsToClose: Promise<void>[] = []
for (const connections of waku.libp2p.connectionManager.connections.values()) {
for (const connection of connections) {
if (!connection.streams.length) {
connectionsToClose.push(connection.close())
}
for (const connection of waku.libp2p.connectionManager.getConnections()) {
if (!connection.streams.length) {
connectionsToClose.push(connection.close())
}
}

View File

@ -14,7 +14,7 @@ const external = [
export default defineConfig(({ mode }) => {
const alias: Alias[] = []
if (process.env.VITEST === 'true' || mode === 'test') {
if (process.env.VITE_NODE === 'true' || mode === 'test') {
alias.push({
/**
* Note: `happy-dom` nor `jsdom` have Crypto implemented (@see https://github.com/jsdom/jsdom/issues/1612)

3505
yarn.lock

File diff suppressed because it is too large Load Diff