Skip to content

Commit

Permalink
Remove Wallet management from the GUI and add Data creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Jan 20, 2020
1 parent bcd96c1 commit c0448ab
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 61 deletions.
6 changes: 3 additions & 3 deletions src/Interfaces/GUI/Bindings/GUIBindings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ proc addTo*(

#Grab the page we're trying to load.
case pageArg:
of "main":
page = MAIN
of "send":
page = SEND

of "data":
page = DATA

#Format it as a line of JS code.
try:
page = &"document.body.innerHTML = (`{page}`);"
Expand Down
48 changes: 16 additions & 32 deletions src/Interfaces/GUI/Bindings/PersonalBindings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,46 @@ proc addTo*(
gui: GUI
) {.forceCheck: [].} =
try:
#Get the Wallet.
gui.webview.bindProcNoArg(
#Create a Send.
gui.webview.bindProc(
"Personal",
"getWallet",
proc () {.forceCheck: [].} =
#Get the Mnemnoic and address.
var
mnemonic: JSONNode
address: JSONNode
"send",
proc (
data: string
) {.forceCheck: [].} =
#Create the Send.
var hash: JSONNode
try:
mnemonic = gui.call("personal", "getMnemonic")
address = gui.call("personal", "getAddress")
hash = gui.call("personal", "send", data.split("|")[0], data.split("|")[1])
except RPCError as e:
gui.webview.error("RPC Error", e.msg)
return

#Display the Mnemnoic and address.
#Display the hash.
var js: string
try:
js = &"""
document.getElementById("mnemonic").innerHTML = "{mnemonic.getStr()}";
document.getElementById("address").innerHTML = "{address.getStr()}";
document.getElementById("hash").innerHTML = "{hash.getStr()}";
"""
except ValueError as e:
gui.webview.error("Value Error", "Couldn't format the JS to display the Mnemonic and address: " & e.msg)
gui.webview.error("Value Error", "Couldn't format the JS to display the hash: " & e.msg)
return
if gui.webview.eval(js) != 0:
gui.webview.error("RPC Error", "Couldn't eval the JS to display the Mnemonic and address.")
return
)

#Create a Wallet from a Mnemonic.
gui.webview.bindProc(
"Personal",
"setMnemonic",
proc (
mnemonic: string
) {.forceCheck: [].} =
try:
discard gui.call("personal", "setMnemonic", mnemonic, "")
except RPCError as e:
gui.webview.error("RPC Error", e.msg)
gui.webview.error("RPC Error", "Couldn't eval the JS to display the hash.")
return
)

#Create a Send.
#Create a Data.
gui.webview.bindProc(
"Personal",
"send",
"data",
proc (
data: string
) {.forceCheck: [].} =
#Create the Send.
var hash: JSONNode
try:
hash = gui.call("personal", "send", data.split("|")[0], data.split("|")[1])
hash = gui.call("personal", "data", data)
except RPCError as e:
gui.webview.error("RPC Error", e.msg)
return
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/GUI/GUI.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ proc newGUI*(
var js: string
try:
js = &"""
document.body.innerHTML = `{MAIN}`;
document.body.innerHTML = `{SEND}`;
"""
except ValueError as e:
doAssert(false, "Couldn't format the JS to load the main page: " & e.msg)
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/GUI/objects/GUIObj.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import json

#Constants of the HTML.
const
MAIN*: string = staticRead("../static/Main.html")
SEND*: string = staticRead("../static/Send.html")
DATA*: string = staticRead("../static/Data.html")

#GUI object.
type GUI* = ref object
Expand Down
22 changes: 22 additions & 0 deletions src/Interfaces/GUI/static/Data.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<html>
<body>
<h1>Send</h1>
<button onclick="GUI.load('send')">Send</button>
<button onclick="GUI.load('data')">Data</button>
<button onclick="GUI.quit()">Quit</button>
<hr>

Data: <input type="text" id="data"></input>
<br>
<button onclick="
var data = document.getElementById('data').value;
Personal.data(data);
">Publish</button>

<br>
<hr>
<br>

<div id="hash"></div>
</body>
</html>
23 changes: 0 additions & 23 deletions src/Interfaces/GUI/static/Main.html

This file was deleted.

2 changes: 1 addition & 1 deletion src/Interfaces/GUI/static/Send.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<html>
<body>
<h1>Send</h1>
<button onclick="GUI.load('main')">Main</button>
<button onclick="GUI.load('send')">Send</button>
<button onclick="GUI.load('data')">Data</button>
<button onclick="GUI.quit()">Quit</button>
<hr>

Expand Down

0 comments on commit c0448ab

Please sign in to comment.