-
Notifications
You must be signed in to change notification settings - Fork 1
/
rpc.html
70 lines (66 loc) · 3.3 KB
/
rpc.html
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
66
67
68
69
70
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Eleos - Equihash Wallet and Messaging</title>
<link rel="stylesheet" href="resources/w3.css">
<link rel="stylesheet" href="resources/styles.css">
</head>
<body>
<div class="containerDiv w3-light-gray">
<div class="tabsBar">
<ul class="w3-navbar w3-light-gray">
<li>Set RPC Credentials</li>
</ul>
</div>
<div class="bodyDiv" id="bodyDiv">
<div class="page w3-container" id="setRPCCredentialsPage">
<form class="w3-container w3-margin-top w3-medium">
<div class="w3-container">
<label id="rpcUserField">RPC Username: </label><input class="w3-input w3-round" type="text" id="rpcUserFieldValue" title="rpcUserFieldValue">
<label id="rpcPassField">RPC Password: </label><input class="w3-input w3-round" type="password" id="rpcPassFieldValue" title="rpcPassFieldValue">
<label id="rpcIPField">RPC IP Address:</label><input class="w3-input w3-round" type="text" id="rpcIPFieldValue" title="rpcIPFieldValue">
<label id="rpcIPPort">RPC Port:</label><input class="w3-input w3-round" type="number" id="rpcPortFieldValue" title="rpcPortFieldValue">
</div>
<div class="w3-container w3-center w3-margin-top">
<button type="button" id="rpcTestButton" onclick="testRPCOpts()">Test</button>
<button type="button" id="rpcSaveButton" onclick="saveRPCOpts()">Save</button>
<button type="button" id="rpcCancelButton" onclick="window.close()">Close</button>
</div>
</form>
</div>
</div>
</div>
</body>
<script>
const {ipcRenderer} = require('electron');
function testRPCOpts() {
let rpcUser = document.getElementById("rpcUserFieldValue").value;
let rpcPass = document.getElementById("rpcPassFieldValue").value;
let rpcIP = document.getElementById("rpcIPFieldValue").value;
let rpcPort = document.getElementById("rpcPortFieldValue").value;
let jsonObject = {'jsonrpc': '1.0', 'id': 'getinfo', 'method': 'getinfo', 'params': []};
let url = 'http://' + rpcUser + ':' + rpcPass + '@' + rpcIP + ':' + rpcPort;
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if ((xhr.readyState === XMLHttpRequest.DONE) && (xhr.status === 200)) {
let resp = JSON.parse(xhr.responseText);
alert('Wallet contains a balance of ' + resp.result.balance);
}
else if ((xhr.readyState === XMLHttpRequest.DONE) && (xhr.status !== 200)) {
alert('Test failed');
}
};
xhr.open("POST", url, true);
xhr.setRequestHeader('Content-type', 'text/plain');
xhr.send(JSON.stringify(jsonObject));
}
function saveRPCOpts() {
let rpcUser = document.getElementById("rpcUserFieldValue").value;
let rpcPass = document.getElementById("rpcPassFieldValue").value;
let rpcIP = document.getElementById("rpcIPFieldValue").value;
let rpcPort = document.getElementById("rpcPortFieldValue").value;
ipcRenderer.send('save-opts', {rpcUser: rpcUser, rpcPass: rpcPass, rpcIP: rpcIP, rpcPort: rpcPort});
}
</script>
</html>