-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOTC2.htm
423 lines (415 loc) · 18.4 KB
/
OTC2.htm
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
<!DOCTYPE html>
<script>
//To run locally:
//python -m SimpleHTTPServer 8000
//http://localhost:8000/(file-you-want-to-run).htm
//Other notes(if you need to test cross-origin):
//about:config
//security.fileuri.strict_origin_policy
//privacy.file_unique_origin
</script>
<meta charset="UTF-8" />
<html>
<body>
NightTrader OTC Buy calculator
<select id="coin">
<option>Sell Bitcoin</option>
<option>Sell Ethereum</option>
</select>
<br>
<div id="buydiv"></div>
<div id="buyQR"></div>
<div id="timerdiv"></div>
<tr>
<td colspan="2"><input class="textBox" id="buyamount" type="text" maxlength="30" required/></td>
</tr>
<select id="conversion">
<option>USD</option>
<option>Pesos</option>
<option>Coins</option>
</select>
<input type="button" value="Buy $" onclick="calculatePrice()">
<input type="button" value="Email" onclick="email()">
<input type="button" value="Send DAI" onclick="sendDAI()">
<input type="button" value="Clear" onclick="clearit()">
<tr>
<br>Dollar to peso exchange rate(selling dollars):<br>
<td colspan="2"><input class="textBox" id="exchangerate" type="text" maxlength="50" required/></td>
</tr>
<tr>
<br>Email Receipt(optional):<br>
<td colspan="2"><input class="textBox" id="emailreceipt" type="text" maxlength="50" required/></td>
</tr>
<tr>
<br>Address:<br>
<td colspan="2"><input class="textBox" id="manualaddress" type="text" maxlength="50" style="width: 300px;" required/></td>
</tr>
<div id="hiddendiv">
<tr>
<br>Custom bid price(to confirm calculation):<br>
<td colspan="2"><input class="textBox" id="custombid" type="text" maxlength="50" required/></td>
</tr>
</div>
<script>
function hide (elements) {
document.getElementById('custombid').value="";
elements = elements.length ? elements : [elements];
for (var index = 0; index < elements.length; index++) {
elements[index].style.display = 'none';
}
}
function show (elements, specifiedDisplay) {
elements = elements.length ? elements : [elements];
for (var index = 0; index < elements.length; index++) {
elements[index].style.display = specifiedDisplay || 'block';
}
}
hide(document.getElementById('hiddendiv'));
</script>
<tr>
<br>Casa de cambio email:<br>
<td colspan="2"><input class="textBox" id="emailcasa" type="text" maxlength="50" style="width: 300px;" required/></td>
</tr>
<input type="button" value="Login" onclick="login()">
<input type="button" value="Refresh Balance" onclick="checkbalances()">
<tr>
<br>ETH Password:<br>
<td colspan="2"><input class="textBox" id="password" type="password" maxlength="50" style="width: 300px;" required/></td>
</tr>
<div id="accountInfo">Please log in</div><br>
<div id="notificationdiv"></div><br>
<div id="QRdiv">No QR code detected.</div>
<br><br>
<script src="./jsQR.js"></script>
<div id="loadingMessage">🎥 Unable to access video stream (please make sure you have a webcam enabled)</div>
<canvas id="canvas" hidden></canvas>
<div id="output" hidden>
<div id="outputMessage">Scanning...</div>
<div hidden><b>Data:</b> <span id="outputData"></span></div>
</div>
<script>
var video = document.createElement("video");
var canvasElement = document.getElementById("canvas");
var canvas = canvasElement.getContext("2d");
var loadingMessage = document.getElementById("loadingMessage");
var outputContainer = document.getElementById("output");
var outputMessage = document.getElementById("outputMessage");
var outputData = document.getElementById("outputData");
function drawLine(begin, end, color) {
canvas.beginPath();
canvas.moveTo(begin.x, begin.y);
canvas.lineTo(end.x, end.y);
canvas.lineWidth = 4;
canvas.strokeStyle = color;
canvas.stroke();
}
// Use facingMode: environment to attemt to get the front camera on phones
navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" } }).then(function(stream) {
video.srcObject = stream;
video.setAttribute("playsinline", true); // required to tell iOS safari we don't want fullscreen
video.play();
requestAnimationFrame(tick);
});
function tick() {
loadingMessage.innerText = "⌛ Loading video..."
if (video.readyState === video.HAVE_ENOUGH_DATA) {
loadingMessage.hidden = true;
canvasElement.hidden = false;
outputContainer.hidden = false;
canvasElement.height = video.videoHeight;
canvasElement.width = video.videoWidth;
canvas.drawImage(video, 0, 0, canvasElement.width, canvasElement.height);
var imageData = canvas.getImageData(0, 0, canvasElement.width, canvasElement.height);
var code = jsQR(imageData.data, imageData.width, imageData.height, {
inversionAttempts: "dontInvert",
});
if (code) {
drawLine(code.location.topLeftCorner, code.location.topRightCorner, "#FF3B58");
drawLine(code.location.topRightCorner, code.location.bottomRightCorner, "#FF3B58");
drawLine(code.location.bottomRightCorner, code.location.bottomLeftCorner, "#FF3B58");
drawLine(code.location.bottomLeftCorner, code.location.topLeftCorner, "#FF3B58");
outputMessage.hidden = true;
outputData.parentElement.hidden = false;
outputData.innerText = code.data;
document.getElementById("QRdiv").innerHTML = code.data;
document.getElementById('manualaddress').value = code.data;
} else {
outputMessage.hidden = false;
outputData.parentElement.hidden = true;
}
}
requestAnimationFrame(tick);
}
</script>
<script src="./web3.min.js"></script>
<script src="./users.js"></script>
<script type="text/javascript" src="./human_standard_token_abi.js"></script>
<script type="text/javascript" src="./OTCabi.js"></script>
<div id="EthData"></div>
<script type="text/javascript">
web3 = new Web3("https://cloudflare-eth.com");
var tokenInst = new web3.eth.Contract(human_standard_token_abi,"0x6B175474E89094C44Da98b954EedeAC495271d0F");
var contractInst = "";
myAccount = "";
DAIBalance = 0;
ETHBalance = 0;
destaddy = "";
owneraddy = "";
pk = "";
locked = "";
function sendDAI() {
if (contractInst == "") {
document.getElementById('notificationdiv').innerHTML="Contract not loaded!";
}
if (document.getElementById('manualaddress').value == "withdraw") {
if (document.getElementById("conversion").value != "USD") {
document.getElementById('notificationdiv').innerHTML="Withdraw amount must be denominated in USD!";
}
amount2 = document.getElementById("buyamount").value;
amt = web3.utils.toWei(String(amount2));
console.log(amt);
contractInst.methods.moveFunds(owneraddy,amt).send({"from":myAccount,"gasLimit": 250000});
}
else {
amt = web3.utils.toWei(String(globamt));
console.log(amt);
contractInst.methods.moveFunds(destaddy,amt).send({"from":myAccount,"gasLimit": 250000});
}
document.getElementById('notificationdiv').innerHTML="";
}
async function login() {
if (window.ethereum) {
console.log("connecting");
await window.ethereum.send('eth_requestAccounts');
window.web3 = new Web3(window.ethereum);
console.log("success");
} else {
return;
}
em=document.getElementById('emailcasa').value.toLowerCase();
pw=document.getElementById('password').value;
if (pw.length < 12) {
document.getElementById('notificationdiv').innerHTML="Password needs to be a minimum of 12 characters";
return;
}
pk=web3.utils.sha3(Array(2000 + 1).join(em + pw));
myAccount1 = web3.eth.accounts.privateKeyToAccount(pk);
myAccount=myAccount1.address;
if (myAccount in registeredusers) {
checkbalances();
document.getElementById('notificationdiv').innerHTML="";
} else {
console.log("Email hash: " + web3.utils.sha3(document.getElementById('emailcasa').value.toLowerCase()));
console.log("ETH address(gas): " + myAccount);
document.getElementById('notificationdiv').innerHTML="Account not found! Please check email/password";
myAccount = "";
contractInst = "";
pk = "";
destaddy = "";
owneraddy = "";
locked = "";
document.getElementById('accountInfo').innerHTML="Please log in";
return;
}
contractInst = new web3.eth.Contract(OTCabi,registeredusers[myAccount]);
document.getElementById('password').value="";
pw="";
}
async function checkbalances() {
timest=0;
await tokenInst.methods.balanceOf(registeredusers[myAccount]).call().then(function (bal) {
DAIBalance=web3.utils.fromWei(bal, "ether");
})
await contractInst.methods.destinations(0).call().then(function (dest) {
destaddy=dest;
})
await contractInst.methods.destinations(1).call().then(function (dest) {
owneraddy=dest;
})
await contractInst.methods.islocked().call().then(function (islocked) {
locked=islocked;
})
await contractInst.methods.locktime().call().then(function (thetime) {
timest=thetime;
})
if (myAccount != "") {
await web3.eth.getBalance(myAccount, function(err, result) {
if (err) {
//Can show error to console if you want
} else {
ETHBalance = web3.utils.fromWei(result, "ether");
}})
}
document.getElementById('accountInfo').innerHTML="DAI Balance: "+DAIBalance+"<br>"+"ETH Balance: "+ETHBalance+"<br>"+"ETH Address(used for gas): "+myAccount+"<br>";
if (parseFloat(locked)==parseFloat(0)) {
document.getElementById('accountInfo').innerHTML+="WARNING: Contract is unlocked. Please ask NT to lock the contract.";
} else {
thetime = Math.floor((new Date().getTime()) / 1000);
if ((parseFloat(thetime) - parseFloat(timest)) > parseFloat(13149000)) {
document.getElementById('accountInfo').innerHTML+="WARNING: Contract locktime is about to expire. Please ask NT to lock the contract.";
}
}
if (parseFloat(ETHBalance) <= parseFloat(0.005)) {
document.getElementById('notificationdiv').innerHTML="Ethereum balance too low, please refill to sustainable levels.";
}
}
setInterval(checkbalances, 120000);
</script>
</body>
<script src="./rates.js"></script>
<script>
var quoted = 0;
var globcontent = "";
var globamt = 0;
function calculatePrice(){
amount=document.getElementById('buyamount').value;
if (amount == "show") {
show(document.getElementById('hiddendiv'));
return;
}
if (amount == "showpk") {
console.log(pk);
return;
}
if (amount == "unlock") {
contractInst.methods.unlock().send({"from":myAccount,"gasLimit": 250000});
return;
}
var coin = document.getElementById("coin");
if (coin.value == "Sell Bitcoin") {
coin = "BTC";
}
if (coin.value == "Sell Ethereum") {
coin = "ETH";
}
var burl = "https://api.binance.com";
var query = '/api/v1/ticker/24hr';
query += '?symbol='+coin+'DAI';
var url = burl + query;
var ourRequest = new XMLHttpRequest();
ourRequest.open('GET',url,true);
ourRequest.onload = function(){
binancedata=JSON.parse(ourRequest.responseText);
binancedata = binancedata.askPrice;
customrate = document.getElementById('custombid').value;
if (customrate != "") {
binancedata = customrate;
}
var conversion = document.getElementById("conversion").value;
if (conversion == "Pesos") {
rate=document.getElementById('exchangerate').value;
amount=parseFloat(parseFloat(amount)/parseFloat(rate)).toFixed(0);
}
if (conversion == "Coins") {
btctotal=amount;
amount=parseFloat(parseFloat(binancedata)*parseFloat(amount)).toFixed(0);
} else {
btctotal = parseFloat(parseFloat(amount) / parseFloat(binancedata)).toFixed(8);
}
amount=parseFloat(amount);
if (parseFloat(ETHBalance) <= parseFloat(0.005)) {
document.getElementById('notificationdiv').innerHTML="Ethereum balance too low, please refill to sustainable levels.";
}
if (parseFloat(amount) > parseFloat(DAIBalance)) {
clearfields();
document.getElementById('notificationdiv').innerHTML="Not enough DAI!";
return;
}
if (coin == "BTC") {
if (amount < parseFloat(rates.minBTCbuy)) {
clearfields();
document.getElementById('notificationdiv').innerHTML="Amount under minimum: " + rates.minBTCbuy;
return;
}
}
if (coin == "ETH") {
if (amount < parseFloat(rates.minERCbuy)) {
clearfields();
document.getElementById('notificationdiv').innerHTML="Amount under minimum: " + rates.minERCbuy;
return;
}
}
document.getElementById('notificationdiv').innerHTML="";
var totalcom = 10;
var comcasa = 3;
var comnt = 7;
for(var i = 0, size = rates.rates.length; i < size ; i++) {
if (amount > parseFloat(rates.rates[i][0])) {
totalcom = rates.rates[i][1] + rates.rates[i][2];
comcasa = rates.rates[i][1];
comnt = rates.rates[i][2];
}
}
//https://api.binance.com/sapi/v1/capital/deposit/address
commission = parseFloat((parseFloat(amount)*parseFloat(totalcom))/parseFloat(100)).toFixed(0);
commissionCasa = parseFloat((parseFloat(amount)*parseFloat(comcasa))/parseFloat(100)).toFixed(0);
commissionNT = parseFloat(parseFloat(commission) - parseFloat(commissionCasa)).toFixed(0);
daitotal = parseFloat(parseFloat(amount)-parseFloat(commissionCasa)).toFixed(0);
payout = parseFloat((parseFloat(amount) - parseFloat(commission)) / parseFloat(binancedata)).toFixed(8);
document.getElementById('buydiv').innerHTML = "";
mycontent = "";
mycontent += "Amount of DAI to send(cashier): " + daitotal.toString();
mycontent += "<br>Commission in dollars(total): " + commission + " (Casa:" + commissionCasa + ")(NT/fees:" + commissionNT + ")";
globcontent = mycontent;
globcontent = globcontent.replace(/<br>/g,"%0A");
globcontent += "%0ABinance/exchange "+coin+" ask price: " + binancedata + "%0A";
globcontent += "%0APayout in "+coin+": " + payout;
mycontent += "<br>Payout in "+coin+": " + payout;
document.getElementById('buydiv').innerHTML = mycontent;
//document.getElementById("buyQR").innerHTML = "";
//var elem = document.createElement("img");
//QRcontent="https://chart.googleapis.com/chart?chs=250x250&chld=L|2&cht=qr&chl=dai:"+destaddy+"?amount="+daitotal
//elem.setAttribute("src", QRcontent);
//elem.setAttribute("height", "250");
//elem.setAttribute("width", "250");
//document.getElementById("buyQR").appendChild(elem);
//document.getElementById('buyQR').innerHTML += "<br>DAI deposit address: " + destaddy + "<br>";
//mycontent+="%0ADAI deposit address: " + destaddy;
globamt = daitotal;
quoted = 600;
clearInterval(interval);
interval = setInterval(clearfields, 600000);
}
ourRequest.send();
}
function clearit() {
if (confirm("Are you sure you want to clear everything?")) {
clearfields();
}
}
function clearfields() {
document.getElementById('buydiv').innerHTML = "";
document.getElementById("buyQR").innerHTML = "";
document.getElementById('timerdiv').innerHTML = "";
document.getElementById('emailreceipt').value="";
document.getElementById('QRdiv').innerHTML="No QR code detected.";
document.getElementById('notificationdiv').innerHTML="";
document.getElementById('custombid').value="";
document.getElementById('manualaddress').value="";
quoted = 0;
globcontent = "";
globamt = "";
pk = "";
}
interval = setInterval(clearfields, 600000);
function quotetime() {
if (quoted != 0) {
quoted -= 1;
document.getElementById('timerdiv').innerHTML = "Seconds until quote expires: " + quoted;
}
}
setInterval(quotetime, 1000);
function email() {
qrval=document.getElementById('QRdiv').innerHTML;
if (document.getElementById('manualaddress').value==""){
document.getElementById('QRdiv').innerHTML="ERROR: No QR code detected.";
return;
}
myemail=globcontent+"%0APayout address: "+document.getElementById('manualaddress').value;
window.location.href = "mailto:[email protected],"+document.getElementById('emailreceipt').value+"?subject=NightTrader OTC notification&body="+myemail;
document.getElementById('emailreceipt').value="";
document.getElementById('manualaddress').value="";
document.getElementById('QRdiv').innerHTML="No QR code detected.";
}
</script>
</html>