@sanketsaagar/polygon-kit 0.1.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.mjs ADDED
@@ -0,0 +1,652 @@
1
+ // src/components/PolygonKitProvider.tsx
2
+ import { WagmiProvider } from "wagmi";
3
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
4
+ import { createAppKit } from "@reown/appkit/react";
5
+ import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
6
+
7
+ // src/constants/chains.ts
8
+ var polygon = {
9
+ id: 137,
10
+ name: "Polygon",
11
+ network: "matic",
12
+ nativeCurrency: {
13
+ name: "MATIC",
14
+ symbol: "MATIC",
15
+ decimals: 18
16
+ },
17
+ rpcUrls: {
18
+ default: {
19
+ http: ["https://polygon-rpc.com"]
20
+ },
21
+ public: {
22
+ http: ["https://polygon-rpc.com"]
23
+ }
24
+ },
25
+ blockExplorers: {
26
+ default: {
27
+ name: "PolygonScan",
28
+ url: "https://polygonscan.com"
29
+ }
30
+ }
31
+ };
32
+ var polygonMumbai = {
33
+ id: 80001,
34
+ name: "Polygon Mumbai",
35
+ network: "maticmum",
36
+ nativeCurrency: {
37
+ name: "MATIC",
38
+ symbol: "MATIC",
39
+ decimals: 18
40
+ },
41
+ rpcUrls: {
42
+ default: {
43
+ http: ["https://rpc-mumbai.maticvigil.com"]
44
+ },
45
+ public: {
46
+ http: ["https://rpc-mumbai.maticvigil.com"]
47
+ }
48
+ },
49
+ blockExplorers: {
50
+ default: {
51
+ name: "PolygonScan",
52
+ url: "https://mumbai.polygonscan.com"
53
+ }
54
+ }
55
+ };
56
+ var polygonAmoy = {
57
+ id: 80002,
58
+ name: "Polygon Amoy",
59
+ network: "polygon-amoy",
60
+ nativeCurrency: {
61
+ name: "MATIC",
62
+ symbol: "MATIC",
63
+ decimals: 18
64
+ },
65
+ rpcUrls: {
66
+ default: {
67
+ http: ["https://rpc-amoy.polygon.technology"]
68
+ },
69
+ public: {
70
+ http: ["https://rpc-amoy.polygon.technology"]
71
+ }
72
+ },
73
+ blockExplorers: {
74
+ default: {
75
+ name: "PolygonScan",
76
+ url: "https://amoy.polygonscan.com"
77
+ }
78
+ }
79
+ };
80
+ var polygonZkEVM = {
81
+ id: 1101,
82
+ name: "Polygon zkEVM",
83
+ network: "polygon-zkevm",
84
+ nativeCurrency: {
85
+ name: "Ether",
86
+ symbol: "ETH",
87
+ decimals: 18
88
+ },
89
+ rpcUrls: {
90
+ default: {
91
+ http: ["https://zkevm-rpc.com"]
92
+ },
93
+ public: {
94
+ http: ["https://zkevm-rpc.com"]
95
+ }
96
+ },
97
+ blockExplorers: {
98
+ default: {
99
+ name: "PolygonScan",
100
+ url: "https://zkevm.polygonscan.com"
101
+ }
102
+ }
103
+ };
104
+ var defaultChains = [polygon, polygonAmoy, polygonZkEVM];
105
+
106
+ // src/components/PolygonKitProvider.tsx
107
+ import { jsx } from "react/jsx-runtime";
108
+ var queryClient = new QueryClient();
109
+ var projectId = process.env.VITE_PROJECT_ID || "f6bd6e2911b56f5ac3bc8b2d0e2d7ad5";
110
+ function PolygonKitProvider({
111
+ children,
112
+ config: userConfig
113
+ }) {
114
+ const chains = userConfig?.chains || [polygon, polygonAmoy, polygonZkEVM];
115
+ const metadata = {
116
+ name: userConfig?.appName || "PolygonKit App",
117
+ description: userConfig?.appDescription || "Your Polygon App",
118
+ url: userConfig?.appUrl || "https://polygon.technology",
119
+ icons: userConfig?.appIcons || ["https://avatars.githubusercontent.com/u/21101868"]
120
+ };
121
+ const wagmiAdapter = new WagmiAdapter({
122
+ networks: chains,
123
+ projectId: userConfig?.projectId || projectId
124
+ });
125
+ createAppKit({
126
+ adapters: [wagmiAdapter],
127
+ networks: chains,
128
+ projectId: userConfig?.projectId || projectId,
129
+ metadata,
130
+ features: {
131
+ analytics: true
132
+ }
133
+ });
134
+ return /* @__PURE__ */ jsx(WagmiProvider, { config: wagmiAdapter.wagmiConfig, children: /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children }) });
135
+ }
136
+
137
+ // src/components/Wallet/Wallet.tsx
138
+ import { jsx as jsx2 } from "react/jsx-runtime";
139
+ function Wallet({ children, className = "" }) {
140
+ return /* @__PURE__ */ jsx2("div", { className: `inline-flex items-center gap-2 ${className}`, children });
141
+ }
142
+
143
+ // src/components/Wallet/ConnectWallet.tsx
144
+ import { useAccount, useDisconnect } from "wagmi";
145
+ import { useAppKit } from "@reown/appkit/react";
146
+ import { useEffect } from "react";
147
+ import { jsx as jsx3 } from "react/jsx-runtime";
148
+ function ConnectWallet({
149
+ children,
150
+ className = "",
151
+ onConnect,
152
+ onDisconnect: onDisconnectCallback
153
+ }) {
154
+ const { address, isConnected } = useAccount();
155
+ const { disconnect } = useDisconnect();
156
+ const { open } = useAppKit();
157
+ useEffect(() => {
158
+ if (isConnected && address && onConnect) {
159
+ onConnect(address);
160
+ }
161
+ }, [isConnected, address, onConnect]);
162
+ const handleConnect = () => {
163
+ open();
164
+ };
165
+ const handleDisconnect = () => {
166
+ disconnect();
167
+ if (onDisconnectCallback) {
168
+ onDisconnectCallback();
169
+ }
170
+ };
171
+ if (children) {
172
+ return /* @__PURE__ */ jsx3("div", { className, onClick: isConnected ? handleDisconnect : handleConnect, children });
173
+ }
174
+ return /* @__PURE__ */ jsx3(
175
+ "button",
176
+ {
177
+ className: `px-4 py-2 rounded-lg font-medium transition-colors ${isConnected ? "bg-red-500 hover:bg-red-600 text-white" : "bg-purple-600 hover:bg-purple-700 text-white"} ${className}`,
178
+ onClick: isConnected ? handleDisconnect : handleConnect,
179
+ children: isConnected ? "Disconnect" : "Connect Wallet"
180
+ }
181
+ );
182
+ }
183
+
184
+ // src/components/Wallet/WalletDropdown.tsx
185
+ import { useState } from "react";
186
+ import { useAccount as useAccount2, useDisconnect as useDisconnect2, useBalance, useSwitchChain } from "wagmi";
187
+
188
+ // src/utils/format.ts
189
+ function shortenAddress(address, chars = 4) {
190
+ return `${address.substring(0, chars + 2)}...${address.substring(42 - chars)}`;
191
+ }
192
+ function formatBalance(balance, decimals = 18, displayDecimals = 4) {
193
+ const divisor = BigInt(10 ** decimals);
194
+ const integerPart = balance / divisor;
195
+ const fractionalPart = balance % divisor;
196
+ const fractionalString = fractionalPart.toString().padStart(decimals, "0");
197
+ const trimmedFractional = fractionalString.substring(0, displayDecimals);
198
+ return `${integerPart}.${trimmedFractional}`;
199
+ }
200
+ function parseTokenAmount(amount, decimals = 18) {
201
+ const [integer, fraction = ""] = amount.split(".");
202
+ const paddedFraction = fraction.padEnd(decimals, "0").substring(0, decimals);
203
+ const combinedString = integer + paddedFraction;
204
+ return BigInt(combinedString);
205
+ }
206
+ function truncateText(text, maxLength) {
207
+ if (text.length <= maxLength) return text;
208
+ return `${text.substring(0, maxLength)}...`;
209
+ }
210
+
211
+ // src/components/Wallet/WalletDropdown.tsx
212
+ import { jsx as jsx4, jsxs } from "react/jsx-runtime";
213
+ function WalletDropdown({ children, className = "" }) {
214
+ const [isOpen, setIsOpen] = useState(false);
215
+ const { address, isConnected, chain } = useAccount2();
216
+ const { disconnect } = useDisconnect2();
217
+ const { data: balance } = useBalance({ address });
218
+ const { switchChain } = useSwitchChain();
219
+ const handleDisconnect = () => {
220
+ disconnect();
221
+ setIsOpen(false);
222
+ };
223
+ const handleSwitchChain = (chainId) => {
224
+ switchChain({ chainId });
225
+ setIsOpen(false);
226
+ };
227
+ if (!isConnected || !address) {
228
+ return null;
229
+ }
230
+ const supportedChains = [polygon, polygonAmoy, polygonZkEVM];
231
+ return /* @__PURE__ */ jsxs("div", { className: `relative ${className}`, children: [
232
+ /* @__PURE__ */ jsx4(
233
+ "button",
234
+ {
235
+ className: "px-4 py-2 rounded-lg bg-gray-100 hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-700 font-medium transition-colors",
236
+ onClick: () => setIsOpen(!isOpen),
237
+ children: children || shortenAddress(address)
238
+ }
239
+ ),
240
+ isOpen && /* @__PURE__ */ jsxs("div", { className: "absolute right-0 mt-2 w-64 rounded-lg shadow-lg bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 z-50", children: [
241
+ /* @__PURE__ */ jsxs("div", { className: "p-4 border-b border-gray-200 dark:border-gray-700", children: [
242
+ /* @__PURE__ */ jsx4("div", { className: "text-sm text-gray-500 dark:text-gray-400", children: "Connected Account" }),
243
+ /* @__PURE__ */ jsx4("div", { className: "font-medium mt-1", children: shortenAddress(address) }),
244
+ balance && /* @__PURE__ */ jsxs("div", { className: "text-sm text-gray-600 dark:text-gray-300 mt-1", children: [
245
+ formatBalance(balance.value),
246
+ " ",
247
+ balance.symbol
248
+ ] })
249
+ ] }),
250
+ /* @__PURE__ */ jsxs("div", { className: "p-2", children: [
251
+ /* @__PURE__ */ jsx4("div", { className: "text-xs text-gray-500 dark:text-gray-400 px-3 py-2", children: "Switch Network" }),
252
+ supportedChains.map((supportedChain) => /* @__PURE__ */ jsx4(
253
+ "button",
254
+ {
255
+ className: `w-full text-left px-3 py-2 rounded hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors ${chain?.id === supportedChain.id ? "bg-purple-50 dark:bg-purple-900/20" : ""}`,
256
+ onClick: () => handleSwitchChain(supportedChain.id),
257
+ children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
258
+ /* @__PURE__ */ jsx4("span", { children: supportedChain.name }),
259
+ chain?.id === supportedChain.id && /* @__PURE__ */ jsx4("span", { className: "text-purple-600 dark:text-purple-400", children: "\u2713" })
260
+ ] })
261
+ },
262
+ supportedChain.id
263
+ ))
264
+ ] }),
265
+ /* @__PURE__ */ jsx4("div", { className: "p-2 border-t border-gray-200 dark:border-gray-700", children: /* @__PURE__ */ jsx4(
266
+ "button",
267
+ {
268
+ className: "w-full text-left px-3 py-2 rounded hover:bg-red-50 dark:hover:bg-red-900/20 text-red-600 dark:text-red-400 transition-colors",
269
+ onClick: handleDisconnect,
270
+ children: "Disconnect"
271
+ }
272
+ ) })
273
+ ] }),
274
+ isOpen && /* @__PURE__ */ jsx4(
275
+ "div",
276
+ {
277
+ className: "fixed inset-0 z-40",
278
+ onClick: () => setIsOpen(false)
279
+ }
280
+ )
281
+ ] });
282
+ }
283
+
284
+ // src/components/Identity/Identity.tsx
285
+ import { useBalance as useBalance2 } from "wagmi";
286
+
287
+ // src/components/Identity/Avatar.tsx
288
+ import { jsx as jsx5 } from "react/jsx-runtime";
289
+ function Avatar({ address, className = "", size = 40 }) {
290
+ const generateGradient = (addr) => {
291
+ const colors = [
292
+ "#8B5CF6",
293
+ "#EC4899",
294
+ "#10B981",
295
+ "#F59E0B",
296
+ "#3B82F6",
297
+ "#EF4444",
298
+ "#6366F1",
299
+ "#14B8A6",
300
+ "#F97316",
301
+ "#06B6D4"
302
+ ];
303
+ const index1 = parseInt(addr.slice(2, 4), 16) % colors.length;
304
+ const index2 = parseInt(addr.slice(4, 6), 16) % colors.length;
305
+ return `linear-gradient(135deg, ${colors[index1]}, ${colors[index2]})`;
306
+ };
307
+ const getInitials = (addr) => {
308
+ return addr.slice(2, 4).toUpperCase();
309
+ };
310
+ return /* @__PURE__ */ jsx5(
311
+ "div",
312
+ {
313
+ className: `rounded-full flex items-center justify-center text-white font-bold ${className}`,
314
+ style: {
315
+ width: `${size}px`,
316
+ height: `${size}px`,
317
+ background: generateGradient(address),
318
+ fontSize: `${size / 2.5}px`
319
+ },
320
+ children: getInitials(address)
321
+ }
322
+ );
323
+ }
324
+
325
+ // src/components/Identity/Name.tsx
326
+ import { useEnsName } from "wagmi";
327
+ import { mainnet } from "viem/chains";
328
+ import { jsx as jsx6 } from "react/jsx-runtime";
329
+ function Name({ address, className = "" }) {
330
+ const { data: ensName } = useEnsName({
331
+ address,
332
+ chainId: mainnet.id
333
+ });
334
+ return /* @__PURE__ */ jsx6("span", { className: `font-medium ${className}`, children: ensName || shortenAddress(address) });
335
+ }
336
+
337
+ // src/components/Identity/Identity.tsx
338
+ import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
339
+ function Identity({
340
+ address,
341
+ className = "",
342
+ showAvatar = true,
343
+ showAddress = true,
344
+ showBalance = false
345
+ }) {
346
+ const { data: balance } = useBalance2({ address });
347
+ return /* @__PURE__ */ jsxs2("div", { className: `flex items-center gap-3 ${className}`, children: [
348
+ showAvatar && /* @__PURE__ */ jsx7(Avatar, { address }),
349
+ /* @__PURE__ */ jsxs2("div", { className: "flex flex-col", children: [
350
+ showAddress && /* @__PURE__ */ jsx7("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx7(Name, { address }) }),
351
+ showBalance && balance && /* @__PURE__ */ jsxs2("div", { className: "text-sm text-gray-600 dark:text-gray-400", children: [
352
+ formatBalance(balance.value, 18, 4),
353
+ " ",
354
+ balance.symbol
355
+ ] })
356
+ ] })
357
+ ] });
358
+ }
359
+
360
+ // src/components/Transaction/Transaction.tsx
361
+ import { useAccount as useAccount3 } from "wagmi";
362
+ import { jsx as jsx8 } from "react/jsx-runtime";
363
+ function Transaction({
364
+ children,
365
+ className = "",
366
+ chainId
367
+ }) {
368
+ const { chain } = useAccount3();
369
+ if (chainId && chain?.id !== chainId) {
370
+ return /* @__PURE__ */ jsx8("div", { className: `text-red-500 ${className}`, children: "Please switch to the correct network" });
371
+ }
372
+ return /* @__PURE__ */ jsx8("div", { className, children });
373
+ }
374
+
375
+ // src/components/Transaction/TransactionButton.tsx
376
+ import { useState as useState2 } from "react";
377
+ import { useSendTransaction, useWaitForTransactionReceipt } from "wagmi";
378
+ import { jsx as jsx9 } from "react/jsx-runtime";
379
+ function TransactionButton({
380
+ text = "Send Transaction",
381
+ className = "",
382
+ disabled = false,
383
+ calls = [],
384
+ onSuccess,
385
+ onError
386
+ }) {
387
+ const [isPending, setIsPending] = useState2(false);
388
+ const { sendTransaction, data: hash } = useSendTransaction();
389
+ const { isLoading: isConfirming } = useWaitForTransactionReceipt({
390
+ hash
391
+ });
392
+ const handleTransaction = async () => {
393
+ if (calls.length === 0) {
394
+ onError?.(new Error("No transaction calls provided"));
395
+ return;
396
+ }
397
+ setIsPending(true);
398
+ try {
399
+ const call = calls[0];
400
+ sendTransaction(
401
+ {
402
+ to: call.to,
403
+ data: call.data,
404
+ value: call.value
405
+ },
406
+ {
407
+ onSuccess: (hash2) => {
408
+ setIsPending(false);
409
+ onSuccess?.(hash2);
410
+ },
411
+ onError: (error) => {
412
+ setIsPending(false);
413
+ onError?.(error);
414
+ }
415
+ }
416
+ );
417
+ } catch (error) {
418
+ setIsPending(false);
419
+ onError?.(error);
420
+ }
421
+ };
422
+ const isLoading = isPending || isConfirming;
423
+ return /* @__PURE__ */ jsx9(
424
+ "button",
425
+ {
426
+ className: `px-4 py-2 rounded-lg font-medium transition-colors ${disabled || isLoading ? "bg-gray-300 dark:bg-gray-700 cursor-not-allowed" : "bg-purple-600 hover:bg-purple-700 text-white"} ${className}`,
427
+ onClick: handleTransaction,
428
+ disabled: disabled || isLoading,
429
+ children: isLoading ? "Processing..." : text
430
+ }
431
+ );
432
+ }
433
+
434
+ // src/components/Transaction/TransactionStatus.tsx
435
+ import { useWaitForTransactionReceipt as useWaitForTransactionReceipt2 } from "wagmi";
436
+ import { jsx as jsx10, jsxs as jsxs3 } from "react/jsx-runtime";
437
+ function TransactionStatus({ hash, className = "" }) {
438
+ const { isLoading, isSuccess, isError } = useWaitForTransactionReceipt2({
439
+ hash
440
+ });
441
+ return /* @__PURE__ */ jsxs3("div", { className: `flex items-center gap-2 ${className}`, children: [
442
+ isLoading && /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-2 text-yellow-600 dark:text-yellow-400", children: [
443
+ /* @__PURE__ */ jsx10("div", { className: "animate-spin rounded-full h-4 w-4 border-2 border-current border-t-transparent" }),
444
+ /* @__PURE__ */ jsx10("span", { children: "Confirming..." })
445
+ ] }),
446
+ isSuccess && /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-2 text-green-600 dark:text-green-400", children: [
447
+ /* @__PURE__ */ jsx10("span", { children: "\u2713" }),
448
+ /* @__PURE__ */ jsx10("span", { children: "Transaction confirmed" })
449
+ ] }),
450
+ isError && /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-2 text-red-600 dark:text-red-400", children: [
451
+ /* @__PURE__ */ jsx10("span", { children: "\u2717" }),
452
+ /* @__PURE__ */ jsx10("span", { children: "Transaction failed" })
453
+ ] })
454
+ ] });
455
+ }
456
+
457
+ // src/components/Token/Token.tsx
458
+ import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
459
+ function Token({ amount, symbol, className = "" }) {
460
+ const displayAmount = amount ? parseFloat(amount).toFixed(4) : "0.0000";
461
+ return /* @__PURE__ */ jsxs4("div", { className: `flex items-center gap-2 ${className}`, children: [
462
+ /* @__PURE__ */ jsx11("div", { className: "w-8 h-8 rounded-full bg-gradient-to-br from-purple-500 to-pink-500 flex items-center justify-center text-white font-bold text-sm", children: symbol ? symbol.charAt(0) : "?" }),
463
+ /* @__PURE__ */ jsxs4("div", { className: "flex flex-col", children: [
464
+ /* @__PURE__ */ jsx11("span", { className: "font-medium", children: symbol || "Unknown" }),
465
+ amount && /* @__PURE__ */ jsx11("span", { className: "text-sm text-gray-600 dark:text-gray-400", children: displayAmount })
466
+ ] })
467
+ ] });
468
+ }
469
+
470
+ // src/components/Token/TokenBalance.tsx
471
+ import { useBalance as useBalance3 } from "wagmi";
472
+ import { jsx as jsx12, jsxs as jsxs5 } from "react/jsx-runtime";
473
+ function TokenBalance({ address, token, className = "" }) {
474
+ const { data: balance, isLoading } = useBalance3({
475
+ address,
476
+ token
477
+ });
478
+ if (isLoading) {
479
+ return /* @__PURE__ */ jsx12("div", { className: `animate-pulse ${className}`, children: /* @__PURE__ */ jsx12("div", { className: "h-6 bg-gray-200 dark:bg-gray-700 rounded w-24" }) });
480
+ }
481
+ if (!balance) {
482
+ return /* @__PURE__ */ jsx12("div", { className, children: "-" });
483
+ }
484
+ return /* @__PURE__ */ jsxs5("div", { className: `font-medium ${className}`, children: [
485
+ formatBalance(balance.value),
486
+ " ",
487
+ balance.symbol
488
+ ] });
489
+ }
490
+
491
+ // src/components/Swap/Swap.tsx
492
+ import { useState as useState3 } from "react";
493
+ import { jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
494
+ function Swap({ className = "", onSuccess, onError }) {
495
+ const [fromAmount, setFromAmount] = useState3("");
496
+ const [toAmount, setToAmount] = useState3("");
497
+ const [isLoading, setIsLoading] = useState3(false);
498
+ const handleSwap = async () => {
499
+ setIsLoading(true);
500
+ try {
501
+ await new Promise((resolve) => setTimeout(resolve, 2e3));
502
+ onSuccess?.("0x...");
503
+ } catch (error) {
504
+ onError?.(error);
505
+ } finally {
506
+ setIsLoading(false);
507
+ }
508
+ };
509
+ return /* @__PURE__ */ jsxs6("div", { className: `bg-white dark:bg-gray-900 rounded-xl p-4 shadow-lg border border-gray-200 dark:border-gray-700 ${className}`, children: [
510
+ /* @__PURE__ */ jsx13("h3", { className: "text-lg font-bold mb-4", children: "Swap Tokens" }),
511
+ /* @__PURE__ */ jsxs6("div", { className: "space-y-2", children: [
512
+ /* @__PURE__ */ jsxs6("div", { className: "bg-gray-50 dark:bg-gray-800 rounded-lg p-3", children: [
513
+ /* @__PURE__ */ jsx13("label", { className: "text-sm text-gray-600 dark:text-gray-400", children: "From" }),
514
+ /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-2 mt-1", children: [
515
+ /* @__PURE__ */ jsx13(
516
+ "input",
517
+ {
518
+ type: "number",
519
+ value: fromAmount,
520
+ onChange: (e) => setFromAmount(e.target.value),
521
+ placeholder: "0.0",
522
+ className: "flex-1 bg-transparent text-2xl font-medium outline-none"
523
+ }
524
+ ),
525
+ /* @__PURE__ */ jsx13("button", { className: "px-3 py-1 bg-gray-200 dark:bg-gray-700 rounded-lg font-medium", children: "MATIC" })
526
+ ] })
527
+ ] }),
528
+ /* @__PURE__ */ jsx13("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx13("button", { className: "p-2 bg-purple-100 dark:bg-purple-900 rounded-lg hover:bg-purple-200 dark:hover:bg-purple-800 transition-colors", children: "\u2193" }) }),
529
+ /* @__PURE__ */ jsxs6("div", { className: "bg-gray-50 dark:bg-gray-800 rounded-lg p-3", children: [
530
+ /* @__PURE__ */ jsx13("label", { className: "text-sm text-gray-600 dark:text-gray-400", children: "To" }),
531
+ /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-2 mt-1", children: [
532
+ /* @__PURE__ */ jsx13(
533
+ "input",
534
+ {
535
+ type: "number",
536
+ value: toAmount,
537
+ onChange: (e) => setToAmount(e.target.value),
538
+ placeholder: "0.0",
539
+ className: "flex-1 bg-transparent text-2xl font-medium outline-none"
540
+ }
541
+ ),
542
+ /* @__PURE__ */ jsx13("button", { className: "px-3 py-1 bg-gray-200 dark:bg-gray-700 rounded-lg font-medium", children: "USDC" })
543
+ ] })
544
+ ] })
545
+ ] }),
546
+ /* @__PURE__ */ jsx13(
547
+ "button",
548
+ {
549
+ onClick: handleSwap,
550
+ disabled: isLoading || !fromAmount,
551
+ className: `w-full mt-4 px-4 py-3 rounded-lg font-medium transition-colors ${isLoading || !fromAmount ? "bg-gray-300 dark:bg-gray-700 cursor-not-allowed" : "bg-purple-600 hover:bg-purple-700 text-white"}`,
552
+ children: isLoading ? "Swapping..." : "Swap"
553
+ }
554
+ ),
555
+ /* @__PURE__ */ jsx13("div", { className: "mt-3 text-xs text-gray-500 dark:text-gray-400 text-center", children: "Powered by Polygon DEX Aggregators" })
556
+ ] });
557
+ }
558
+
559
+ // src/hooks/usePolygonKit.ts
560
+ import { useAccount as useAccount4, useBalance as useBalance4, useConnect, useDisconnect as useDisconnect3 } from "wagmi";
561
+ function usePolygonKit() {
562
+ const { address, isConnected, chain } = useAccount4();
563
+ const { connect, connectors } = useConnect();
564
+ const { disconnect } = useDisconnect3();
565
+ const { data: balance } = useBalance4({ address });
566
+ const connectWallet = () => {
567
+ const injectedConnector = connectors.find((c) => c.id === "injected");
568
+ if (injectedConnector) {
569
+ connect({ connector: injectedConnector });
570
+ }
571
+ };
572
+ return {
573
+ address,
574
+ isConnected,
575
+ chain,
576
+ balance,
577
+ connect: connectWallet,
578
+ disconnect,
579
+ connectors
580
+ };
581
+ }
582
+
583
+ // src/hooks/usePolygonBalance.ts
584
+ import { useBalance as useBalance5 } from "wagmi";
585
+ function usePolygonBalance(address, token) {
586
+ const { data, isLoading, isError, refetch } = useBalance5({
587
+ address,
588
+ token
589
+ });
590
+ const formattedBalance = data ? formatBalance(data.value, data.decimals) : "0";
591
+ return {
592
+ balance: data?.value,
593
+ formatted: formattedBalance,
594
+ symbol: data?.symbol,
595
+ decimals: data?.decimals,
596
+ isLoading,
597
+ isError,
598
+ refetch
599
+ };
600
+ }
601
+
602
+ // src/hooks/usePolygonTransaction.ts
603
+ import { useSendTransaction as useSendTransaction2, useWaitForTransactionReceipt as useWaitForTransactionReceipt3 } from "wagmi";
604
+ function usePolygonTransaction() {
605
+ const { sendTransaction, data: hash, isPending, isError, error } = useSendTransaction2();
606
+ const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt3({
607
+ hash
608
+ });
609
+ const send = (to, value, data) => {
610
+ sendTransaction({
611
+ to,
612
+ value,
613
+ data
614
+ });
615
+ };
616
+ return {
617
+ send,
618
+ hash,
619
+ isPending,
620
+ isConfirming,
621
+ isSuccess,
622
+ isError,
623
+ error
624
+ };
625
+ }
626
+ export {
627
+ Avatar,
628
+ ConnectWallet,
629
+ Identity,
630
+ Name,
631
+ PolygonKitProvider,
632
+ Swap,
633
+ Token,
634
+ TokenBalance,
635
+ Transaction,
636
+ TransactionButton,
637
+ TransactionStatus,
638
+ Wallet,
639
+ WalletDropdown,
640
+ defaultChains,
641
+ formatBalance,
642
+ parseTokenAmount,
643
+ polygon,
644
+ polygonAmoy,
645
+ polygonMumbai,
646
+ polygonZkEVM,
647
+ shortenAddress,
648
+ truncateText,
649
+ usePolygonBalance,
650
+ usePolygonKit,
651
+ usePolygonTransaction
652
+ };