This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
index.html
315 lines (288 loc) · 10.3 KB
/
index.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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AlgoSigner dApp</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<link rel="shortcut icon" href="assets/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/tomorrow.min.css">
<script src="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
<link rel="stylesheet" type="text/css" href="assets/style.css">
</head>
<body>
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="index.html"><img src="assets/logotype.png" height="28"></a>
</div>
<div class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item" href="payment.html">Payment Txn</a>
<a class="navbar-item" href="asset-create.html">Asset Create Txn</a>
<a class="navbar-item" href="asset-optin.html">Asset Opt-in Txn</a>
<a class="navbar-item" href="arcTransitionGuide.html">ARC Transition Guide</a>
</div>
<div class="navbar-end">
<a class="navbar-item" target="_blank" rel="noopener noreferrer" href="https://github.com/PureStake/algosigner/blob/develop/docs/dApp-integration.md">
Documentation
</a>
</div>
</div>
</nav>
<!-- CHECK -->
<section class="section">
<div class="container">
<h1 class="title">
AlgoSigner API Availability
<a class="button is-small is-pulled-right" target="_blank" rel="noopener noreferrer" href="https://github.com/PureStake/algosigner-dapp-example/blob/master/index.html#L227-L235">
<span class="icon is-small">
<i class="fab fa-github"></i>
</span>
<span>See code on GitHub</span>
</a>
</h1>
<p class="subtitle">
Check for the AlgoSigner API to be available in the browser context
</p>
<div class="columns">
<div class="column">
<pre><code class="js">
if (typeof <b>algorand</b> !== 'undefined') {
console.log('AlgoSigner is installed.');
} else {
console.log('AlgoSigner is NOT installed.');
};
</code></pre>
<button class="button is-primary is-fullwidth" id="check">Run code</button>
</div>
<div class="column">
<pre><code class="JSON" id="check-code">code snippet output</code></pre>
</div>
</div>
</div>
</section>
<!-- /CHECK -->
<!-- SDKSETUP -->
<section class="section">
<div class="container">
<h1 class="title">
Clients Setup & Usage
<a class="button is-small is-pulled-right" target="_blank" rel="noopener noreferrer"
href="https://github.com/PureStake/algosigner-dapp-example/blob/master/index.html#L257-L278">
<span class="icon is-small">
<i class="fab fa-github"></i>
</span>
<span>See code on GitHub</span>
</a>
</h1>
<p class="subtitle">
Setup Algod and Indexer clients and fetch transactions parameters
</p>
<div class="columns">
<div class="column">
<pre><code class="js">
const algodServer = 'https://testnet-algorand.api.purestake.io/ps2';
const indexerServer = 'https://testnet-algorand.api.purestake.io/idx2';
const token = { 'X-API-Key': 'YOUR API KEY HERE' };
const port = '';
algodClient = new algosdk.Algodv2(token, algodServer, port);
indexerClient = new algosdk.Indexer(token, indexerServer, port);
algodClient.getTransactionParams().do()
.then(d => {
console.log(d);
txnParams = d;
})
.catch(e => {
console.error(e);
});
</code></pre>
<button class="button is-primary is-fullwidth" id="sdksetup">Run code</button>
</div>
<div class="column">
<pre><code class="JSON" id="sdk-setup">code snippet output</code></pre>
</div>
</div>
</div>
</section>
<!-- /SDKSETUP -->
<!-- ENABLE -->
<section class="section">
<div class="container">
<h1 class="title">
Enable account discovery
<a class="button is-small is-pulled-right" target="_blank" rel="noopener noreferrer" href="https://github.com/PureStake/algosigner-dapp-example/blob/master/index.html#L237-L255">
<span class="icon is-small">
<i class="fab fa-github"></i>
</span>
<span>See code on GitHub</span>
</a>
</h1>
<p class="subtitle">
Request from the user which accounts will be shared with the dApp
</p>
<div class="columns">
<div class="column">
<pre><code class="js">
<b>algorand</b>.enable({ genesisID: txnParams.genesisID })
.then((d) => {
console.log(d);
sharedAccounts = d.accounts;
})
.catch((e) => {
console.error(e);
});
</code></pre>
<button class="button is-primary is-fullwidth" id="enable">Run code</button>
</div>
<div class="column">
<pre><code class="JSON" id="enable-code">code snippet output</code></pre>
</div>
</div>
</div>
</section>
<!-- /ENABLE -->
<!-- ASSETS -->
<section class="section">
<div class="container">
<h1 class="title">
Get Assets from Indexer
<a class="button is-small is-pulled-right" target="_blank" rel="noopener noreferrer" href="https://github.com/PureStake/algosigner-dapp-example/blob/master/index.html#L280-L306">
<span class="icon is-small">
<i class="fab fa-github"></i>
</span>
<span>See code on GitHub</span>
</a>
</h1>
<p class="subtitle">
Query Indexer with the client to fetch TestNet assets
</p>
<div class="columns">
<div class="column">
<pre><code class="js">
const name = document.getElementById('name').value;
const limit = document.getElementById('limit').value;
indexerClient.searchForAssets().limit(limit).name(name).do()
.then((d) => {
console.log(d);
})
.catch((e) => {
console.error(e);
});
</code></pre>
<button class="button is-primary is-fullwidth" id="assets">Run code</button>
</div>
<div class="column">
<div class="field">
<p class="control has-icons-left">
<input class="input" id="name" placeholder="Name">
<span class="icon is-small is-left">
<i class="fas fa-signature"></i>
</span>
</p>
</div>
<div class="field">
<p class="control has-icons-left">
<input class="input" id="limit" type="number" placeholder="Limit">
<span class="icon is-small is-left">
<i class="fas fa-list"></i>
</span>
</p>
</div>
<pre><code class="JSON" id="assets-code">code snippet output</code></pre>
</div>
</div>
</div>
</section>
<!-- /ASSETS -->
<footer class="footer">
<div class="content has-text-centered">
by <a target="_blank" rel="noopener noreferrer" href="https://purestake.com">
<img src="assets/ps-logo.png" height="28">
</a>
</div>
</footer>
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
<script>
hljs.initHighlightingOnLoad();
let algodClient;
let indexerClient;
let txnParams;
let sharedAccounts;
function check() {
let checkCodeElem = document.getElementById('check-code');
if (typeof algorand !== 'undefined') {
checkCodeElem.innerHTML = 'AlgoSigner is installed.';
} else {
checkCodeElem.innerHTML = 'AlgoSigner is NOT installed.';
}
}
function enable() {
let enableCodeElem = document.getElementById('enable-code');
if (txnParams === undefined) {
enableCodeElem.innerHTML = 'Please run the client setup code first.';
} else {
algorand.enable({ genesisID: txnParams.genesisID })
.then((d) => {
enableCodeElem.innerHTML = JSON.stringify(d, null, 2);
})
.catch((e) => {
console.error(e);
enableCodeElem.innerHTML = JSON.stringify(e, null, 2);
})
.finally(() => {
hljs.highlightBlock(enableCodeElem);
});
}
}
function sdkSetup() {
let sdkSetupCodeElem = document.getElementById('sdk-setup');
const algodServer = 'https://testnet-algorand.api.purestake.io/ps2';
const indexerServer = 'https://testnet-algorand.api.purestake.io/idx2';
const token = { 'X-API-Key': 'B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab' }
const port = '';
algodClient = new algosdk.Algodv2(token, algodServer, port);
indexerClient = new algosdk.Indexer(token, indexerServer, port);
// Fetch params
algodClient.getTransactionParams().do()
.then(d => {
txnParams = d;
sdkSetupCodeElem.innerHTML = JSON.stringify(d, null, 2);
})
.catch(e => { sdkSetupCodeElem.innerHTML = JSON.stringify(e, null, 2); })
.finally(() => {
hljs.highlightBlock(sdkSetupCodeElem);
});
}
function assets(){
let assetsCodeElem = document.getElementById('assets-code');
const name = document.getElementById('name').value;
const limit = document.getElementById('limit').value;
if (indexerClient === undefined) {
assetsCodeElem.innerHTML = 'Please run the client setup code first.';
} else if (!name || !limit) {
assetsCodeElem.innerHTML = 'Please fill the "name" and "limit" fields.';
} else {
indexerClient.searchForAssets()
.limit(limit)
.name(name)
.do()
.then((d) => {
assetsCodeElem.innerHTML = JSON.stringify(d, null, 2);
})
.catch((e) => {
console.error(e);
assetsCodeElem.innerHTML = JSON.stringify(e, null, 2);
})
.finally(() => {
hljs.highlightBlock(assetsCodeElem);
});
}
}
document.getElementById('check').addEventListener('click', check);
document.getElementById('enable').addEventListener('click', enable);
document.getElementById('sdksetup').addEventListener('click', sdkSetup);
document.getElementById('assets').addEventListener('click', assets);
</script>
<script src="https://unpkg.com/[email protected]"></script>
</body>
</html>