create-polygon-kit 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/nextjs/typescript/app/page.tsx +148 -48
- package/templates/remix/typescript/.env.example +2 -0
- package/templates/remix/typescript/README.md +47 -0
- package/templates/remix/typescript/app/components/client-only.tsx +15 -0
- package/templates/remix/typescript/app/components/dashboard.tsx +285 -0
- package/templates/remix/typescript/app/components/landing-page.tsx +432 -0
- package/templates/remix/typescript/app/providers.tsx +18 -0
- package/templates/remix/typescript/app/root.tsx +44 -0
- package/templates/remix/typescript/app/routes/_index.tsx +25 -0
- package/templates/remix/typescript/package.json +37 -0
- package/templates/remix/typescript/tsconfig.json +30 -0
- package/templates/remix/typescript/vite.config.ts +16 -0
- package/templates/vite/typescript/src/App.tsx +151 -58
|
@@ -4,15 +4,20 @@ import {
|
|
|
4
4
|
ConnectWallet,
|
|
5
5
|
WalletDropdown,
|
|
6
6
|
Identity,
|
|
7
|
+
Avatar,
|
|
8
|
+
Name,
|
|
9
|
+
TokenBalance,
|
|
10
|
+
TokenIcon,
|
|
11
|
+
TransactionButton,
|
|
12
|
+
Swap,
|
|
7
13
|
usePolygonKit,
|
|
8
14
|
} from '@sanketsaagar/polygon-kit';
|
|
9
15
|
import { useState } from 'react';
|
|
10
|
-
import '
|
|
16
|
+
import { parseEther } from 'viem';
|
|
11
17
|
|
|
12
18
|
function LandingPage() {
|
|
13
19
|
return (
|
|
14
20
|
<div className="min-h-screen bg-gradient-to-br from-purple-900 via-indigo-900 to-blue-900">
|
|
15
|
-
{/* Hero Section */}
|
|
16
21
|
<div className="container mx-auto px-4 py-16">
|
|
17
22
|
<nav className="flex justify-between items-center mb-20">
|
|
18
23
|
<div className="flex items-center space-x-2">
|
|
@@ -36,7 +41,7 @@ function LandingPage() {
|
|
|
36
41
|
<div className="flex gap-4 justify-center">
|
|
37
42
|
<ConnectWallet />
|
|
38
43
|
<a
|
|
39
|
-
href="https://
|
|
44
|
+
href="https://polygonlabs.mintlify.app"
|
|
40
45
|
target="_blank"
|
|
41
46
|
rel="noopener noreferrer"
|
|
42
47
|
className="px-8 py-3 bg-white/10 backdrop-blur-sm text-white rounded-lg font-semibold hover:bg-white/20 transition-all duration-200"
|
|
@@ -144,8 +149,9 @@ function LandingPage() {
|
|
|
144
149
|
}
|
|
145
150
|
|
|
146
151
|
function Dashboard() {
|
|
147
|
-
const { address, chainId } = usePolygonKit();
|
|
148
|
-
const [activeTab, setActiveTab] = useState<'overview' | '
|
|
152
|
+
const { address, isConnected, chainId } = usePolygonKit();
|
|
153
|
+
const [activeTab, setActiveTab] = useState<'overview' | 'components' | 'transactions' | 'swap'>('overview');
|
|
154
|
+
const [txHash, setTxHash] = useState<string>('');
|
|
149
155
|
|
|
150
156
|
const getNetworkName = (chainId?: number) => {
|
|
151
157
|
switch (chainId) {
|
|
@@ -160,6 +166,10 @@ function Dashboard() {
|
|
|
160
166
|
}
|
|
161
167
|
};
|
|
162
168
|
|
|
169
|
+
if (!isConnected || !address) {
|
|
170
|
+
return <LandingPage />;
|
|
171
|
+
}
|
|
172
|
+
|
|
163
173
|
return (
|
|
164
174
|
<div className="min-h-screen bg-gradient-to-br from-slate-50 via-purple-50 to-indigo-50 dark:from-gray-900 dark:via-purple-900/20 dark:to-indigo-900/20">
|
|
165
175
|
{/* Header */}
|
|
@@ -169,7 +179,7 @@ function Dashboard() {
|
|
|
169
179
|
<div className="flex items-center space-x-3">
|
|
170
180
|
<div className="w-10 h-10 bg-gradient-to-br from-purple-500 to-pink-500 rounded-lg" />
|
|
171
181
|
<div>
|
|
172
|
-
<h1 className="text-xl font-bold text-gray-900 dark:text-white">
|
|
182
|
+
<h1 className="text-xl font-bold text-gray-900 dark:text-white">PolygonKit Showcase</h1>
|
|
173
183
|
<p className="text-sm text-gray-500 dark:text-gray-400">{getNetworkName(chainId)}</p>
|
|
174
184
|
</div>
|
|
175
185
|
</div>
|
|
@@ -182,11 +192,12 @@ function Dashboard() {
|
|
|
182
192
|
|
|
183
193
|
<div className="container mx-auto px-4 py-8">
|
|
184
194
|
{/* Tabs */}
|
|
185
|
-
<div className="flex
|
|
195
|
+
<div className="flex flex-wrap gap-2 mb-8 bg-white/50 dark:bg-gray-800/50 backdrop-blur-sm p-1 rounded-lg w-fit">
|
|
186
196
|
{[
|
|
187
197
|
{ id: 'overview', label: 'Overview', icon: '📊' },
|
|
188
|
-
{ id: '
|
|
189
|
-
{ id: '
|
|
198
|
+
{ id: 'components', label: 'Components', icon: '🧩' },
|
|
199
|
+
{ id: 'transactions', label: 'Transactions', icon: '💸' },
|
|
200
|
+
{ id: 'swap', label: 'Swap', icon: '🔄' },
|
|
190
201
|
].map((tab) => (
|
|
191
202
|
<button
|
|
192
203
|
key={tab.id}
|
|
@@ -211,22 +222,14 @@ function Dashboard() {
|
|
|
211
222
|
<div className="lg:col-span-2 bg-gradient-to-br from-purple-500 to-pink-500 p-8 rounded-2xl text-white shadow-xl">
|
|
212
223
|
<h2 className="text-lg font-semibold mb-4 opacity-90">Your Wallet</h2>
|
|
213
224
|
<Identity
|
|
214
|
-
address={address
|
|
225
|
+
address={address}
|
|
215
226
|
showAvatar
|
|
216
227
|
showAddress
|
|
217
228
|
showBalance
|
|
218
|
-
className="scale-110"
|
|
219
229
|
/>
|
|
220
|
-
<div className="mt-6
|
|
221
|
-
<
|
|
222
|
-
|
|
223
|
-
</button>
|
|
224
|
-
<button className="flex-1 py-3 bg-white/20 backdrop-blur-sm rounded-lg font-semibold hover:bg-white/30 transition-all">
|
|
225
|
-
Receive
|
|
226
|
-
</button>
|
|
227
|
-
<button className="flex-1 py-3 bg-white/20 backdrop-blur-sm rounded-lg font-semibold hover:bg-white/30 transition-all">
|
|
228
|
-
Swap
|
|
229
|
-
</button>
|
|
230
|
+
<div className="mt-6 pt-6 border-t border-white/20">
|
|
231
|
+
<p className="text-sm opacity-75 mb-3">Native Balance</p>
|
|
232
|
+
<TokenBalance address={address} className="text-2xl font-bold" />
|
|
230
233
|
</div>
|
|
231
234
|
</div>
|
|
232
235
|
|
|
@@ -245,8 +248,8 @@ function Dashboard() {
|
|
|
245
248
|
<span className="font-mono font-semibold text-gray-900 dark:text-white">{chainId || 'N/A'}</span>
|
|
246
249
|
</div>
|
|
247
250
|
<div className="flex items-center justify-between">
|
|
248
|
-
<span className="text-gray-700 dark:text-gray-300">
|
|
249
|
-
<span className="text-gray-900 dark:text-white font-semibold"
|
|
251
|
+
<span className="text-gray-700 dark:text-gray-300">Network</span>
|
|
252
|
+
<span className="text-gray-900 dark:text-white font-semibold">{getNetworkName(chainId)}</span>
|
|
250
253
|
</div>
|
|
251
254
|
</div>
|
|
252
255
|
</div>
|
|
@@ -255,30 +258,128 @@ function Dashboard() {
|
|
|
255
258
|
{/* Quick Actions */}
|
|
256
259
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
|
257
260
|
{[
|
|
258
|
-
{ icon: '💸', title: 'Send Tokens', desc: 'Transfer assets',
|
|
259
|
-
{ icon: '🔄', title: 'Swap', desc: 'Exchange tokens',
|
|
260
|
-
{ icon: '
|
|
261
|
-
{ icon: '
|
|
261
|
+
{ icon: '💸', title: 'Send Tokens', desc: 'Transfer assets', tab: 'transactions' },
|
|
262
|
+
{ icon: '🔄', title: 'Swap', desc: 'Exchange tokens', tab: 'swap' },
|
|
263
|
+
{ icon: '🧩', title: 'Components', desc: 'Explore all features', tab: 'components' },
|
|
264
|
+
{ icon: '📖', title: 'Documentation', desc: 'Learn more', link: 'https://polygonlabs.mintlify.app' },
|
|
262
265
|
].map((action) => (
|
|
263
266
|
<button
|
|
264
267
|
key={action.title}
|
|
268
|
+
onClick={() => action.tab ? setActiveTab(action.tab as typeof activeTab) : window.open(action.link, '_blank')}
|
|
265
269
|
className="p-6 bg-white/80 dark:bg-gray-800/80 backdrop-blur-lg rounded-xl border border-gray-200 dark:border-gray-700 hover:scale-105 transition-all duration-200 text-left group shadow-lg hover:shadow-xl"
|
|
266
270
|
>
|
|
267
|
-
<div className=
|
|
271
|
+
<div className="text-4xl mb-3 group-hover:scale-110 transition-transform">{action.icon}</div>
|
|
268
272
|
<h3 className="font-bold text-gray-900 dark:text-white mb-1">{action.title}</h3>
|
|
269
273
|
<p className="text-sm text-gray-600 dark:text-gray-400">{action.desc}</p>
|
|
270
274
|
</button>
|
|
271
275
|
))}
|
|
272
276
|
</div>
|
|
277
|
+
</div>
|
|
278
|
+
)}
|
|
279
|
+
|
|
280
|
+
{/* Components Showcase Tab */}
|
|
281
|
+
{activeTab === 'components' && (
|
|
282
|
+
<div className="space-y-6">
|
|
283
|
+
<div className="bg-white/80 dark:bg-gray-800/80 backdrop-blur-lg p-8 rounded-2xl shadow-lg border border-gray-200 dark:border-gray-700">
|
|
284
|
+
<h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-6">Identity Components</h2>
|
|
285
|
+
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
|
286
|
+
<div className="p-6 bg-gray-50 dark:bg-gray-700/50 rounded-xl">
|
|
287
|
+
<h3 className="font-semibold mb-4 text-gray-900 dark:text-white">Full Identity</h3>
|
|
288
|
+
<Identity address={address} showAvatar showAddress showBalance />
|
|
289
|
+
</div>
|
|
290
|
+
<div className="p-6 bg-gray-50 dark:bg-gray-700/50 rounded-xl">
|
|
291
|
+
<h3 className="font-semibold mb-4 text-gray-900 dark:text-white">Avatar Only</h3>
|
|
292
|
+
<div className="flex items-center gap-4">
|
|
293
|
+
<Avatar address={address} size={48} />
|
|
294
|
+
<Avatar address={address} size={64} />
|
|
295
|
+
<Avatar address={address} size={80} />
|
|
296
|
+
</div>
|
|
297
|
+
</div>
|
|
298
|
+
<div className="p-6 bg-gray-50 dark:bg-gray-700/50 rounded-xl">
|
|
299
|
+
<h3 className="font-semibold mb-4 text-gray-900 dark:text-white">Name/Address</h3>
|
|
300
|
+
<Name address={address} />
|
|
301
|
+
</div>
|
|
302
|
+
</div>
|
|
303
|
+
</div>
|
|
273
304
|
|
|
274
|
-
{/* Recent Activity */}
|
|
275
305
|
<div className="bg-white/80 dark:bg-gray-800/80 backdrop-blur-lg p-8 rounded-2xl shadow-lg border border-gray-200 dark:border-gray-700">
|
|
276
|
-
<h2 className="text-
|
|
306
|
+
<h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-6">Token Components</h2>
|
|
307
|
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
308
|
+
<div className="p-6 bg-gray-50 dark:bg-gray-700/50 rounded-xl">
|
|
309
|
+
<h3 className="font-semibold mb-4 text-gray-900 dark:text-white">Token Balance</h3>
|
|
310
|
+
<div className="space-y-3">
|
|
311
|
+
<div className="flex items-center justify-between p-3 bg-white dark:bg-gray-800 rounded-lg">
|
|
312
|
+
<span className="text-gray-600 dark:text-gray-400">Native (MATIC)</span>
|
|
313
|
+
<TokenBalance address={address} />
|
|
314
|
+
</div>
|
|
315
|
+
</div>
|
|
316
|
+
</div>
|
|
317
|
+
<div className="p-6 bg-gray-50 dark:bg-gray-700/50 rounded-xl">
|
|
318
|
+
<h3 className="font-semibold mb-4 text-gray-900 dark:text-white">Token Icons</h3>
|
|
319
|
+
<div className="flex items-center gap-4">
|
|
320
|
+
<div className="text-center">
|
|
321
|
+
<TokenIcon symbol="MATIC" size={32} />
|
|
322
|
+
<p className="text-xs mt-1 text-gray-600 dark:text-gray-400">MATIC</p>
|
|
323
|
+
</div>
|
|
324
|
+
<div className="text-center">
|
|
325
|
+
<TokenIcon symbol="ETH" size={32} />
|
|
326
|
+
<p className="text-xs mt-1 text-gray-600 dark:text-gray-400">ETH</p>
|
|
327
|
+
</div>
|
|
328
|
+
<div className="text-center">
|
|
329
|
+
<TokenIcon symbol="USDC" size={32} />
|
|
330
|
+
<p className="text-xs mt-1 text-gray-600 dark:text-gray-400">USDC</p>
|
|
331
|
+
</div>
|
|
332
|
+
</div>
|
|
333
|
+
</div>
|
|
334
|
+
</div>
|
|
335
|
+
</div>
|
|
336
|
+
</div>
|
|
337
|
+
)}
|
|
338
|
+
|
|
339
|
+
{/* Transactions Tab */}
|
|
340
|
+
{activeTab === 'transactions' && (
|
|
341
|
+
<div className="space-y-6">
|
|
342
|
+
<div className="bg-white/80 dark:bg-gray-800/80 backdrop-blur-lg p-8 rounded-2xl shadow-lg border border-gray-200 dark:border-gray-700">
|
|
343
|
+
<h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-6">Send Transaction</h2>
|
|
344
|
+
<p className="text-gray-600 dark:text-gray-400 mb-6">
|
|
345
|
+
Send 0.001 MATIC to a recipient address. Replace the address below with your test address.
|
|
346
|
+
</p>
|
|
347
|
+
<TransactionButton
|
|
348
|
+
text="Send 0.001 MATIC"
|
|
349
|
+
calls={[
|
|
350
|
+
{
|
|
351
|
+
to: address, // Sending to self for demo
|
|
352
|
+
value: parseEther('0.001'),
|
|
353
|
+
},
|
|
354
|
+
]}
|
|
355
|
+
onSuccess={(hash) => {
|
|
356
|
+
console.log('Transaction successful:', hash);
|
|
357
|
+
setTxHash(hash);
|
|
358
|
+
}}
|
|
359
|
+
onError={(error) => {
|
|
360
|
+
console.error('Transaction failed:', error);
|
|
361
|
+
alert('Transaction failed: ' + error.message);
|
|
362
|
+
}}
|
|
363
|
+
className="px-6 py-3 bg-gradient-to-r from-purple-500 to-pink-500 text-white rounded-lg font-semibold hover:from-purple-600 hover:to-pink-600 transition-all"
|
|
364
|
+
/>
|
|
365
|
+
|
|
366
|
+
{txHash && (
|
|
367
|
+
<div className="mt-6 p-4 bg-green-50 dark:bg-green-900/20 rounded-lg border border-green-200 dark:border-green-800">
|
|
368
|
+
<p className="font-semibold text-green-900 dark:text-green-100 mb-2">Transaction Sent!</p>
|
|
369
|
+
<p className="text-sm text-green-700 dark:text-green-300 break-all">
|
|
370
|
+
Hash: {txHash}
|
|
371
|
+
</p>
|
|
372
|
+
</div>
|
|
373
|
+
)}
|
|
374
|
+
</div>
|
|
375
|
+
|
|
376
|
+
<div className="bg-white/80 dark:bg-gray-800/80 backdrop-blur-lg p-8 rounded-2xl shadow-lg border border-gray-200 dark:border-gray-700">
|
|
377
|
+
<h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-6">Recent Activity</h2>
|
|
277
378
|
<div className="space-y-4">
|
|
278
379
|
{[
|
|
279
|
-
{ type: 'Received', amount: '100 MATIC', time: '2 mins ago'
|
|
280
|
-
{ type: 'Sent', amount: '50 MATIC', time: '1 hour ago'
|
|
281
|
-
{ type: 'Swapped', amount: '25 MATIC → 40 USDC', time: '3 hours ago'
|
|
380
|
+
{ type: 'Received', amount: '100 MATIC', time: '2 mins ago' },
|
|
381
|
+
{ type: 'Sent', amount: '50 MATIC', time: '1 hour ago' },
|
|
382
|
+
{ type: 'Swapped', amount: '25 MATIC → 40 USDC', time: '3 hours ago' },
|
|
282
383
|
].map((tx, idx) => (
|
|
283
384
|
<div key={idx} className="flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-700/50 rounded-lg">
|
|
284
385
|
<div className="flex items-center gap-4">
|
|
@@ -305,23 +406,21 @@ function Dashboard() {
|
|
|
305
406
|
</div>
|
|
306
407
|
)}
|
|
307
408
|
|
|
308
|
-
{/*
|
|
309
|
-
{activeTab === '
|
|
310
|
-
<div className="
|
|
311
|
-
<
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
<p className="text-gray-600 dark:text-gray-400">Configure your app settings here.</p>
|
|
324
|
-
</div>
|
|
409
|
+
{/* Swap Tab */}
|
|
410
|
+
{activeTab === 'swap' && (
|
|
411
|
+
<div className="max-w-2xl mx-auto">
|
|
412
|
+
<div className="bg-white/80 dark:bg-gray-800/80 backdrop-blur-lg p-8 rounded-2xl shadow-lg border border-gray-200 dark:border-gray-700">
|
|
413
|
+
<h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-6">Token Swap</h2>
|
|
414
|
+
<Swap
|
|
415
|
+
onSuccess={(hash) => {
|
|
416
|
+
console.log('Swap successful:', hash);
|
|
417
|
+
alert('Swap successful! Hash: ' + hash);
|
|
418
|
+
}}
|
|
419
|
+
onError={(error) => {
|
|
420
|
+
console.error('Swap failed:', error);
|
|
421
|
+
alert('Swap failed: ' + error.message);
|
|
422
|
+
}}
|
|
423
|
+
/>
|
|
325
424
|
</div>
|
|
326
425
|
</div>
|
|
327
426
|
)}
|
|
@@ -336,18 +435,12 @@ function AppContent() {
|
|
|
336
435
|
return isConnected ? <Dashboard /> : <LandingPage />;
|
|
337
436
|
}
|
|
338
437
|
|
|
339
|
-
function App() {
|
|
438
|
+
export default function App() {
|
|
340
439
|
const projectId = import.meta.env.VITE_REOWN_PROJECT_ID;
|
|
341
440
|
|
|
342
441
|
return (
|
|
343
|
-
<PolygonKitProvider
|
|
344
|
-
config={{
|
|
345
|
-
projectId,
|
|
346
|
-
}}
|
|
347
|
-
>
|
|
442
|
+
<PolygonKitProvider config={{ projectId }}>
|
|
348
443
|
<AppContent />
|
|
349
444
|
</PolygonKitProvider>
|
|
350
445
|
);
|
|
351
446
|
}
|
|
352
|
-
|
|
353
|
-
export default App;
|