-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpage.tsx
More file actions
407 lines (383 loc) · 16.1 KB
/
page.tsx
File metadata and controls
407 lines (383 loc) · 16.1 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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
'use client';
import { useContext, useState } from 'react';
import { Button } from '@/components/ui/button';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card';
import { Gamepad2, ChevronDown, ChevronUp } from 'lucide-react';
import Link from 'next/link';
import { ArcadeTokenOptions, ArcadeTokenCreationResult } from '@/types/token';
// import { createArcadeTokenForUI } from '@/lib/arcadeToken';
import { mockCreateArcadeTokenForUI } from '@/lib/mockFunctions';
import { SelectedWalletAccountContext } from '@/context/SelectedWalletAccountContext';
export default function ArcadeTokenCreatePage() {
const [selectedWalletAccount] = useContext(SelectedWalletAccountContext);
const [arcadeTokenOptions, setArcadeTokenOptions] =
useState<ArcadeTokenOptions>({
name: '',
symbol: '',
decimals: '6',
uri: '',
mintAuthority: '',
metadataAuthority: '',
pausableAuthority: '',
permanentDelegateAuthority: '',
mintKeypair: '',
keypair: '',
});
const [showOptionalParams, setShowOptionalParams] = useState(false);
const [isCreating, setIsCreating] = useState(false);
const [result, setResult] = useState<ArcadeTokenCreationResult | null>(null);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!selectedWalletAccount) {
alert('Please connect your wallet first');
return;
}
setIsCreating(true);
setResult(null);
try {
const result = await mockCreateArcadeTokenForUI(arcadeTokenOptions, {
publicKey: selectedWalletAccount.address,
connected: true,
});
setResult(result);
if (result.success) {
// console.log('Arcade token created successfully:', result);
} else {
// console.error('Failed to create arcade token:', result.error);
}
} catch (error) {
// console.error('Error creating arcade token:', error);
setResult({
success: false,
error:
error instanceof Error ? error.message : 'Unknown error occurred',
});
} finally {
setIsCreating(false);
}
};
const handleInputChange = (field: string, value: string) => {
setArcadeTokenOptions(prev => ({ ...prev, [field]: value }));
};
return (
<div className="flex-1 p-8">
<div className="max-w-4xl mx-auto">
<div className="flex items-center mb-8">
<Link href="/dashboard/create">
<Button variant="ghost" className="mr-4">
← Back
</Button>
</Link>
<div>
<h2 className="text-3xl font-bold mb-2">Create Arcade Token</h2>
<p className="text-muted-foreground">
Configure your arcade token parameters
</p>
</div>
</div>
<Card>
<CardHeader>
<div className="flex items-center">
<Gamepad2 className="h-8 w-8 text-primary mr-3" />
<div>
<CardTitle>Arcade Token Configuration</CardTitle>
<CardDescription>
Fill in the required fields to create your gaming or utility
token
</CardDescription>
</div>
</div>
</CardHeader>
<CardContent>
<form onSubmit={handleSubmit}>
<div className="space-y-6">
{/* Required Fields */}
<div>
<h3 className="text-lg font-semibold mb-4">
Required Parameters
</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label className="block text-sm font-medium mb-2">
Name *
</label>
<input
type="text"
value={arcadeTokenOptions.name}
onChange={e =>
handleInputChange('name', e.target.value)
}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent"
placeholder="Token Name"
required
/>
</div>
<div>
<label className="block text-sm font-medium mb-2">
Symbol *
</label>
<input
type="text"
value={arcadeTokenOptions.symbol}
onChange={e =>
handleInputChange('symbol', e.target.value)
}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent"
placeholder="TKN"
required
/>
</div>
<div>
<label className="block text-sm font-medium mb-2">
Decimals *
</label>
<input
type="number"
value={arcadeTokenOptions.decimals}
onChange={e =>
handleInputChange('decimals', e.target.value)
}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent"
placeholder="6"
min="0"
max="9"
required
/>
</div>
</div>
</div>
{/* Optional Parameters Dropdown */}
<div className="border rounded-lg">
<button
type="button"
onClick={() => setShowOptionalParams(!showOptionalParams)}
className="w-full px-4 py-3 flex items-center justify-between text-left hover:scale-[1.01] transition-transform duration-200"
>
<span className="font-medium">Optional Parameters</span>
{showOptionalParams ? (
<ChevronUp className="h-5 w-5" />
) : (
<ChevronDown className="h-5 w-5" />
)}
</button>
{showOptionalParams && (
<div className="px-4 pb-4 border-t">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 pt-4">
<div>
<label className="block text-sm font-medium mb-2">
Mint Authority
</label>
<input
type="text"
value={arcadeTokenOptions.mintAuthority}
onChange={e =>
handleInputChange('mintAuthority', e.target.value)
}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent"
placeholder="Public key"
/>
</div>
<div>
<label className="block text-sm font-medium mb-2">
Metadata Authority
</label>
<input
type="text"
value={arcadeTokenOptions.metadataAuthority}
onChange={e =>
handleInputChange(
'metadataAuthority',
e.target.value
)
}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent"
placeholder="Public key"
/>
</div>
<div>
<label className="block text-sm font-medium mb-2">
Pausable Authority
</label>
<input
type="text"
value={arcadeTokenOptions.pausableAuthority}
onChange={e =>
handleInputChange(
'pausableAuthority',
e.target.value
)
}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent"
placeholder="Public key"
/>
</div>
<div>
<label className="block text-sm font-medium mb-2">
Permanent Delegate Authority
</label>
<input
type="text"
value={
arcadeTokenOptions.permanentDelegateAuthority
}
onChange={e =>
handleInputChange(
'permanentDelegateAuthority',
e.target.value
)
}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent"
placeholder="Public key"
/>
</div>
<div>
<label className="block text-sm font-medium mb-2">
Mint Keypair
</label>
<input
type="text"
value={arcadeTokenOptions.mintKeypair}
onChange={e =>
handleInputChange('mintKeypair', e.target.value)
}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent"
placeholder="Base58 encoded keypair"
/>
</div>
<div>
<label className="block text-sm font-medium mb-2">
Keypair
</label>
<input
type="text"
value={arcadeTokenOptions.keypair}
onChange={e =>
handleInputChange('keypair', e.target.value)
}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent"
placeholder="Base58 encoded keypair"
/>
</div>
</div>
</div>
)}
</div>
</div>
<div className="mt-8 flex justify-end">
<Button type="submit" className="px-8" disabled={isCreating}>
{isCreating ? 'Creating...' : 'Create Arcade Token'}
</Button>
</div>
</form>
</CardContent>
</Card>
{/* Result Display */}
{result && (
<Card className="mt-6">
<CardHeader>
<CardTitle
className={result.success ? 'text-green-600' : 'text-red-600'}
>
{result.success
? '✅ Arcade Token Creation Successful'
: '❌ Arcade Token Creation Failed'}
</CardTitle>
</CardHeader>
<CardContent>
{result.success ? (
<div className="space-y-4">
<div>
<h4 className="font-semibold text-gray-700 mb-2">
📋 Details:
</h4>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2 text-sm">
<div>
<span className="font-medium">Name:</span>{' '}
{result.details?.name}
</div>
<div>
<span className="font-medium">Symbol:</span>{' '}
{result.details?.symbol}
</div>
<div>
<span className="font-medium">Decimals:</span>{' '}
{result.details?.decimals}
</div>
<div>
<span className="font-medium">Mint Address:</span>{' '}
{result.mintAddress}
</div>
<div>
<span className="font-medium">Transaction:</span>{' '}
{result.transactionSignature}
</div>
</div>
</div>
<div>
<h4 className="font-semibold text-gray-700 mb-2">
🔐 Authorities:
</h4>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2 text-sm">
<div>
<span className="font-medium">Mint Authority:</span>{' '}
{result.details?.mintAuthority}
</div>
<div>
<span className="font-medium">Metadata Authority:</span>{' '}
{result.details?.metadataAuthority}
</div>
<div>
<span className="font-medium">Pausable Authority:</span>{' '}
{result.details?.pausableAuthority}
</div>
<div>
<span className="font-medium">
Permanent Delegate Authority:
</span>{' '}
{result.details?.permanentDelegateAuthority}
</div>
</div>
</div>
<div>
<h4 className="font-semibold text-gray-700 mb-2">
🛡️ Token Extensions:
</h4>
<div className="flex flex-wrap gap-2">
{result.details?.extensions.map(
(ext: string, index: number) => (
<span
key={index}
className="px-2 py-1 bg-green-100 text-green-800 rounded text-xs"
>
✓ {ext}
</span>
)
)}
</div>
</div>
{arcadeTokenOptions.uri && (
<div>
<span className="font-medium">Metadata URI:</span>{' '}
{arcadeTokenOptions.uri}
</div>
)}
</div>
) : (
<div className="text-red-600">
<p className="font-medium">Error:</p>
<p>{result.error}</p>
</div>
)}
</CardContent>
</Card>
)}
</div>
</div>
);
}