Skip to content

Commit

Permalink
Merge pull request #167 from status-im/default-fleet
Browse files Browse the repository at this point in the history
  • Loading branch information
D4nte authored May 18, 2021
2 parents fb99d60 + c4c259f commit 85f2b84
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion examples/cli-chat/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import util from 'util';

import {
ChatMessage,
Environment,
getStatusFleetNodes,
StoreCodec,
Waku,
Expand Down Expand Up @@ -105,6 +106,7 @@ interface Options {
staticNodes: Multiaddr[];
listenAddr: string;
autoDial: boolean;
prod: boolean;
}

function processArguments(): Options {
Expand All @@ -114,6 +116,7 @@ function processArguments(): Options {
listenAddr: '/ip4/0.0.0.0/tcp/0',
staticNodes: [],
autoDial: false,
prod: false,
};

while (passedArgs.length) {
Expand All @@ -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);
Expand All @@ -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));
})
Expand Down
16 changes: 13 additions & 3 deletions examples/web-chat/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/', {
Expand Down

0 comments on commit 85f2b84

Please sign in to comment.