-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet_it.js
42 lines (38 loc) · 1.12 KB
/
wallet_it.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
// ## wallet ##
// This class monitor button with class '.ita .ita-button[data-wallet]'
class Wallet {
// get the qrcode data url as option for costructor
// if is present almost an ita-button[data-wallet] run add-observer
constructor(url) {
this.url = url
this.elements = document.querySelectorAll('.ita .ita-button[data-wallet]')
if (this.elements.length > 0 ) { this.add_observer() }
}
// add an observer for each vutton[data-wallet]
// on click execute wallet_get
add_observer () {
for (var u = 0; u < this.elements.length; u++) {
this.elements[u].addEventListener('click', ()=> {
this.wallet_get()
});
}
}
// Try to get qrcode data from url and populate the wallet
async wallet_get() {
try {
const response = await fetch(this.url);
if (response.ok) {
this.wallet_populate(await response.json())
}
} catch (error) {
console.log(error)
}
}
// add qrcode from data
wallet_populate(data) {
let qrcode = document.getElementById("qrcode")
qrcode.innerHTML = ''
new QRCode(qrcode, data["code"]);
console.log(data)
}
}