Skip to content

Commit

Permalink
feat(site): add filter function
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiserKarel authored and cor committed Sep 28, 2023
1 parent ae5940b commit 0cc1a46
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions site/src/lib/Xterm.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import { onMount } from 'svelte';
import { ApolloClient, InMemoryCache, ApolloProvider, gql } from '@apollo/client';
import { ApolloClient, InMemoryCache, ApolloProvider, gql, type ApolloQueryResult } from '@apollo/client';
import type { Terminal } from 'xterm';
import { json } from '@sveltejs/kit';
const client = new ApolloClient({
uri: 'https://graphql.union.build/v1/graphql',
Expand All @@ -20,6 +21,47 @@
let terminal: null | Terminal;
let terminalElement: HTMLElement;
const filter = (r: ApolloQueryResult<any>): null | string => {
let data = r.data.demo_txes_by_pk;
if (data === null) {
return null
}
data = r.data.demo_txes_by_pk.data;
let network;
let action;
if ('EthereumMinimal' in data) {
network = "[union]: "
data = data['EthereumMinimal']
}
if ('CometblsMinimal' in data) {
network = "[sepolia]: "
data = data['CometblsMinimal']
}
if ('Fetch' in data) {
action = "fetching "
data = data["Fetch"]["data"]
}
if ('Event' in data) {
action = "observed event "
data = data["Event"]["data"]
}
if ('Msg' in data) {
action = "sending message "
data = data["Msg"]["data"]
}
if (network === undefined) {
return null
}
return network + action + JSON.stringify(data) + '\r\n'
}
const worker = async () => {
for (let i = 0; i < 100000000; i++) {
await new Promise(r => setTimeout(r, 2000));
Expand All @@ -35,15 +77,18 @@
return;
}
console.log(result)
terminal.write(JSON.stringify(result))
let line = filter(result);
if (line !== null) {
terminal.write(line)
}
})
.catch(err => {
if (terminal == null) {
console.error("Terminal has not been initiated correctly prior to starting worker");
return;
}
console.error(err)
terminal.write(JSON.stringify(err))
terminal.write(err)
});
}
}
Expand Down

0 comments on commit 0cc1a46

Please sign in to comment.