Merge pull request #167 from status-im/default-fleet

This commit is contained in:
Franck Royer 2021-05-18 14:10:36 +10:00 committed by GitHub
commit 85f2b84cd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 6 deletions

View File

@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Testing: Upgrade nim-waku node to v0.3.
- **Breaking**: Modify `WakuStore.queryHistory()` to accept one `Object` instead of multiple individual arguments.
- `getStatusFleetNodes` return prod nodes by default, instead of test nodes.
- Examples (web chat): Connect to prod fleet by default, test fleet for local development.
- Examples (cli chat): Connect to test fleet by default, use `--prod` to connect to prod fleet.
### Fixed
- Expose `Enviroment` and `Protocol` enums to pass to `getStatusFleetNodes`.
## [0.3.0] - 2021-05-15

View File

@ -3,6 +3,7 @@ import util from 'util';
import {
ChatMessage,
Environment,
getStatusFleetNodes,
StoreCodec,
Waku,
@ -105,6 +106,7 @@ interface Options {
staticNodes: Multiaddr[];
listenAddr: string;
autoDial: boolean;
prod: boolean;
}
function processArguments(): Options {
@ -114,6 +116,7 @@ function processArguments(): Options {
listenAddr: '/ip4/0.0.0.0/tcp/0',
staticNodes: [],
autoDial: false,
prod: false,
};
while (passedArgs.length) {
@ -128,6 +131,9 @@ function processArguments(): Options {
case '--autoDial':
opts.autoDial = true;
break;
case '--prod':
opts.prod = true;
break;
default:
console.log(`Unsupported argument: ${arg}`);
process.exit(1);
@ -149,7 +155,9 @@ export function formatMessage(chatMsg: ChatMessage): string {
}
async function addFleetNodes(opts: Options): Promise<Options> {
await getStatusFleetNodes().then((nodes) =>
await getStatusFleetNodes(
opts.prod ? Environment.Prod : Environment.Test
).then((nodes) =>
nodes.map((addr) => {
opts.staticNodes.push(multiaddr(addr));
})

View File

@ -3,10 +3,11 @@ import { useEffect, useState } from 'react';
import './App.css';
import {
ChatMessage,
WakuMessage,
getStatusFleetNodes,
Environment,
StoreCodec,
Waku,
getStatusFleetNodes,
WakuMessage,
} from 'js-waku';
import handleCommand from './command';
import Room from './Room';
@ -171,7 +172,7 @@ async function initWaku(setter: (waku: Waku) => void) {
setter(waku);
const nodes = await getStatusFleetNodes();
const nodes = await getNodes();
await Promise.all(
nodes.map((addr) => {
return waku.dial(addr);
@ -181,3 +182,12 @@ async function initWaku(setter: (waku: Waku) => void) {
console.log('Issue starting waku ', e);
}
}
function getNodes() {
// Works with react-scripts
if (process?.env?.NODE_ENV === 'development') {
return getStatusFleetNodes(Environment.Test);
} else {
return getStatusFleetNodes(Environment.Prod);
}
}

View File

@ -1,4 +1,4 @@
export { getStatusFleetNodes } from './lib/discover';
export { getStatusFleetNodes, Environment, Protocol } from './lib/discover';
export { Waku } from './lib/waku';
export { WakuMessage } from './lib/waku_message';

View File

@ -15,7 +15,7 @@ export enum Environment {
}
export async function getStatusFleetNodes(
env: Environment = Environment.Test,
env: Environment = Environment.Prod,
protocol: Protocol = Protocol.websocket
): Promise<string[]> {
const res = await axios.get('https://fleets.status.im/', {