forked from getAlby/bitcoin-connect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
244 lines (231 loc) · 7.18 KB
/
index.html
File metadata and controls
244 lines (231 loc) · 7.18 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Lit + TS</title>
<script type="module" src="../../src/index.ts"></script>
<script src="https://cdn.jsdelivr.net/npm/@getalby/lightning-tools@latest/dist/index.browser.js"></script>
<script>
window.addEventListener('bc:connected', () =>
console.info('Received connected event from html')
);
window.addEventListener('bc:connecting', () =>
console.info('Received connecting event from html')
);
window.addEventListener('bc:disconnected', () =>
console.info('Received disconnected event from html')
);
window.addEventListener('bc:modalopened', () =>
console.info('Received modalopened event from html')
);
window.addEventListener('bc:modalclosed', () =>
console.info('Received modalclosed event from html')
);
const bcTheme = window.localStorage.getItem('bcTheme');
if (bcTheme) {
window.bcDarkMode = 'class';
document.documentElement.classList.add(bcTheme);
} else {
document.documentElement.classList.add('system');
}
async function payInvoice() {
try {
const ln = new window.lightningTools.LightningAddress(
'hello@getalby.com'
);
await ln.fetch();
const invoice = await ln.requestInvoice({satoshi: 1});
const result = await window.webln.sendPayment(invoice.paymentRequest);
alert('PAID! ' + JSON.stringify(result));
} catch (error) {
console.error(error);
alert('Failed to pay: ' + error);
}
}
(async () => {
const ln = new window.lightningTools.LightningAddress(
'hello@getalby.com'
);
await ln.fetch();
const invoice = await ln.requestInvoice({satoshi: 1});
document
.getElementsByTagName('bc-send-payment')[0]
.setAttribute('invoice', invoice.paymentRequest);
})();
</script>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
margin: 0px;
@media (prefers-color-scheme: dark) {
background-color: black;
color: white;
}
}
.dark body {
background-color: black;
color: white;
}
.light body {
background-color: white;
color: black;
}
.dark #button-theme-dark {
background-color: skyblue;
}
.light #button-theme-light {
background-color: skyblue;
}
.system #button-theme-system {
background-color: skyblue;
}
.theme-geyser {
--bc-color-brand: #21ecc7;
--bc-brand-mix: 75%;
}
.theme-orange {
--bc-color-brand: #ff8008;
}
.theme-stacker-news {
--bc-color-brand: #fada5e;
--bc-brand-mix: 75%;
}
.theme-white {
--bc-color-brand: #ffffff;
--bc-brand-mix: 50%;
}
.theme-black {
--bc-color-brand: #000000;
--bc-brand-mix: 50%;
}
</style>
</head>
<body>
<h1>Programmatic Access</h1>
<button onclick="window.bitcoinConnect.launchModal()">Open modal</button>
<button
onclick="const invoiceToPay = window.prompt('paste invoice'); window.bitcoinConnect.launchModal({invoice: invoiceToPay})"
>
Open modal to pay invoice
</button>
<bc-modal id="first-modal"></bc-modal>
<br /><br />
<a href="balance.html">Balance tester</a>
<h1>Light / Dark Mode</h1>
<button
id="button-theme-system"
onclick="window.localStorage.removeItem('bcTheme');window.location.reload();"
>
System
</button>
<button
id="button-theme-dark"
onclick="window.localStorage.setItem('bcTheme', 'dark');window.location.reload();"
>
Force Dark
</button>
<button
id="button-theme-light"
onclick="window.localStorage.setItem('bcTheme', 'light');window.location.reload();"
>
Force Light
</button>
<h1>Settings</h1>
<p>Name (e.g. Zap.Stream)</p>
<input
id="app-name"
onchange="localStorage.setItem('app-name', document.getElementById('app-name').value); window.location.reload()"
/>
<p>Filters (e.g. nwc)</p>
<input
id="filters"
onchange="localStorage.setItem('filters', document.getElementById('filters').value); window.location.reload()"
/>
<p>Invoice</p>
<input
id="invoice"
onchange="localStorage.setItem('invoice', document.getElementById('invoice').value); window.location.reload()"
/>
<br />
<br />
<h1>Components</h1>
<h2>Button</h2>
<bc-button id="first-button"></bc-button>
<br /><br />
<div class="theme-geyser">
<bc-button></bc-button>
</div>
<br /><br />
<div class="theme-orange">
<bc-button></bc-button>
</div>
<br /><br />
<div class="theme-stacker-news">
<bc-button></bc-button>
</div>
<br /><br />
<div class="theme-white">
<bc-button></bc-button>
</div>
<br /><br />
<div class="theme-black">
<bc-button></bc-button>
</div>
<h2>Modal header</h2>
<div style="width: 448px">
<bc-modal-header></bc-modal-header>
</div>
<h2>Navbar</h2>
<div style="width: 448px">
<bc-navbar heading="Custom Heading"></bc-navbar>
</div>
<h2>Router outlet</h2>
<div style="width: 448px">
<bc-router-outlet></bc-router-outlet>
</div>
<h2>Request Payment Screen</h2>
<div style="width: 448px; border: 1px solid black">
<bc-send-payment
invoice="lnbc10n1pj4g7ugpp5h0lld9qzh06ngn8ur756rva0ntfdfg34h298337rljjyztxy8rfqhp50kncf9zk35xg4lxewt4974ry6mudygsztsz8qn3ar8pn3mtpe50scqzzsxqyz5vqsp5lwlnu7xjs7hj7vltx7rhzsjf60l5mwckuw93qngjrz7sdhdkw7gs9qyyssqzy543rxhkdtncjrmuzlz4lrh2eauldawa9np5yysh7dhqhv8kaahydurha2cfelr7t6wt33xse7fdykupnjv36na6x6crrhy53lyg6cqf2jhjj"
></bc-send-payment>
</div>
<h2>Start screen</h2>
<div style="width: 448px">
<bc-start></bc-start>
</div>
<h2>Help screen</h2>
<div style="width: 448px; border: 1px solid black">
<bc-help></bc-help>
</div>
<h2>NWC screen</h2>
<div style="width: 448px; border: 1px solid black">
<bc-nwc></bc-nwc>
</div>
<h2>Connector List</h2>
<bc-connector-list></bc-connector-list>
<h2>Pay an invoice</h2>
<button onclick="payInvoice()">Pay</button>
<script>
const appName = localStorage.getItem('app-name');
document.getElementById('app-name').value = appName;
if (appName) {
document
.getElementById('first-button')
.setAttribute('app-name', appName);
}
const filters = localStorage.getItem('filters');
document.getElementById('filters').value = filters;
if (filters) {
document
.getElementById('first-button')
.setAttribute('filters', filters);
}
const invoice = localStorage.getItem('invoice');
document.getElementById('invoice').value = invoice;
if (invoice) {
document.getElementById('first-modal').setAttribute('invoice', invoice);
}
</script>
</body>
</html>