Skip to content

Commit

Permalink
feat: weshnet example
Browse files Browse the repository at this point in the history
Signed-off-by: Norman Meier <norman@berty.tech>
  • Loading branch information
n0izn0iz committed May 20, 2023
1 parent e9c13b8 commit 39eea5b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/components/navigation/Navigator.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import React from "react";

import { ChatScreen } from "../../screens/Chat/ChatScreen";
import { ComingSoonScreen } from "../../screens/ComingSoon/ComingSoon";
import { DAppStore } from "../../screens/DAppStore/HomeScreen";
import { ToriPunks } from "../../screens/DAppStore/apps/toripunks/HomeScreen";
Expand Down Expand Up @@ -254,6 +255,11 @@ export const Navigator: React.FC = () => {
component={DAppStore}
options={{ header: () => null, title: screenTitle("dApp Store") }}
/>
<Stack.Screen
name="Chat"
component={ChatScreen}
options={{ header: () => null, title: screenTitle("Chat") }}
/>
</Stack.Navigator>
);
};
40 changes: 40 additions & 0 deletions packages/screens/Chat/ChatScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useState } from "react";

import { BrandText } from "../../components/BrandText";
import { ScreenContainer } from "../../components/ScreenContainer";
import { PrimaryButton } from "../../components/buttons/PrimaryButton";
import { ScreenFC } from "../../utils/navigation";
import { createWeshClient } from "../../weshnet";

/*
To test this:
- clone this branch https://github.com/TERITORI/weshnet/tree/first-contact
- run `go run ./cmd/weshd` at weshnet root
- navigate to `/chat` in teritori ui
- click `Test` button
*/

export const ChatScreen: ScreenFC<"Chat"> = () => {
const [text, setText] = useState("");
return (
<ScreenContainer>
<PrimaryButton
size="M"
text="Test"
loader
onPress={async () => {
try {
const weshClient = createWeshClient("http://localhost:4242");
const weshConfig = await weshClient.ServiceGetConfiguration({});
console.log("wesh test success", weshConfig);
setText(JSON.stringify(weshConfig));
} catch (err) {
console.error("wesh test error", err);
setText(`${err}`);
}
}}
/>
<BrandText>{text}</BrandText>
</ScreenContainer>
);
};
4 changes: 4 additions & 0 deletions packages/utils/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export type RootStackParamList = {

DAppStore: undefined;
ToriPunks: { route: string };

Chat: undefined;
};

export type AppNavigationProp = NativeStackNavigationProp<RootStackParamList>;
Expand Down Expand Up @@ -123,6 +125,8 @@ const navConfig: {

// === DApps
ToriPunks: "dapp/tori-punks/:route?",

Chat: "chat",
},
};

Expand Down
4 changes: 2 additions & 2 deletions packages/weshnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ProtocolServiceClientImpl, GrpcWebImpl } from "./protocoltypes";

export * from "./protocoltypes";

export const createWeshClient = () => {
const rpc = new GrpcWebImpl("http://localhost:4242", {
export const createWeshClient = (url: string) => {
const rpc = new GrpcWebImpl(url, {
debug: true,
});
return new ProtocolServiceClientImpl(rpc);
Expand Down

0 comments on commit 39eea5b

Please sign in to comment.