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:
parent
abd26c9c1d
commit
a083d3251b
|
@ -59,8 +59,8 @@ node_modules/
|
||||||
|
|
||||||
# dotenv environment variables file
|
# dotenv environment variables file
|
||||||
.env
|
.env
|
||||||
.env.test
|
.env.*
|
||||||
.env.local
|
!.env.example
|
||||||
|
|
||||||
# parcel-bundler cache (https://parceljs.org/)
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
.parcel-cache
|
.parcel-cache
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
<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
|
<link
|
||||||
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"
|
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"browserslist": "> 0.5%, last 2 versions, not dead, not ios_saf < 13",
|
"browserslist": "> 0.5%, last 2 versions, not dead, not ios_saf < 13",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "parcel index.html --https --no-cache --open",
|
"dev": "vite",
|
||||||
"prebuild": "rm -rf dist",
|
"prebuild": "rm -rf dist",
|
||||||
"build": "parcel build index.html --no-cache"
|
"build": "vite build",
|
||||||
|
"start": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@status-im/react": "0.1.0-alpha.2",
|
"@status-im/react": "0.1.0-alpha.2",
|
||||||
|
@ -17,8 +18,9 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/react": "^17.0.0",
|
"@types/react": "^17.0.0",
|
||||||
"@types/react-dom": "^17.0.0",
|
"@types/react-dom": "^17.0.0",
|
||||||
"parcel": "^2.6.2",
|
"@vitejs/plugin-react": "^2.1.0",
|
||||||
"process": "^0.11.10",
|
"process": "^0.11.10",
|
||||||
"typescript": "^4.0.0"
|
"typescript": "^4.0.0",
|
||||||
|
"vite": "^3.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 ''
|
||||||
|
}),
|
||||||
|
{}
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
10
package.json
10
package.json
|
@ -15,7 +15,7 @@
|
||||||
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint/.eslint-cache .",
|
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint/.eslint-cache .",
|
||||||
"format": "prettier --cache --write .",
|
"format": "prettier --cache --write .",
|
||||||
"format:check": "prettier --check .",
|
"format:check": "prettier --check .",
|
||||||
"clean": "turbo run clean && rm -rf node_modules .parcel-cache"
|
"clean": "turbo run clean && rm -rf node_modules"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@changesets/cli": "^2.23.0",
|
"@changesets/cli": "^2.23.0",
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
"eslint": "^8.9.0",
|
"eslint": "^8.9.0",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
"eslint-import-resolver-node": "^0.3.6",
|
"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-eslint-comments": "^3.2.0",
|
||||||
"eslint-plugin-import": "^2.25.2",
|
"eslint-plugin-import": "^2.25.2",
|
||||||
"eslint-plugin-jsx-a11y": "^6.5.1",
|
"eslint-plugin-jsx-a11y": "^6.5.1",
|
||||||
|
@ -50,9 +50,5 @@
|
||||||
"prettier --write"
|
"prettier --write"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"packageManager": "yarn@1.22.17",
|
"packageManager": "yarn@1.22.17"
|
||||||
"alias": {
|
|
||||||
"protons-runtime": "./node_modules/protons-runtime/dist/src/index.js",
|
|
||||||
"uint8arraylist": "./node_modules/uint8arraylist/dist/src/index.js"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ethereum-cryptography": "^1.0.3",
|
"ethereum-cryptography": "^1.0.3",
|
||||||
"js-waku": "^0.23.0",
|
"js-waku": "^0.25.0",
|
||||||
"long": "^5.2.0",
|
"long": "^5.2.0",
|
||||||
"protobufjs": "^6.11.3",
|
"protobufjs": "^6.11.3",
|
||||||
"protons-runtime": "^1.0.4"
|
"protons-runtime": "^1.0.4"
|
||||||
|
|
|
@ -3,12 +3,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { hexToBytes } from 'ethereum-cryptography/utils'
|
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 {
|
import {
|
||||||
discovery,
|
Fleet,
|
||||||
getPredefinedBootstrapNodes,
|
getPredefinedBootstrapNodes,
|
||||||
Waku,
|
} from 'js-waku/lib/predefined_bootstrap_nodes'
|
||||||
WakuMessage,
|
import { waitForRemotePeer } from 'js-waku/lib/wait_for_remote_peer'
|
||||||
} 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'
|
||||||
|
@ -16,6 +18,8 @@ import { ActivityCenter } from './activityCenter'
|
||||||
import { Community } from './community/community'
|
import { Community } from './community/community'
|
||||||
import { handleWakuMessage } from './community/handle-waku-message'
|
import { handleWakuMessage } from './community/handle-waku-message'
|
||||||
|
|
||||||
|
import type { Waku } from 'js-waku'
|
||||||
|
|
||||||
export interface ClientOptions {
|
export interface ClientOptions {
|
||||||
publicKey: string
|
publicKey: string
|
||||||
environment?: 'production' | 'test'
|
environment?: 'production' | 'test'
|
||||||
|
@ -61,10 +65,7 @@ class Client {
|
||||||
|
|
||||||
static async start(options: ClientOptions) {
|
static async start(options: ClientOptions) {
|
||||||
// Waku
|
// Waku
|
||||||
const fleet =
|
const fleet = options.environment === 'test' ? Fleet.Test : Fleet.Prod
|
||||||
options.environment === 'test'
|
|
||||||
? discovery.predefined.Fleet.Test
|
|
||||||
: discovery.predefined.Fleet.Prod
|
|
||||||
/**
|
/**
|
||||||
* >only connects to 1 remote node because of the limited number of nodes
|
* >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
|
* >run by Status and the limited number of connections provided by these nodes
|
||||||
|
@ -72,25 +73,26 @@ class Client {
|
||||||
* >@see https://forum.vac.dev/t/waku-v2-scalability-studies/142/2
|
* >@see https://forum.vac.dev/t/waku-v2-scalability-studies/142/2
|
||||||
*/
|
*/
|
||||||
const peers = getPredefinedBootstrapNodes(fleet)
|
const peers = getPredefinedBootstrapNodes(fleet)
|
||||||
const waku = await Waku.create({
|
const waku = await createWaku({
|
||||||
bootstrap: {
|
defaultBootstrap: false,
|
||||||
default: false,
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
peers,
|
// @ts-ignore
|
||||||
},
|
emitSelf: true,
|
||||||
relayKeepAlive: 15,
|
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 wakuDisconnectionTimer = setInterval(async () => {
|
||||||
const connectionsToClose: Promise<void>[] = []
|
const connectionsToClose: Promise<void>[] = []
|
||||||
|
|
||||||
for (const connections of waku.libp2p.connectionManager.connections.values()) {
|
for (const connection of waku.libp2p.connectionManager.getConnections()) {
|
||||||
for (const connection of connections) {
|
|
||||||
if (!connection.streams.length) {
|
if (!connection.streams.length) {
|
||||||
connectionsToClose.push(connection.close())
|
connectionsToClose.push(connection.close())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.allSettled(connectionsToClose)
|
await Promise.allSettled(connectionsToClose)
|
||||||
}, 10 * 1000)
|
}, 10 * 1000)
|
||||||
|
|
|
@ -14,7 +14,7 @@ const external = [
|
||||||
export default defineConfig(({ mode }) => {
|
export default defineConfig(({ mode }) => {
|
||||||
const alias: Alias[] = []
|
const alias: Alias[] = []
|
||||||
|
|
||||||
if (process.env.VITEST === 'true' || mode === 'test') {
|
if (process.env.VITE_NODE === 'true' || mode === 'test') {
|
||||||
alias.push({
|
alias.push({
|
||||||
/**
|
/**
|
||||||
* Note: `happy-dom` nor `jsdom` have Crypto implemented (@see https://github.com/jsdom/jsdom/issues/1612)
|
* Note: `happy-dom` nor `jsdom` have Crypto implemented (@see https://github.com/jsdom/jsdom/issues/1612)
|
||||||
|
|
Loading…
Reference in New Issue