-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTokenScript Mockup Generator V1.html
333 lines (311 loc) · 13.3 KB
/
TokenScript Mockup Generator V1.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TokenScript Mockup Generator</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
.container {
background-color: white;
padding: 2rem;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 600px;
margin: 0 auto;
}
h1 {
text-align: center;
margin-bottom: 2rem;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input, select, textarea, button {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
#downloadLink {
display: inline-block;
padding: 10px 15px;
background-color: #4CAF50;
color: white;
text-decoration: none;
border-radius: 4px;
margin-top: 10px;
}
#errorMessage {
color: red;
margin-top: 10px;
}
#generatedScript {
margin-top: 20px;
white-space: pre-wrap;
word-wrap: break-word;
background: #f0f0f0;
padding: 10px;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="container">
<h1>TokenScript Mockup Generator</h1>
<select id="tokenType">
<option value="">Choose Token Type</option>
<option value="ERC20">ERC20</option>
<option value="NFT">NFT</option>
</select>
<label>
Tapp name (optional)
<input type="text" id="tappName" placeholder="Tapp name">
</label>
<label>
Tapp singular name (optional)
<input type="text" id="singularName" placeholder="Singular name">
</label>
<label>
Tapp plural name (optional)
<input type="text" id="pluralName" placeholder="Plural name">
</label>
<label>
Tapp description (optional)
<textarea id="description" placeholder="Description"></textarea>
</label>
<label>
Tapp related website (optional)
<input type="text" id="website" placeholder="Website URL">
</label>
<label>
Tapp icon URL (optional)
<input type="text" id="iconUrl" placeholder="Icon URL">
</label>
<label>
Contract name (optional)
<input type="text" id="contractName" placeholder="Contract name">
</label>
<label>
Chain ID and contract address (required)
<input type="text" id="chainIdAndAddress" placeholder="e.g., 137:0x1234...5678">
</label>
<label>
Function card names (required, comma-separated)
<input type="text" id="functionCards" placeholder="e.g., Transfer, Balance, Approve">
</label>
<button id="generateButton">Generate TokenScript Mockup</button>
<div id="errorMessage"></div>
<a id="downloadLink" style="display: none;">Download .tsml File</a>
<pre id="generatedScript"></pre>
</div>
<script>
const erc20Template = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ts:token xmlns:ts="http://tokenscript.org/2024/01/tokenscript"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xsi:schemaLocation="http://tokenscript.org/2024/01/tokenscript https://www.tokenscript.org/schemas/2024-01/tokenscript.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ethereum="urn:ethereum:constantinople"
name="GenericERC20Token">
<ts:label>
<ts:plurals xml:lang="en">
<ts:string quantity="one">Generic ERC20 Token</ts:string>
<ts:string quantity="other">Generic ERC20 Tokens</ts:string>
</ts:plurals>
</ts:label>
<ts:meta>
<ts:description xml:lang="en">A generic ERC20 token template</ts:description>
<ts:aboutUrl xml:lang="en">https://example.com</ts:aboutUrl>
<ts:iconUrl xml:lang="en">https://example.com/icon.png</ts:iconUrl>
</ts:meta>
<ts:contract interface="erc20" name="GenericERC20Contract">
<ts:address network="137">0x1fe78e67ad10ba3a9583e672cac0480737d1b9f7</ts:address>
</ts:contract>
<ts:origins>
<ts:ethereum contract="GenericERC20Contract"/>
</ts:origins>
<ts:cards>
<ts:card type="action" name="Transfer">
<ts:label>
<ts:string xml:lang="en">Transfer</ts:string>
</ts:label>
<ts:view xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<button>Transfer Tokens</button>
</ts:view>
</ts:card>
<ts:card type="action" name="Balance">
<ts:label>
<ts:string xml:lang="en">Check Balance</ts:string>
</ts:label>
<ts:view xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<button>Check Balance</button>
</ts:view>
</ts:card>
<ts:card type="action" name="Approve">
<ts:label>
<ts:string xml:lang="en">Approve Spending</ts:string>
</ts:label>
<ts:view xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<button>Approve Spending</button>
</ts:view>
</ts:card>
</ts:cards>
<ts:attribute-types>
<ts:attribute-type id="decimals" syntax="1.3.6.1.4.1.1466.115.121.1.36">
<ts:name>
<ts:string xml:lang="en">decimals</ts:string>
</ts:name>
<ts:origins>
<ethereum:call function="decimals" contract="GenericERC20Contract" as="uint"/>
</ts:origins>
</ts:attribute-type>
<ts:attribute-type id="symbol" syntax="1.3.6.1.4.1.1466.115.121.1.26">
<ts:name>
<ts:string xml:lang="en">symbol</ts:string>
</ts:name>
<ts:origins>
<ethereum:call function="symbol" contract="GenericERC20Contract" as="utf8"/>
</ts:origins>
</ts:attribute-type>
</ts:attribute-types>
</ts:token>`;
const nftTemplate = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ts:token xmlns:ts="http://tokenscript.org/2024/01/tokenscript"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xsi:schemaLocation="http://tokenscript.org/2024/01/tokenscript https://www.tokenscript.org/schemas/2024-01/tokenscript.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ethereum="urn:ethereum:constantinople"
name="GenericToken">
<ts:label>
<ts:plurals xml:lang="en">
<ts:string quantity="one">Generic Token</ts:string>
<ts:string quantity="other">Generic Tokens</ts:string>
</ts:plurals>
</ts:label>
<ts:meta>
<ts:description xml:lang="en">A generic token template</ts:description>
<ts:aboutUrl xml:lang="en">https://example.com</ts:aboutUrl>
<ts:iconUrl xml:lang="en">https://example.com/icon.png</ts:iconUrl>
</ts:meta>
<ts:contract interface="erc721" name="GenericTokenContract">
<ts:address network="8453">0x6F418b21aabe625192577De7720b4D27297Beb92</ts:address>
</ts:contract>
<ts:origins>
<ts:ethereum contract="GenericTokenContract"/>
</ts:origins>
<ts:cards>
<ts:card type="action" name="FunctionA">
<ts:label>
<ts:string xml:lang="en">Function A</ts:string>
</ts:label>
<ts:view xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<button>Function A</button>
</ts:view>
</ts:card>
<ts:card type="action" name="FunctionB">
<ts:label>
<ts:string xml:lang="en">Function B</ts:string>
</ts:label>
<ts:view xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<button>Function B</button>
</ts:view>
</ts:card>
<ts:card type="action" name="FunctionC">
<ts:label>
<ts:string xml:lang="en">Function C</ts:string>
</ts:label>
<ts:view xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<button>Function C</button>
</ts:view>
</ts:card>
</ts:cards>
</ts:token>`;
document.getElementById('generateButton').addEventListener('click', generateTokenScript);
function generateTokenScript() {
const tokenType = document.getElementById('tokenType').value;
const tappName = document.getElementById('tappName').value;
const singularName = document.getElementById('singularName').value;
const pluralName = document.getElementById('pluralName').value;
const description = document.getElementById('description').value;
const website = document.getElementById('website').value;
const iconUrl = document.getElementById('iconUrl').value;
const contractName = document.getElementById('contractName').value;
const chainIdAndAddress = document.getElementById('chainIdAndAddress').value;
const functionCards = document.getElementById('functionCards').value;
const errorMessageElement = document.getElementById('errorMessage');
const generatedScriptElement = document.getElementById('generatedScript');
const downloadLinkElement = document.getElementById('downloadLink');
if (!tokenType || !chainIdAndAddress || !functionCards) {
errorMessageElement.textContent = 'Please fill in all required fields';
generatedScriptElement.textContent = '';
downloadLinkElement.style.display = 'none';
return;
}
let template = tokenType === 'ERC20' ? erc20Template : nftTemplate;
// Replace placeholders in the template
if (tokenType === 'ERC20') {
template = template.replace(/GenericERC20Token/g, tappName || 'GenericERC20Token');
template = template.replace(/Generic ERC20 Token/g, singularName || 'Generic ERC20 Token');
template = template.replace(/Generic ERC20 Tokens/g, pluralName || 'Generic ERC20 Tokens');
template = template.replace(/A generic ERC20 token template/g, description || 'A generic ERC20 token template');
template = template.replace(/GenericERC20Contract/g, contractName || 'GenericERC20Contract');
} else {
template = template.replace(/GenericToken/g, tappName || 'GenericToken');
template = template.replace(/Generic Token/g, singularName || 'Generic Token');
template = template.replace(/Generic Tokens/g, pluralName || 'Generic Tokens');
template = template.replace(/A generic token template/g, description || 'A generic token template');
template = template.replace(/GenericTokenContract/g, contractName || 'GenericTokenContract');
}
template = template.replace(/https:\/\/example\.com/g, website || 'https://example.com');
template = template.replace(/https:\/\/example\.com\/icon\.png/g, iconUrl || 'https://example.com/icon.png');
// Replace chain ID and contract address
const [chainId, contractAddress] = chainIdAndAddress.split(':');
template = template.replace(/network="[^"]*"/, `network="${chainId}"`);
template = template.replace(/0x[a-fA-F0-9]{40}/, contractAddress);
// Replace function cards
const functionCardArray = functionCards.split(',').map(card => card.trim());
let cardSection = '';
functionCardArray.forEach((card) => {
cardSection += `
<ts:card type="action" name="${card}">
<ts:label>
<ts:string xml:lang="en">${card}</ts:string>
</ts:label>
<ts:view xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<button>${card}</button>
</ts:view>
</ts:card>`;
});
template = template.replace(/<ts:cards>[\s\S]*?<\/ts:cards>/, `<ts:cards>${cardSection}</ts:cards>`);
generatedScriptElement.textContent = template;
errorMessageElement.textContent = '';
// Create a Blob with the generated script
const blob = new Blob([template], { type: 'text/xml' });
const url = URL.createObjectURL(blob);
downloadLinkElement.href = url;
downloadLinkElement.download = `${tappName || 'TokenScript'}.tsml`;
downloadLinkElement.style.display = 'inline-block';
downloadLinkElement.textContent = 'Download .tsml File';
}
</script>
</body>
</html>