-
Notifications
You must be signed in to change notification settings - Fork 1
/
selector.html
118 lines (103 loc) · 2.64 KB
/
selector.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
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
body {
font-family: sans-serif;
margin: 0;
}
.walletItem {
background: #FFFFFF;
border-bottom: solid 1px #DDDDDD;
padding: 4px 0;
list-style: none;
}
.walletItem:hover {
background: #EEEEEE;
border-bottom: solid 1px #DDDDDD;
cursor: pointer;
padding: 4px 0;
list-style: none;
}
.walletUrl {
color: #555555;
}
ul {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div id="content"></div>
<template id="permission">
<div>
<div>BurnerConnect allows you to use your Burner Wallet accounts on other dapps</div>
<button>Connect</button>
</div>
</template>
<template id="list">
<ul>
</ul>
</template>
<template id="listItem">
<li class="walletItem">
<div></div>
<div class="walletUrl"></div>
</li>
</template>
<script>
var STORAGE_KEY = 'burner-hub-wallets';
var content = document.querySelector('#content');
var defaultWallets = [];
var defaultRegex = /^#wallets=([\w\d%./\-]+)$/;
if (defaultRegex.test(location.hash)) {
defaultWallets = JSON.parse(decodeURIComponent(defaultRegex.exec(location.hash)[1]))
}
function testPermissions() {
try {
localStorage.setItem('test', 'test');
return Promise.resolve(true);
} catch (e) {
return Promise.resolve(false);
}
}
function showList() {
var listClone = document.querySelector('#list').content.cloneNode(true);
var ul = listClone.querySelector('ul');
wallets = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
var addedOrigins = {};
var allWallets = wallets.concat(defaultWallets);
allWallets.forEach(function(wallet) {
if (addedOrigins[wallet.origin]) {
return;
}
addedOrigins[wallet.origin] = true;
var item = document.querySelector('#listItem').content.cloneNode(true);
item.querySelector('li').addEventListener('click', function() {
window.parent.postMessage({ message: 'walletSelected', wallet: wallet }, '*');
});
var rows = item.querySelectorAll('div');
rows[0].textContent = wallet.name;
rows[1].textContent = wallet.origin;
ul.appendChild(item);
});
if (allWallets.length === 0) {
var empty = document.createElement('li');
empty.innerText = 'No wallets found';
ul.appendChild(empty);
}
content.appendChild(listClone);
window.parent.postMessage({ message: 'setHeight', height: document.body.clientHeight }, '*');
}
testPermissions().then(function(hasPermission) {
if (hasPermission || defaultWallets.length > 0) {
showList();
} else {
content.innerHTML = 'Unfortionately, your browser does not support BurnerConnect';
}
});
</script>
</body>
</html>