From e36149fbfd9b4efd42134803919eabcf4c4d7e3c Mon Sep 17 00:00:00 2001 From: Denis Carriere Date: Mon, 2 Oct 2023 18:45:13 -0400 Subject: [PATCH] add expo example --- examples/bun/client.ts | 1 - examples/bun/package.json | 5 ++ examples/expo/.gitignore | 35 +++++++++++++ examples/expo/App.js | 65 +++++++++++++++++++++++++ examples/expo/app.json | 30 ++++++++++++ examples/expo/assets/adaptive-icon.png | Bin 0 -> 17547 bytes examples/expo/assets/favicon.png | Bin 0 -> 1466 bytes examples/expo/assets/icon.png | Bin 0 -> 22380 bytes examples/expo/assets/splash.png | Bin 0 -> 47346 bytes examples/expo/babel.config.js | 6 +++ examples/expo/package.json | 21 ++++++++ examples/html/index.js | 2 - examples/html/package.json | 8 +++ 13 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 examples/bun/package.json create mode 100644 examples/expo/.gitignore create mode 100644 examples/expo/App.js create mode 100644 examples/expo/app.json create mode 100644 examples/expo/assets/adaptive-icon.png create mode 100644 examples/expo/assets/favicon.png create mode 100644 examples/expo/assets/icon.png create mode 100644 examples/expo/assets/splash.png create mode 100644 examples/expo/babel.config.js create mode 100644 examples/expo/package.json create mode 100644 examples/html/package.json diff --git a/examples/bun/client.ts b/examples/bun/client.ts index 0ce864f..0d734b9 100644 --- a/examples/bun/client.ts +++ b/examples/bun/client.ts @@ -1,4 +1,3 @@ -// bun run client.ts import "dotenv/config" const ws = new WebSocket("ws://localhost:3000"); diff --git a/examples/bun/package.json b/examples/bun/package.json new file mode 100644 index 0000000..b04ad4c --- /dev/null +++ b/examples/bun/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "start": "bun client.ts" + } +} \ No newline at end of file diff --git a/examples/expo/.gitignore b/examples/expo/.gitignore new file mode 100644 index 0000000..05647d5 --- /dev/null +++ b/examples/expo/.gitignore @@ -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 diff --git a/examples/expo/App.js b/examples/expo/App.js new file mode 100644 index 0000000..3d282b9 --- /dev/null +++ b/examples/expo/App.js @@ -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 ( + + Substreams WebSockets + Hash Module + +