-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathexample.html
305 lines (274 loc) · 11.1 KB
/
example.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!doctype>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<script type="text/javascript" src="../dist/nebPay.js"></script>
<script type="text/javascript">
var NebPay = require("nebpay");
var nebPay = new NebPay();
var serialNumber;
var enableDebug = true;
function onPayClick() {
var to = document.getElementById("to").value;
var value = document.getElementById("value").value;
serialNumber = nebPay.pay(to, value, {
qrcode: {
showQRCode: document.getElementsByName("showQRCode")[0].checked
},
extension: {
openExtension: document.getElementsByName("openExtension")[0].checked //set if need show extension payment mode
},
goods: {
name: "test",
desc: "test goods"
},
gasPrice: document.getElementById("gasPrice").value ,// || "1000001",// 1000000 ,
gasLimit: document.getElementById("gasLimit").value ,// || "20001", //20000
listener: listener, //set listener for extension transaction result
debug: enableDebug
});
setTimeout(() => {
onrefreshClick(); //search transaction result from server (result upload to server by app)
}, 1000);
}
function onNrc20PayClick() {
var currency = document.getElementById("currency").value;
var to = document.getElementById("nrc20to").value;
var value = document.getElementById("nrc20value").value;
serialNumber = nebPay.nrc20pay(currency, to, value, {
qrcode: {
showQRCode: document.getElementsByName("showQRCode")[0].checked
},
extension: {
openExtension: document.getElementsByName("openExtension")[0].checked //set if need show extension payment mode
},
goods: {
name: "test",
desc: "test goods"
},
nrc20: {
contractAddress: "",
name: "demoToken",
symbol: "NRC",
decimals: 18
},
gasPrice: document.getElementById("gasPrice").value ,// || "1000001",// 1000000 ,
gasLimit: document.getElementById("gasLimit").value ,// || "20001", //20000
debug: enableDebug
});
setTimeout(() => {
onrefreshClick();
}, 1000);
}
function onDeployClick() {
var sourceType = document.getElementById("sourceType").value;
var source = document.getElementById("source").value;
var args = document.getElementById("deployArgs").value;
serialNumber = nebPay.deploy(source, sourceType, args, {
qrcode: {
showQRCode: document.getElementsByName("showQRCode")[0].checked
},
extension: {
openExtension: document.getElementsByName("openExtension")[0].checked //set if need show extension payment mode
},
goods: {
name: "test",
desc: "test goods"
},
gasPrice: document.getElementById("gasPrice").value ,// || "1000001",// 1000000 ,
gasLimit: document.getElementById("gasLimit").value ,// || "20001", //20000
});
setTimeout(() => {
onrefreshClick();
}, 1000);
}
function onCallClick() {
var to = document.getElementById("callTo").value;
var value = document.getElementById("callValue").value;
var callFunction = document.getElementById("callFunction").value;
var callArgs = document.getElementById("callArgs").value;
serialNumber = nebPay.call(to, value, callFunction, callArgs, {
qrcode: {
showQRCode: document.getElementsByName("showQRCode")[0].checked
},
extension: {
openExtension: document.getElementsByName("openExtension")[0].checked //set if need show extension payment mode
},
goods: {
name: "test",
desc: "test goods"
},
gasPrice: document.getElementById("gasPrice").value ,// || "1000001",// 1000000 ,
gasLimit: document.getElementById("gasLimit").value ,// || "20001", //20000
listener: listener, //set listener for extension transaction result
debug: enableDebug
});
setTimeout(() => {
onrefreshClick();
}, 1000);
}
function onSimulateCallClick() {
var to = document.getElementById("simulateCallTo").value;
var value = document.getElementById("simulateCallValue").value;
var callFunction = document.getElementById("simulateCallFunction").value;
var callArgs = document.getElementById("simulateCallArgs").value;
nebPay.simulateCall(to, value, callFunction, callArgs, {
qrcode: {
showQRCode: true
},
goods: {
name: "test",
desc: "test goods"
},
//callback:callbackUrl, //don't need to set callback for simulateCall
listener: listener //set listener for extension transaction result
});
document.getElementById('result').value = `app does not support simulateCall !`;
}
function onrefreshClick() {
nebPay.queryPayInfo(serialNumber,{debug: enableDebug}) //search transaction result from server (result upload to server by app)
.then(function (resp) {
document.getElementById('result').value = resp;
})
.catch(function (err) {
console.log(err);
});
}
function listener(serialNumber ,resp) {
console.log("resp: " + JSON.stringify(resp))
document.getElementById("resultFromExtension").value = `serial_number: ${serialNumber}\nresponse: ` + JSON.stringify(resp)
}
function selectMainnet () {
enableDebug = false;
}
function selectTestnet () {
enableDebug = true;
}
</script>
<style>
body {
width: 100%;
height: 100%;
}
textarea {
width: 400px;
height: 100px;
}
</style>
</head>
<body>
<h1>Demo page for Nebpay</h1>
<h3>Options</h3>
<div style="padding-left:20px">
<div>
<label>Please select MainNet ot TestNet first:</label>
<br>
<div style="padding-left:20px">
<label><input onclick="selectMainnet();" type="radio" value="mainnetUrl" name="network">MainNet</label>
<label><input onclick="selectTestnet();" checked type="radio" value="testnetUrl" name="network">TestNet</label>
<p >Note: You need to switch the network of wallet <a target="_blank" href="https://blog.nebulas.io/2018/05/10/announcement-of-official-app/">App</a> or <a target="_blank" href="https://github.com/ChengOrangeJu/WebExtensionWallet">extension</a> accordingly.</p>
</div>
</div>
<div>
<div>Other settings for <tt>options</tt>:</div>
<div style="padding-left:20px">
<div>
<label><input type="checkbox" value="showQRCode" name="showQRCode"/>showQRCode</label>
<br>
<label><input type="checkbox" value="openExtension" name="openExtension" checked="true"/>openExtension</label>
</div>
<div >
gas limit: <input type="text" id="gasLimit" placeholder="gas limit"/>
</div>
<div >
gas price: <input type="text" id="gasPrice" placeholder="gas price"/> (wei)
</div>
<br>
</div>
</div>
</div>
<h3>Nebpay API</h3>
<div style="padding-left:20px">
<div>
<div>Normal</div>
<div style="display: inline-block">
<div>to:</div>
<input type="text" id="to" placeholder="to address"/>
</div>
<div style="display: inline-block">
<div>value(nas):</div>
<input type="text" id="value" placeholder="value"/>
</div>
<button type="button" onClick="onPayClick();">pay</button>
</div>
<h5></h5>
<div>
<div>NRC20</div>
<div style="display: inline-block">
<div>currency:</div>
<input type="text" id="currency" placeholder="nrc20 currency"/>
</div>
<div style="display: inline-block">
<div>to:</div>
<input type="text" id="nrc20to" placeholder="to address"/>
</div>
<div style="display: inline-block">
<div>value(nas):</div>
<input type="text" id="nrc20value" placeholder="value"/>
</div>
<button type="button" onClick="onNrc20PayClick();">pay</button>
</div>
<h5></h5>
<div>
<div>Call</div>
<div style="display: inline-block">
<div>to:</div>
<input type="text" id="callTo" placeholder="contract address"/>
</div>
<div style="display: inline-block">
<div>value(nas):</div>
<input type="text" id="callValue" placeholder="value"/>
</div>
<div style="display: inline-block">
<div>function:</div>
<input type="text" id="callFunction" placeholder="function name"/>
</div>
<div style="display: inline-block">
<div>args:</div>
<input type="text" id="callArgs" placeholder='["arg1","arg2"]'/>
</div>
<button type="button" onClick="onCallClick();">pay</button>
</div>
<h5></h5>
<div>
<div>Simulate Call (only supported by extension)</div>
<div style="display: inline-block">
<div>to:</div>
<input type="text" id="simulateCallTo" placeholder="contract address"/>
</div>
<div style="display: inline-block">
<div>value(nas):</div>
<input type="text" id="simulateCallValue" placeholder="value"/>
</div>
<div style="display: inline-block">
<div>function:</div>
<input type="text" id="simulateCallFunction" placeholder="function name"/>
</div>
<div style="display: inline-block">
<div>args:</div>
<input type="text" id="simulateCallArgs" placeholder='["arg1","arg2"]'/>
</div>
<button type="button" onClick="onSimulateCallClick();">pay</button>
</div>
<h5></h5>
<div>
<div>pay result queried from server with serialNumber,
you need to click the refresh button th check if the tx result is uploaded to server</div>
<textarea id="result" readonly="readonly"></textarea>
<button type="button" onClick="onrefreshClick();">refresh</button>
<div>pay result listened directly from extension:</div>
<textarea id="resultFromExtension" readonly="readonly"></textarea>
</div>
</div>
</body>
</html>