-
Notifications
You must be signed in to change notification settings - Fork 14
/
web_app_loader.py
39 lines (39 loc) · 1.38 KB
/
web_app_loader.py
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
# Load the browser side of the GUI. 100% totally temporary code to demonstrate the architecture.
WEB_APP_LOADER: str = """
<html>
<head>
<script>
if(typeof(EventSource)!="undefined") {
let source = new EventSource("/event-stream");
source.onmessage=function(event) {
console.log(event);
document.getElementById("result").innerHTML += event.data + "<br>";
}
}
else {
document.getElementById("result").innerHTML="No EventSource. Please upgrade your browser and try again.";
}
function showWallet() {
// simple function to demonstrate API call with browser-side processing
fetch('/wallet')
.then((response) => response.json())
.then(data => document.getElementById("result").innerHTML +=
'Your wallet has this many keys: ' + data.size + "<br>")
}
function showHeight() {
// simple function to demonstrate API call with browser-side processing
fetch('/height')
.then((response) => response.json())
.then(data => document.getElementById("result").innerHTML +=
'Your current blockchain height: ' + data.height + "<br>")
}
</script>
</head>
<body>
(please don't click these until initialization is complete):
<a href="javascript:showWallet()">show wallet</a> | <a href="javascript:showHeight()">show height</a>
<p>IMPORTANT: Do not launch more than one browser window.</p>
<div id="result">Loading...</div>
</body>
</html>
"""