forked from Haroldwonder/AnchorKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdk_config_form.html
More file actions
361 lines (310 loc) · 10.4 KB
/
Copy pathsdk_config_form.html
File metadata and controls
361 lines (310 loc) · 10.4 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
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AnchorKit SDK Configuration</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: #f5f7fa;
padding: 20px;
line-height: 1.6;
}
.container {
max-width: 600px;
margin: 0 auto;
background: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
padding: 32px;
}
h1 {
font-size: 24px;
font-weight: 600;
color: #1a202c;
margin-bottom: 8px;
}
.subtitle {
color: #718096;
font-size: 14px;
margin-bottom: 32px;
}
.form-group {
margin-bottom: 24px;
}
label {
display: block;
font-size: 14px;
font-weight: 500;
color: #2d3748;
margin-bottom: 8px;
}
.required {
color: #e53e3e;
}
input[type="text"],
input[type="number"],
select {
width: 100%;
padding: 10px 12px;
border: 1px solid #cbd5e0;
border-radius: 6px;
font-size: 14px;
transition: border-color 0.2s;
}
input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
outline: none;
border-color: #4299e1;
box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}
.help-text {
font-size: 12px;
color: #718096;
margin-top: 4px;
}
.headers-section {
border: 1px solid #e2e8f0;
border-radius: 6px;
padding: 16px;
background: #f7fafc;
}
.header-item {
display: grid;
grid-template-columns: 1fr 1fr auto;
gap: 8px;
margin-bottom: 12px;
align-items: start;
}
.header-item:last-child {
margin-bottom: 0;
}
.btn {
padding: 10px 16px;
border: none;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
}
.btn-primary {
background: #4299e1;
color: white;
width: 100%;
}
.btn-primary:hover {
background: #3182ce;
}
.btn-secondary {
background: #edf2f7;
color: #2d3748;
padding: 8px 12px;
font-size: 13px;
}
.btn-secondary:hover {
background: #e2e8f0;
}
.btn-remove {
background: #fed7d7;
color: #c53030;
padding: 8px 12px;
font-size: 13px;
}
.btn-remove:hover {
background: #fc8181;
color: white;
}
.error {
color: #e53e3e;
font-size: 12px;
margin-top: 4px;
display: none;
}
.error.show {
display: block;
}
.output {
margin-top: 32px;
padding: 16px;
background: #f7fafc;
border: 1px solid #e2e8f0;
border-radius: 6px;
display: none;
}
.output.show {
display: block;
}
.output h3 {
font-size: 14px;
font-weight: 600;
color: #2d3748;
margin-bottom: 12px;
}
.output pre {
background: #2d3748;
color: #e2e8f0;
padding: 12px;
border-radius: 4px;
overflow-x: auto;
font-size: 12px;
font-family: 'Monaco', 'Courier New', monospace;
}
</style>
</head>
<body>
<div class="container">
<h1>SDK Configuration</h1>
<p class="subtitle">Configure your AnchorKit SDK connection settings</p>
<form id="sdkConfigForm">
<div class="form-group">
<label for="network">Network <span class="required">*</span></label>
<select id="network" name="network" required>
<option value="testnet">Testnet</option>
<option value="mainnet">Mainnet</option>
</select>
<div class="help-text">Select the Stellar network to connect to</div>
</div>
<div class="form-group">
<label for="anchorDomain">Anchor Domain <span class="required">*</span></label>
<input
type="text"
id="anchorDomain"
name="anchorDomain"
placeholder="example.com"
required
minlength="3"
maxlength="253"
/>
<div class="help-text">Domain of the anchor service (3-253 characters)</div>
<div class="error" id="domainError">Invalid domain format</div>
</div>
<div class="form-group">
<label for="timeout">Timeout (seconds) <span class="required">*</span></label>
<input
type="number"
id="timeout"
name="timeout"
value="30"
min="1"
max="300"
required
/>
<div class="help-text">Request timeout in seconds (1-300)</div>
</div>
<div class="form-group">
<label>Custom Headers</label>
<div class="headers-section">
<div id="headersContainer"></div>
<button type="button" class="btn btn-secondary" onclick="addHeader()">+ Add Header</button>
</div>
<div class="help-text">Add custom HTTP headers (max 20)</div>
</div>
<button type="submit" class="btn btn-primary">Generate Configuration</button>
</form>
<div class="output" id="output">
<h3>Configuration Output</h3>
<pre id="configOutput"></pre>
</div>
</div>
<script>
let headerCount = 0;
function addHeader() {
if (headerCount >= 20) {
alert('Maximum 20 headers allowed');
return;
}
const container = document.getElementById('headersContainer');
const headerItem = document.createElement('div');
headerItem.className = 'header-item';
headerItem.id = `header-${headerCount}`;
headerItem.innerHTML = `
<input
type="text"
name="headerKey[]"
placeholder="Header name"
maxlength="64"
/>
<input
type="text"
name="headerValue[]"
placeholder="Header value"
maxlength="1024"
/>
<button type="button" class="btn btn-remove" onclick="removeHeader(${headerCount})">Remove</button>
`;
container.appendChild(headerItem);
headerCount++;
}
function removeHeader(id) {
const element = document.getElementById(`header-${id}`);
if (element) {
element.remove();
}
}
function validateDomain(domain) {
// Basic domain validation
const domainRegex = /^[a-zA-Z0-9][a-zA-Z0-9-_.]*[a-zA-Z0-9]$/;
return domainRegex.test(domain) && domain.length >= 3 && domain.length <= 253;
}
document.getElementById('anchorDomain').addEventListener('blur', function() {
const domain = this.value;
const errorElement = document.getElementById('domainError');
if (domain && !validateDomain(domain)) {
errorElement.classList.add('show');
this.style.borderColor = '#e53e3e';
} else {
errorElement.classList.remove('show');
this.style.borderColor = '#cbd5e0';
}
});
document.getElementById('sdkConfigForm').addEventListener('submit', function(e) {
e.preventDefault();
const network = document.getElementById('network').value;
const anchorDomain = document.getElementById('anchorDomain').value;
const timeout = parseInt(document.getElementById('timeout').value);
// Validate domain
if (!validateDomain(anchorDomain)) {
document.getElementById('domainError').classList.add('show');
return;
}
// Collect headers
const headerKeys = document.getElementsByName('headerKey[]');
const headerValues = document.getElementsByName('headerValue[]');
const headers = [];
for (let i = 0; i < headerKeys.length; i++) {
const key = headerKeys[i].value.trim();
const value = headerValues[i].value.trim();
if (key) {
headers.push({
key: key,
value: value
});
}
}
// Create config object
const config = {
network: network === 'testnet' ? 'Testnet' : 'Mainnet',
anchor_domain: anchorDomain,
timeout_seconds: timeout,
custom_headers: headers
};
// Display output
const outputElement = document.getElementById('configOutput');
outputElement.textContent = JSON.stringify(config, null, 2);
document.getElementById('output').classList.add('show');
// Scroll to output
document.getElementById('output').scrollIntoView({ behavior: 'smooth' });
});
// Add one header by default
addHeader();
</script>
</body>
</html>