forked from Samourai-Wallet/samourai-dojo
-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathpairing.js
More file actions
62 lines (51 loc) · 1.98 KB
/
Copy pathpairing.js
File metadata and controls
62 lines (51 loc) · 1.98 KB
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
const screenPairingScript = {
initPage: () => {
document.querySelector('#btn-copy-payload').addEventListener('click', () => {
screenPairingScript.copyPayload()
})
document.querySelector('#btn-regenerate-payload').addEventListener('click', () => {
screenPairingScript.displayQRPairing()
})
},
copyPayload: () => {
const payload = document.querySelector('#dojo-pairing-payload')
navigator.clipboard.writeText(payload.value).then(() => {
lib_msg.displayInfo('Pairing payload copied to clipboard')
}).catch((error) => {
lib_errors.processError(error)
})
},
preparePage: () => {
screenPairingScript.displayQRPairing()
},
/**
* @returns {Promise<object | null>}
*/
loadPairingPayloads: () => {
lib_msg.displayMessage('Loading pairing payloads...')
return lib_api.getPairingInfo()
.then((apiInfo) => {
const result = apiInfo
result.pairing.url = `${window.location.protocol}//${window.location.host}${conf.api.baseUri}`
lib_msg.cleanMessagesUi()
return result
})
.catch((error) => {
lib_errors.processError(error)
return null
})
},
displayQRPairing: () => {
screenPairingScript.loadPairingPayloads().then(
(result) => {
if (result) {
document.querySelector('#qr-pairing').innerHTML = '' // clear qrcode first
document.querySelector('#dojo-pairing-payload').value = JSON.stringify(result, null, 4)
const pairingQrcode = new QRCode({ content: JSON.stringify(result), join: true, height: 256, width: 256 }).svg()
document.querySelector('#qr-pairing').innerHTML = pairingQrcode
}
}
)
}
}
screenScripts.set('#screen-pairing', screenPairingScript)