-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
65 lines (59 loc) · 1.71 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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,
},
});