Skip to content

Instantly share code, notes, and snippets.

@beber89
beber89 / renderer.go
Created September 17, 2019 15:28
renderer.go
// renderPage reloads elements of the page when change to wallet occurs
func RenderPage() {
wlt := *GetWallet()
document := js.Global().Get("document")
chainView := (*wlt.GetBlockchain()).Draw()
if chn := document.Call("getElementById", "chain"); chn != js.Null() {
document.Call("getElementById", "blockchain-placeholder").Call("removeChild", chn)
}
document.Call("getElementById", "blockchain-placeholder").Call("appendChild", chainView)
networthLabel := document.Call("getElementById", "networth")
@beber89
beber89 / index.html
Created September 16, 2019 22:27
index.html
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="styles.css" media="screen" />
<script src="wasm_exec.js"></script>
<script>
const go = new Go();
WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {go.run(result.instance);});
</script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
@beber89
beber89 / actions.go
Created September 16, 2019 22:03
web/actions.go - package web
func RegisterCallbacks() {
js.Global().Set("reward", js.FuncOf(reward))
js.Global().Set("buyCommodity", js.FuncOf(buyCommodity))
js.Global().Set("networth", js.FuncOf(networth))
js.Global().Set("changeUser", js.FuncOf(changeUser))
js.Global().Set("sendSliderValToWasm", js.FuncOf(sendSliderValToWasm))
}
var (
merchant string