-
Notifications
You must be signed in to change notification settings - Fork 103
/
index.html
128 lines (109 loc) · 3.74 KB
/
index.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html>
<script src='waxjs.js'></script>
<title>waxjs demo</title>
<body>
<h1>wax signing lib demo and tester</h1>
<p>As well as being a demo, this is used by the test cases in the test folder.</p>
<p>This sample dapp operates the <b>test.wax</b> contract's <b>update</b> action.</p>
<p>The source code for this contract can be found in the resources/test-contract folder.</p>
<p>Click the buttons</p>
<button id="login" onclick=login() >WAX Login</button><br><br>
<hr>
<label>updater:</label><input id="updater"><br><br>
<label>message:</label><input id="message"><br><br>
<label>fail:</label><input type="checkbox" id="fail" value="fail"><br><br>
<button id="sign" onclick=sign() >Sign transaction</button><br><br>
<label>Current Message</label><h3 id="current"></h3><br><br>
<hr>
<button id="proof" onclick=proof() >Proof</button><br><br>
<hr>
<label>Transaction Results</label>
<h2 id="response"></h2>
<script>
const wax = new waxjs.WaxJS({
rpcEndpoint: 'https://wax.greymass.com',
chainId: '1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4'
});
// const wax = new waxjs.WaxJS({
// rpcEndpoint: 'http://wax-all.test:8888',
// tryAutoLogin: true,
// waxSigningURL: 'http://all-access.wax.test:8113',
// waxAutoSigningURL: 'http://idm.wax.test:8113/v1/accounts/auto-accept/'
// });
async function login() {
try {
const userAccount = await wax.login('noncerandom');
document.getElementById('updater').value = userAccount;
await getCurrentMessage();
if (wax.user.isProofVerified) {
document.getElementById('response').append(' User login proof is valid');
} else {
document.getElementById('response').append(' User login proof is invalid');
}
} catch(e) {
document.getElementById('response').append(e.message);
}
}
async function sign() {
if(!wax.api) {
return document.getElementById('response').append('* Login first *');
}
const updater = document.getElementById('updater').value;
const message = document.getElementById('message').value;
const fail = document.getElementById('fail').checked;
try {
const result = await wax.api.transact({
actions: [{
account: 'test.wax',
name: 'update',
authorization: [{
actor: wax.userAccount,
permission: 'active',
}],
data: {
updater,
message,
fail,
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30
});
document.getElementById('response').append(JSON.stringify(result));
await new Promise(resolve => setTimeout(resolve, 1000));
await getCurrentMessage();
} catch(e) {
document.getElementById('response').append(e.message);
}
}
async function getCurrentMessage() {
const res = await wax.rpc.get_table_rows({
json: true,
code: 'test.wax',
scope: 'test.wax',
table: 'messages',
lower_bound: wax.userAccount,
upper_bound: wax.userAccount,
});
const message = res.rows[0] ? res.rows[0].message : `<No message is set for ${wax.userAccount}>`;
document.getElementById('current').textContent = message;
}
async function proof() {
try {
const verifyResult = await wax.waxProof('abc', true);
if (verifyResult) {
document.getElementById('response').append(' Proof is valid');
} else {
document.getElementById('response').append(' Proof is invalid');
}
} catch(e) {
document.getElementById('response').append(e.message);
}
}
// set a random value to the initial message value
document.getElementById('message').value = Math.random().toString(36).substring(2);
</script>
</body>
</html>