-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswapbutton.js
113 lines (76 loc) · 2.54 KB
/
swapbutton.js
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
/*
<div class="withbutton"
litecoin-addr = "placeholder123"
pairID = "LTC/BTC"
orderSide = "buy"
invoiceAmount = "100000">
</div>
*/
var qrCode;
if (typeof localStorage === "undefined" || localStorage === null) {
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
}
if (typeof localStorage === "undefined" || localStorage === null) {
var LocalStorage = require('node-localstorage').LocalStorage;
localStorage = new LocalStorage('./scratch');
}
const myConfig =
{
pairId: "LTC/BTC",
orderSide: "buy",
invoiceAmount: 10000,
claimPublicKey: "a9142f7150b969c9c9fb9094a187f8fb41d617a65e20876300670171b1752102e317e5607e757e9c4448fe458876d7e361222d2cbee33ece9e3a7b2e2359be4d68ac"
}
function createQRCode() {
var invoiceLength = 26;
var qr = qrcode(26, "L");
qr.addData(localStorage.getItem('data'));
qr.make();
qrCode = qr.createImgTag(6, 6);
}
function showQRCode() {
var element = document.getElementById("qrcode");
var invoiceText = document.getElementById("invoice-text")
createQRCode();
element.innerHTML = qrCode;
invoiceText.innerHTML = localStorage.getItem("data");
var size = "200px";
var qrElement = element.children[0];
qrElement.style.height = size;
qrElement.style.width = size;
}
function createreverseswap(config) {
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState === 4) {
try {
var json = JSON.parse(request.responseText);
if (request.status === 201) {
localStorage.setItem('data', json.invoice)
showQRCode();
}
} catch (exception) {
console.error(exception)
}
}
};
request.open('POST', 'https://testnet.boltz.exchange/api/createreverseswap', true);
request.setRequestHeader('Content-Type', 'application/json');
request.send(JSON.stringify(config));
}
// creating a dialog
window.onload = function(){
(function() {
createreverseswap(myConfig);
var paywithlightning = document.getElementById('pay');
var invoice = document.getElementById('invoice');
// "payWithLightning" button opens the <dialog> modally
paywithlightning.addEventListener('click', function onOpen() {
if (typeof invoice.showModal === "function") {
invoice.showModal();
} else {
alert("Update your browser")
}
});
})();
}