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