Skip to content

Commit

Permalink
add expo example
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Oct 2, 2023
1 parent 9dcd71f commit e36149f
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 3 deletions.
1 change: 0 additions & 1 deletion examples/bun/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// bun run client.ts
import "dotenv/config"
const ws = new WebSocket("ws://localhost:3000");

Expand Down
5 changes: 5 additions & 0 deletions examples/bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scripts": {
"start": "bun client.ts"
}
}
35 changes: 35 additions & 0 deletions examples/expo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files

# dependencies
node_modules/

# Expo
.expo/
dist/
web-build/

# Native
*.orig.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision

# Metro
.metro-health-check*

# debug
npm-debug.*
yarn-debug.*
yarn-error.*

# macOS
.DS_Store
*.pem

# local env files
.env*.local

# typescript
*.tsbuildinfo
65 changes: 65 additions & 0 deletions examples/expo/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { StatusBar } from 'expo-status-bar';
import { TextInput, StyleSheet, Text, SafeAreaView, Button } from 'react-native';
import { useState, useEffect } from "react";

const hostname = "wss://substreams-sink-websockets-production.up.railway.app"
const ws = new WebSocket(hostname);

export default function App() {
const [moduleHash, setModuleHash] = useState('0a363b2a63aadb76a525208f1973531d3616fbae');
const [messages, setMessages] = useState([]);

function handlePress() {
ws.send(moduleHash);
}

useEffect(() => {
ws.onmessage = event => {
const json = JSON.parse(event.data);
const { message, clock, manifest, data } = json;
const payload = message ?? `Block: ${clock.number} | Transactions: ${data.transactionTraces}`;
if ( payload ) setMessages((prevMessages) => [...prevMessages, payload]);
};
}, [])

return (
<SafeAreaView style={styles.container}>
<Text style={styles.title}>Substreams WebSockets</Text>
<Text>Hash Module</Text>
<TextInput
style={styles.input}
onChangeText={setModuleHash}
value={moduleHash}
/>
<Button
onPress={handlePress}
title="Send"
color="#111"
accessibilityLabel="Learn more about this purple button"
/>
{messages.map((message, index) => {
return <Text key={index}>{message}</Text>;
})}
<StatusBar style="auto" />
</SafeAreaView>
);
}

const styles = StyleSheet.create({
title: {
fontSize: 20,
fontWeight: 'bold',
},
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
},
});
30 changes: 30 additions & 0 deletions examples/expo/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"expo": {
"name": "my-app",
"slug": "my-app",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
}
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}
Binary file added examples/expo/assets/adaptive-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/expo/assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/expo/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/expo/assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/expo/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
21 changes: 21 additions & 0 deletions examples/expo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "my-app",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"expo": "~49.0.13",
"expo-status-bar": "~1.6.0",
"react": "18.2.0",
"react-native": "0.72.5"
},
"devDependencies": {
"@babel/core": "^7.20.0"
},
"private": true
}
2 changes: 0 additions & 2 deletions examples/html/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// http-server . -c-1

const messages = document.querySelector("#messages");
const send = document.querySelector("#send");
const message = document.querySelector("#message");
Expand Down
8 changes: 8 additions & 0 deletions examples/html/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"scripts": {
"start": "http-server . -c-1"
},
"devDependencies": {
"http-server": "latest"
}
}

0 comments on commit e36149f

Please sign in to comment.