@cicero-zcash/react 0.0.0-stage → 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,2602 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ CiceroAccountModal: () => CiceroAccountModal,
34
+ CiceroConnectButton: () => CiceroConnectButton,
35
+ CiceroConnectModal: () => CiceroConnectModal,
36
+ CiceroInvoice: () => CiceroInvoice,
37
+ CiceroModal: () => CiceroModal,
38
+ CiceroPayButton: () => CiceroPayButton,
39
+ CiceroProvider: () => CiceroProvider,
40
+ CiceroQRCode: () => CiceroQRCode,
41
+ ZucchiniWalletAdapter: () => ZucchiniWalletAdapter,
42
+ burnerWallet: () => burnerWallet,
43
+ decodeBase64Url: () => decodeBase64Url,
44
+ encodeBase64Url: () => encodeBase64Url,
45
+ generateZip321Uri: () => generateZip321Uri,
46
+ getAddressType: () => getAddressType,
47
+ getDefaultWallets: () => getDefaultWallets,
48
+ getWalletDeepLinks: () => getWalletDeepLinks,
49
+ isShieldedAddress: () => isShieldedAddress,
50
+ parseZip321Uri: () => parseZip321Uri,
51
+ truncateAddress: () => truncateAddress,
52
+ useAccount: () => useAccount,
53
+ useAccountModal: () => useAccountModal,
54
+ useBalance: () => useBalance,
55
+ useCicero: () => useCicero,
56
+ useCiceroPayment: () => useCiceroPayment,
57
+ useConnectModal: () => useConnectModal,
58
+ useZcashPrice: () => useZcashPrice,
59
+ useZucchiniWallet: () => useZucchiniWallet,
60
+ validateMemoSupport: () => validateMemoSupport,
61
+ viewingKeyWallet: () => viewingKeyWallet,
62
+ ywallet: () => ywallet,
63
+ zashiWallet: () => zashiWallet,
64
+ zucchiniWallet: () => zucchiniWallet
65
+ });
66
+ module.exports = __toCommonJS(index_exports);
67
+
68
+ // src/context/CiceroContext.tsx
69
+ var import_react4 = require("react");
70
+
71
+ // src/utils/zip321.ts
72
+ function encodeBase64Url(str) {
73
+ try {
74
+ const bytes = new TextEncoder().encode(str);
75
+ let binary = "";
76
+ const len = bytes.byteLength;
77
+ for (let i = 0; i < len; i++) {
78
+ binary += String.fromCharCode(bytes[i]);
79
+ }
80
+ const base64 = btoa(binary);
81
+ return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
82
+ } catch {
83
+ return "";
84
+ }
85
+ }
86
+ function decodeBase64Url(base64url) {
87
+ try {
88
+ let base64 = base64url.replace(/-/g, "+").replace(/_/g, "/");
89
+ while (base64.length % 4) {
90
+ base64 += "=";
91
+ }
92
+ const binary = atob(base64);
93
+ const bytes = new Uint8Array(binary.length);
94
+ for (let i = 0; i < binary.length; i++) {
95
+ bytes[i] = binary.charCodeAt(i);
96
+ }
97
+ return new TextDecoder().decode(bytes);
98
+ } catch {
99
+ return "";
100
+ }
101
+ }
102
+ function generateZip321Uri({
103
+ address,
104
+ amount,
105
+ memo,
106
+ message
107
+ }) {
108
+ const cleanAddress = address.trim();
109
+ const params = new URLSearchParams();
110
+ if (amount !== void 0 && amount !== null && amount !== "") {
111
+ const numAmount = typeof amount === "number" ? amount : parseFloat(amount);
112
+ if (!isNaN(numAmount) && numAmount > 0) {
113
+ params.append("amount", numAmount.toString());
114
+ }
115
+ }
116
+ if (memo && memo.trim().length > 0) {
117
+ const encodedMemo = encodeBase64Url(memo.trim());
118
+ if (encodedMemo) {
119
+ params.append("memo", encodedMemo);
120
+ }
121
+ }
122
+ if (message && message.trim().length > 0) {
123
+ params.append("message", message.trim());
124
+ }
125
+ const queryString = params.toString();
126
+ return queryString ? `zcash:${cleanAddress}?${queryString}` : `zcash:${cleanAddress}`;
127
+ }
128
+ function parseZip321Uri(rawUri) {
129
+ const trimmed = rawUri.trim();
130
+ const withoutScheme = trimmed.startsWith("zcash:") ? trimmed.slice(6) : trimmed;
131
+ const [addressPart, queryPart] = withoutScheme.split("?");
132
+ const result = {
133
+ address: addressPart || "",
134
+ rawUri: trimmed
135
+ };
136
+ if (!queryPart) {
137
+ return result;
138
+ }
139
+ const searchParams = new URLSearchParams(queryPart);
140
+ const amount = searchParams.get("amount");
141
+ const memo = searchParams.get("memo");
142
+ const message = searchParams.get("message");
143
+ if (amount) result.amount = amount;
144
+ if (memo) result.memo = decodeBase64Url(memo);
145
+ if (message) result.message = message;
146
+ return result;
147
+ }
148
+ function getWalletDeepLinks(zip321Uri) {
149
+ return {
150
+ generic: zip321Uri,
151
+ zashi: zip321Uri,
152
+ // Zashi registers the native zcash: URI handler on iOS/Android
153
+ ywallet: zip321Uri
154
+ // Ywallet also natively handles zcash: protocol
155
+ };
156
+ }
157
+
158
+ // src/wallet/zucchini.ts
159
+ var ZucchiniWalletAdapter = class _ZucchiniWalletAdapter {
160
+ client = null;
161
+ provider = null;
162
+ _connected = false;
163
+ _address = null;
164
+ _lastAccounts = [];
165
+ /**
166
+ * Checks whether the Zucchini Wallet extension is installed and its
167
+ * provider is available in the current browser environment.
168
+ */
169
+ static isAvailable() {
170
+ if (typeof window === "undefined") return false;
171
+ const win = window;
172
+ if (win.zucchini && typeof win.zucchini.request === "function") {
173
+ return true;
174
+ }
175
+ if (win.zcash) {
176
+ return true;
177
+ }
178
+ return !!win.zucchini;
179
+ }
180
+ /**
181
+ * Subscribes to wallet readiness. Fires callback immediately if already available,
182
+ * or listens for injection events / polls briefly for late extension initialization.
183
+ */
184
+ static onReady(callback) {
185
+ if (typeof window === "undefined") return () => {
186
+ };
187
+ if (_ZucchiniWalletAdapter.isAvailable()) {
188
+ callback();
189
+ return () => {
190
+ };
191
+ }
192
+ const handler = () => callback();
193
+ window.addEventListener("zucchini#initialized", handler);
194
+ window.addEventListener("zcash#initialized", handler);
195
+ const interval = setInterval(() => {
196
+ if (_ZucchiniWalletAdapter.isAvailable()) {
197
+ clearInterval(interval);
198
+ callback();
199
+ }
200
+ }, 150);
201
+ const timeout = setTimeout(() => {
202
+ clearInterval(interval);
203
+ }, 3500);
204
+ return () => {
205
+ window.removeEventListener("zucchini#initialized", handler);
206
+ window.removeEventListener("zcash#initialized", handler);
207
+ clearInterval(interval);
208
+ clearTimeout(timeout);
209
+ };
210
+ }
211
+ /**
212
+ * Discovers and initializes the Zucchini Client using @zucchinifi/dapp-sdk/zcash
213
+ * with graceful fallback to raw window.zucchini / window.zcash globals.
214
+ */
215
+ async getClient() {
216
+ if (this.client) return this.client;
217
+ if (typeof window === "undefined") {
218
+ throw new Error("Zucchini Wallet is only available in browser environments.");
219
+ }
220
+ const win = window;
221
+ let rawProvider = win.zucchini || win.zcash;
222
+ try {
223
+ const { discoverZucchiniProvider, createZucchiniClient } = await import("@zucchinifi/dapp-sdk/zcash");
224
+ const discovered = discoverZucchiniProvider() || rawProvider;
225
+ if (discovered) {
226
+ this.provider = discovered;
227
+ this.client = createZucchiniClient(discovered);
228
+ return this.client;
229
+ }
230
+ } catch {
231
+ }
232
+ if (rawProvider) {
233
+ this.provider = rawProvider;
234
+ this.client = {
235
+ async connect(req) {
236
+ if (typeof rawProvider.connect === "function") {
237
+ return rawProvider.connect(req?.permissions || ["view_addresses", "view_balance", "send_transaction"]);
238
+ }
239
+ if (typeof rawProvider.request === "function") {
240
+ return rawProvider.request({ method: "connect", params: req });
241
+ }
242
+ return { connected: true };
243
+ },
244
+ async disconnect() {
245
+ if (typeof rawProvider.disconnect === "function") {
246
+ return rawProvider.disconnect();
247
+ }
248
+ },
249
+ async requestPayment(uri) {
250
+ if (typeof rawProvider.request === "function") {
251
+ const res = await rawProvider.request({
252
+ method: "zcash_requestPayment",
253
+ params: { uri }
254
+ });
255
+ return { txid: res?.txid || res?.txId || res };
256
+ }
257
+ throw new Error("Direct ZIP-321 send not supported by provider");
258
+ },
259
+ async getAddresses() {
260
+ if (typeof rawProvider.request === "function") {
261
+ return rawProvider.request({ method: "getAddresses" });
262
+ }
263
+ return {};
264
+ },
265
+ on(event, listener) {
266
+ rawProvider.on?.(event, listener);
267
+ return () => rawProvider.off?.(event, listener);
268
+ }
269
+ };
270
+ return this.client;
271
+ }
272
+ throw new Error(
273
+ "Zucchini Wallet extension not detected. Please install it from the Chrome Web Store or ensure the side-panel is open."
274
+ );
275
+ }
276
+ /**
277
+ * Requests connection with view_addresses and send_transaction permissions.
278
+ * Resolves the user's active Shielded Unified Address.
279
+ */
280
+ async connect() {
281
+ const client = await this.getClient();
282
+ const connection = await client.connect({
283
+ permissions: ["view_addresses", "view_balance", "send_transaction"]
284
+ });
285
+ let address = void 0;
286
+ if (connection?.accounts && connection.accounts.length > 0) {
287
+ address = connection.accounts[0].address;
288
+ }
289
+ if (!address && typeof client.getAddresses === "function") {
290
+ try {
291
+ const addresses = await client.getAddresses();
292
+ address = addresses?.unified || addresses?.orchard || addresses?.sapling || addresses?.transparent;
293
+ } catch {
294
+ }
295
+ }
296
+ this._lastAccounts = connection?.accounts || [];
297
+ const balance = await this.getBalance({ address });
298
+ this._connected = true;
299
+ this._address = address || null;
300
+ return {
301
+ address,
302
+ connected: true,
303
+ balance: balance ?? void 0
304
+ };
305
+ }
306
+ /**
307
+ * Helper to normalize raw balance formats (e.g. number, string, zatoshis, or pool totals).
308
+ */
309
+ parseBalancePayload(payload) {
310
+ if (payload === void 0 || payload === null) return null;
311
+ if (typeof payload === "number") {
312
+ return payload > 1e6 ? payload / 1e8 : payload;
313
+ }
314
+ if (typeof payload === "string") {
315
+ const parsed = parseFloat(payload);
316
+ if (!isNaN(parsed)) {
317
+ return parsed > 1e6 ? parsed / 1e8 : parsed;
318
+ }
319
+ }
320
+ if (typeof payload === "object") {
321
+ const cand = payload.total ?? payload.balance ?? payload.amount ?? payload.zec ?? payload.value ?? payload.zatoshis;
322
+ if (cand !== void 0 && cand !== null) {
323
+ return this.parseBalancePayload(cand);
324
+ }
325
+ let sum = 0;
326
+ let hasPool = false;
327
+ for (const pool of ["orchard", "sapling", "transparent", "shielded", "unshielded"]) {
328
+ if (payload[pool] !== void 0) {
329
+ const v = this.parseBalancePayload(payload[pool]);
330
+ if (v !== null) {
331
+ sum += v;
332
+ hasPool = true;
333
+ }
334
+ }
335
+ }
336
+ if (hasPool) return sum;
337
+ }
338
+ return null;
339
+ }
340
+ /**
341
+ * Reads real-time balance from Zucchini provider.
342
+ */
343
+ async getBalance(options) {
344
+ const raw = this.provider || (typeof window !== "undefined" ? window.zucchini || window.zcash : null);
345
+ const methods = [
346
+ "getBalance",
347
+ "getBalances",
348
+ "zcash_getBalance",
349
+ "zcash_getBalances",
350
+ "view_balance",
351
+ "getBalanceSummary"
352
+ ];
353
+ if (raw && typeof raw.request === "function") {
354
+ for (const method of methods) {
355
+ try {
356
+ const res = await raw.request({ method, params: options });
357
+ const parsed = this.parseBalancePayload(res);
358
+ if (parsed !== null) return parsed;
359
+ } catch {
360
+ }
361
+ }
362
+ }
363
+ if (this._lastAccounts && this._lastAccounts.length > 0) {
364
+ for (const acc of this._lastAccounts) {
365
+ const parsed = this.parseBalancePayload(acc);
366
+ if (parsed !== null) return parsed;
367
+ }
368
+ }
369
+ return null;
370
+ }
371
+ /**
372
+ * Sends payment via standard ZIP-321 URI requestPayment or transaction fallback.
373
+ */
374
+ async requestPayment(params) {
375
+ if (!this._connected) {
376
+ await this.connect();
377
+ }
378
+ const client = await this.getClient();
379
+ const numAmount = typeof params.amount === "number" ? params.amount : parseFloat(params.amount);
380
+ if (isNaN(numAmount) || numAmount <= 0) {
381
+ throw new Error("Payment amount must be a positive number.");
382
+ }
383
+ const uri = generateZip321Uri({
384
+ address: params.recipient.trim(),
385
+ amount: numAmount,
386
+ memo: params.memo?.trim()
387
+ });
388
+ try {
389
+ if (typeof client.requestPayment === "function") {
390
+ const res = await client.requestPayment(uri);
391
+ const txId = res?.txid || res?.txId || "";
392
+ return { txId, submitted: true };
393
+ }
394
+ } catch (e) {
395
+ }
396
+ if (typeof client.requestTransaction === "function") {
397
+ const zatoshis = BigInt(Math.round(numAmount * 1e8));
398
+ const res = await client.requestTransaction({
399
+ amountZatoshis: zatoshis,
400
+ recipient: params.recipient.trim(),
401
+ memo: params.memo?.trim()
402
+ });
403
+ return { txId: res?.txid || "", submitted: true };
404
+ }
405
+ throw new Error("Zucchini Wallet does not support payment dispatch.");
406
+ }
407
+ /**
408
+ * Subscribes to accountsChanged events.
409
+ */
410
+ onAccountsChanged(listener) {
411
+ if (this.client?.on) {
412
+ return this.client.on("accountsChanged", listener);
413
+ }
414
+ if (this.provider?.on) {
415
+ this.provider.on("accountsChanged", listener);
416
+ return () => this.provider?.off?.("accountsChanged", listener);
417
+ }
418
+ return () => {
419
+ };
420
+ }
421
+ /**
422
+ * Subscribes to disconnect events.
423
+ */
424
+ onDisconnect(listener) {
425
+ if (this.client?.on) {
426
+ return this.client.on("disconnect", listener);
427
+ }
428
+ if (this.provider?.on) {
429
+ this.provider.on("disconnect", listener);
430
+ return () => this.provider?.off?.("disconnect", listener);
431
+ }
432
+ return () => {
433
+ };
434
+ }
435
+ /**
436
+ * Disconnects the current session.
437
+ */
438
+ async disconnect() {
439
+ try {
440
+ if (this.client?.disconnect) {
441
+ await this.client.disconnect();
442
+ } else if (this.provider?.disconnect) {
443
+ await this.provider.disconnect();
444
+ }
445
+ } catch {
446
+ }
447
+ this._connected = false;
448
+ this._address = null;
449
+ }
450
+ get isConnected() {
451
+ return this._connected;
452
+ }
453
+ get address() {
454
+ return this._address;
455
+ }
456
+ };
457
+
458
+ // src/wallets/zucchini.ts
459
+ var adapter = new ZucchiniWalletAdapter();
460
+ var zucchiniWallet = {
461
+ id: "zucchini",
462
+ name: "Zucchini Wallet",
463
+ icon: "\u{1F952}",
464
+ description: "In-browser Chrome extension with 1-click side-panel approvals",
465
+ category: "extension",
466
+ downloadUrl: "https://chromewebstore.google.com/detail/zucchini-wallet",
467
+ isAvailable: () => ZucchiniWalletAdapter.isAvailable(),
468
+ connect: async (options) => {
469
+ const session = await adapter.connect();
470
+ return {
471
+ address: session.address,
472
+ connected: true,
473
+ network: options?.network || "mainnet",
474
+ walletId: "zucchini",
475
+ balance: session.balance
476
+ };
477
+ },
478
+ disconnect: async () => {
479
+ await adapter.disconnect();
480
+ },
481
+ getBalance: async (options) => {
482
+ return adapter.getBalance(options);
483
+ },
484
+ sendPayment: async (params) => {
485
+ const res = await adapter.requestPayment({
486
+ recipient: params.recipient,
487
+ amount: params.amount,
488
+ memo: params.memo
489
+ });
490
+ return {
491
+ txId: res.txId,
492
+ submitted: res.submitted
493
+ };
494
+ }
495
+ };
496
+
497
+ // src/wallets/zashi.ts
498
+ var zashiWallet = {
499
+ id: "zashi",
500
+ name: "Zashi by ECC",
501
+ icon: "\u{1F6E1}\uFE0F",
502
+ description: "Official zero-knowledge mobile wallet by Electric Coin Co.",
503
+ category: "mobile",
504
+ downloadUrl: "https://electriccoin.co/zashi/",
505
+ isAvailable: () => true,
506
+ // Available via mobile QR or deep link
507
+ connect: async (options) => {
508
+ return {
509
+ connected: true,
510
+ network: options?.network || "mainnet",
511
+ walletId: "zashi"
512
+ };
513
+ },
514
+ sendPayment: async (params) => {
515
+ const rawUri = generateZip321Uri({
516
+ address: params.recipient,
517
+ amount: params.amount,
518
+ memo: params.memo,
519
+ message: params.message
520
+ });
521
+ if (typeof window !== "undefined") {
522
+ window.location.href = rawUri;
523
+ }
524
+ return {
525
+ txId: "",
526
+ submitted: false,
527
+ rawUri
528
+ };
529
+ }
530
+ };
531
+
532
+ // src/wallets/ywallet.ts
533
+ var ywallet = {
534
+ id: "ywallet",
535
+ name: "Ywallet",
536
+ icon: "\u26A1",
537
+ description: "Fast-syncing multi-platform shielded wallet for mobile & desktop",
538
+ category: "mobile",
539
+ downloadUrl: "https://ywallet.app/",
540
+ isAvailable: () => true,
541
+ connect: async (options) => {
542
+ return {
543
+ connected: true,
544
+ network: options?.network || "mainnet",
545
+ walletId: "ywallet"
546
+ };
547
+ },
548
+ sendPayment: async (params) => {
549
+ const rawUri = generateZip321Uri({
550
+ address: params.recipient,
551
+ amount: params.amount,
552
+ memo: params.memo,
553
+ message: params.message
554
+ });
555
+ if (typeof window !== "undefined") {
556
+ window.location.href = rawUri;
557
+ }
558
+ return {
559
+ txId: "",
560
+ submitted: false,
561
+ rawUri
562
+ };
563
+ }
564
+ };
565
+
566
+ // src/wallets/viewingKey.ts
567
+ var viewingKeyWallet = {
568
+ id: "viewing-key",
569
+ name: "Viewing Key / Auditor",
570
+ icon: "\u{1F441}\uFE0F",
571
+ description: "Connect with a Unified Address or Viewing Key for read-only audit mode",
572
+ category: "read-only",
573
+ isAvailable: () => true,
574
+ connect: async (options) => {
575
+ return {
576
+ connected: true,
577
+ network: options?.network || "mainnet",
578
+ walletId: "viewing-key"
579
+ };
580
+ }
581
+ };
582
+
583
+ // src/wallets/burner.ts
584
+ var MOCK_BURNER_ADDR = "u1qwe829xkps9482mzsll049281kz8471hzkas093847zkd09472619as8361048293710293847102938471029384710";
585
+ var burnerWallet = {
586
+ id: "burner",
587
+ name: "Dev Session Wallet",
588
+ icon: "\u{1F9EA}",
589
+ description: "Instant ephemeral shielded test wallet for rapid local testing",
590
+ category: "developer",
591
+ isAvailable: () => true,
592
+ connect: async (options) => {
593
+ return {
594
+ address: MOCK_BURNER_ADDR,
595
+ connected: true,
596
+ network: options?.network || "testnet",
597
+ walletId: "burner"
598
+ };
599
+ },
600
+ sendPayment: async (_params) => {
601
+ const mockTxId = `0x${Array.from(
602
+ { length: 64 },
603
+ () => Math.floor(Math.random() * 16).toString(16)
604
+ ).join("")}`;
605
+ return {
606
+ txId: mockTxId,
607
+ submitted: true
608
+ };
609
+ }
610
+ };
611
+
612
+ // src/wallets/index.ts
613
+ function getDefaultWallets() {
614
+ return [
615
+ zucchiniWallet,
616
+ zashiWallet,
617
+ ywallet,
618
+ viewingKeyWallet,
619
+ burnerWallet
620
+ ];
621
+ }
622
+
623
+ // src/hooks/useZcashPrice.ts
624
+ var import_react = require("react");
625
+ var cachedPrice = null;
626
+ var lastFetchTime = 0;
627
+ var CACHE_DURATION_MS = 6e4;
628
+ function useZcashPrice(enabled = true) {
629
+ const [state, setState] = (0, import_react.useState)(() => ({
630
+ usdPrice: cachedPrice,
631
+ loading: !cachedPrice && enabled,
632
+ error: null,
633
+ lastUpdated: lastFetchTime || null
634
+ }));
635
+ (0, import_react.useEffect)(() => {
636
+ if (!enabled) return;
637
+ let isMounted = true;
638
+ const now = Date.now();
639
+ if (cachedPrice && now - lastFetchTime < CACHE_DURATION_MS) {
640
+ setState((prev) => {
641
+ if (prev.usdPrice === cachedPrice && !prev.loading) return prev;
642
+ return {
643
+ usdPrice: cachedPrice,
644
+ loading: false,
645
+ error: null,
646
+ lastUpdated: lastFetchTime
647
+ };
648
+ });
649
+ return;
650
+ }
651
+ async function fetchPrice() {
652
+ try {
653
+ const res = await fetch(
654
+ "https://api.coingecko.com/api/v3/simple/price?ids=zcash&vs_currencies=usd",
655
+ { signal: AbortSignal.timeout(4e3) }
656
+ );
657
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
658
+ const data = await res.json();
659
+ const price = data?.zcash?.usd;
660
+ if (typeof price === "number") {
661
+ cachedPrice = price;
662
+ lastFetchTime = Date.now();
663
+ if (isMounted) {
664
+ setState({
665
+ usdPrice: price,
666
+ loading: false,
667
+ error: null,
668
+ lastUpdated: lastFetchTime
669
+ });
670
+ }
671
+ return;
672
+ }
673
+ throw new Error("Invalid price payload");
674
+ } catch (err) {
675
+ try {
676
+ const binanceRes = await fetch(
677
+ "https://api.binance.com/api/v3/ticker/price?symbol=ZECUSDT",
678
+ { signal: AbortSignal.timeout(3e3) }
679
+ );
680
+ if (binanceRes.ok) {
681
+ const bData = await binanceRes.json();
682
+ const bPrice = parseFloat(bData.price);
683
+ if (!isNaN(bPrice) && bPrice > 0) {
684
+ cachedPrice = bPrice;
685
+ lastFetchTime = Date.now();
686
+ if (isMounted) {
687
+ setState({
688
+ usdPrice: bPrice,
689
+ loading: false,
690
+ error: null,
691
+ lastUpdated: lastFetchTime
692
+ });
693
+ }
694
+ return;
695
+ }
696
+ }
697
+ } catch {
698
+ }
699
+ if (isMounted) {
700
+ const fallback = cachedPrice ?? 38.5;
701
+ setState({
702
+ usdPrice: fallback,
703
+ loading: false,
704
+ error: err instanceof Error ? err.message : "Price fetch error",
705
+ lastUpdated: Date.now()
706
+ });
707
+ }
708
+ }
709
+ }
710
+ fetchPrice();
711
+ return () => {
712
+ isMounted = false;
713
+ };
714
+ }, [enabled]);
715
+ const convertZecToUsd = (0, import_react.useCallback)(
716
+ (zecAmount) => {
717
+ const num = typeof zecAmount === "number" ? zecAmount : parseFloat(zecAmount);
718
+ if (isNaN(num) || state.usdPrice === null) return null;
719
+ return (num * state.usdPrice).toFixed(2);
720
+ },
721
+ [state.usdPrice]
722
+ );
723
+ return {
724
+ ...state,
725
+ convertZecToUsd
726
+ };
727
+ }
728
+
729
+ // src/components/CiceroConnectModal.tsx
730
+ var import_react2 = require("react");
731
+ var import_react_dom = require("react-dom");
732
+ var import_lucide_react = require("lucide-react");
733
+
734
+ // src/components/CiceroQRCode.tsx
735
+ var import_qrcode = require("qrcode.react");
736
+ var import_jsx_runtime = require("react/jsx-runtime");
737
+ var CiceroQRCode = ({
738
+ value,
739
+ size = 200,
740
+ className = "",
741
+ level = "M",
742
+ includeMargin = true
743
+ }) => {
744
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
745
+ "div",
746
+ {
747
+ className: `inline-flex items-center justify-center p-3 bg-white rounded-lg border border-[#ededed] shadow-sm ${className}`,
748
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
749
+ import_qrcode.QRCodeSVG,
750
+ {
751
+ value,
752
+ size,
753
+ level,
754
+ includeMargin,
755
+ imageSettings: {
756
+ src: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23171717'%3E%3Cpath d='M12 2L3 7v6c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V7l-9-5zm0 4.5l5 2.5v4.5c0 3.3-2.1 6.3-5 7.2-2.9-.9-5-3.9-5-7.2V9l5-2.5z'/%3E%3Cpath d='M10 11h4l-3 4h3' stroke='%233ecf8e' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E",
757
+ height: 28,
758
+ width: 28,
759
+ excavate: true
760
+ }
761
+ }
762
+ )
763
+ }
764
+ );
765
+ };
766
+
767
+ // src/components/CiceroConnectModal.tsx
768
+ var import_jsx_runtime2 = require("react/jsx-runtime");
769
+ var CiceroConnectModal = ({
770
+ isOpen: propIsOpen,
771
+ onClose: propOnClose
772
+ }) => {
773
+ const {
774
+ isConnectModalOpen,
775
+ closeConnectModal,
776
+ wallets,
777
+ connect,
778
+ network,
779
+ appName
780
+ } = useCicero();
781
+ const isOpen = propIsOpen !== void 0 ? propIsOpen : isConnectModalOpen;
782
+ const handleClose = propOnClose || closeConnectModal;
783
+ const [selectedWalletId, setSelectedWalletId] = (0, import_react2.useState)("zucchini");
784
+ const [customKeyInput, setCustomKeyInput] = (0, import_react2.useState)("");
785
+ const [error, setError] = (0, import_react2.useState)(null);
786
+ const [isSubmitting, setIsSubmitting] = (0, import_react2.useState)(false);
787
+ const [mounted, setMounted] = (0, import_react2.useState)(false);
788
+ const [, setAvailabilityTick] = (0, import_react2.useState)(0);
789
+ (0, import_react2.useEffect)(() => {
790
+ setMounted(true);
791
+ }, []);
792
+ (0, import_react2.useEffect)(() => {
793
+ if (!isOpen) return;
794
+ const cleanupReady = ZucchiniWalletAdapter.onReady(() => {
795
+ setAvailabilityTick((t) => t + 1);
796
+ });
797
+ const interval = setInterval(() => {
798
+ setAvailabilityTick((t) => t + 1);
799
+ }, 600);
800
+ return () => {
801
+ cleanupReady();
802
+ clearInterval(interval);
803
+ };
804
+ }, [isOpen]);
805
+ (0, import_react2.useEffect)(() => {
806
+ const handleKeyDown = (e) => {
807
+ if (e.key === "Escape" && isOpen) {
808
+ handleClose();
809
+ }
810
+ };
811
+ window.addEventListener("keydown", handleKeyDown);
812
+ return () => window.removeEventListener("keydown", handleKeyDown);
813
+ }, [isOpen, handleClose]);
814
+ if (!isOpen || !mounted) return null;
815
+ const selectedWallet = wallets.find((w) => w.id === selectedWalletId) || wallets[0];
816
+ const isAvailable = selectedWallet?.isAvailable();
817
+ const handleWalletSelect = (walletId) => {
818
+ setSelectedWalletId(walletId);
819
+ setError(null);
820
+ };
821
+ const handleConnectAction = async () => {
822
+ if (!selectedWallet) return;
823
+ setError(null);
824
+ setIsSubmitting(true);
825
+ try {
826
+ if (selectedWallet.id === "viewing-key") {
827
+ if (!customKeyInput.trim()) {
828
+ throw new Error("Please enter a valid Unified Address or Viewing Key.");
829
+ }
830
+ await connect(selectedWallet.id, customKeyInput.trim());
831
+ } else {
832
+ await connect(selectedWallet.id);
833
+ }
834
+ } catch (err) {
835
+ setError(err instanceof Error ? err.message : "Connection failed");
836
+ } finally {
837
+ setIsSubmitting(false);
838
+ }
839
+ };
840
+ return (0, import_react_dom.createPortal)(
841
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "fixed inset-0 z-[99999] flex items-center justify-center p-4 sm:p-6 overflow-y-auto font-sans", children: [
842
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
843
+ "div",
844
+ {
845
+ className: "fixed inset-0 bg-[#171717]/60 backdrop-blur-sm transition-opacity z-[99999]",
846
+ onClick: handleClose
847
+ }
848
+ ),
849
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "relative w-full max-w-2xl bg-white rounded-xl border border-[#ededed] shadow-2xl overflow-hidden z-[100000] text-[#171717] animate-in fade-in zoom-in-95 duration-150", children: [
850
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center justify-between px-6 py-4 border-b border-[#ededed] bg-[#fafafa]", children: [
851
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center gap-2.5", children: [
852
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "w-8 h-8 rounded-md bg-[#171717] flex items-center justify-center text-[#3ecf8e]", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.Shield, { className: "w-4 h-4 fill-[#3ecf8e]" }) }),
853
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
854
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center gap-2", children: [
855
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "font-semibold text-sm text-[#171717]", children: "Connect Zcash Wallet" }),
856
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-[10px] uppercase tracking-wider font-semibold px-2 py-0.5 rounded-full bg-[#3ecf8e]/15 text-[#24b47e] border border-[#3ecf8e]/30", children: network })
857
+ ] }),
858
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "text-xs text-[#707070] mt-0.5", children: [
859
+ "Connect to ",
860
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { className: "text-[#171717]", children: appName }),
861
+ " with your preferred zero-knowledge wallet."
862
+ ] })
863
+ ] })
864
+ ] }),
865
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
866
+ "button",
867
+ {
868
+ onClick: handleClose,
869
+ className: "p-1 rounded-md text-[#707070] hover:text-[#171717] hover:bg-[#ededed] transition-colors",
870
+ "aria-label": "Close modal",
871
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.X, { className: "w-4 h-4" })
872
+ }
873
+ )
874
+ ] }),
875
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "grid grid-cols-1 md:grid-cols-12 min-h-[380px]", children: [
876
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "md:col-span-5 p-3 bg-[#fafafa] border-r border-[#ededed] space-y-1", children: [
877
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "px-3 py-2 text-[11px] font-mono uppercase tracking-wider text-[#707070]", children: "Available Wallets" }),
878
+ wallets.map((w) => {
879
+ const active = w.id === selectedWalletId;
880
+ const available = w.isAvailable();
881
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
882
+ "button",
883
+ {
884
+ onClick: () => handleWalletSelect(w.id),
885
+ className: `w-full flex items-center justify-between p-3 rounded-lg text-left text-xs transition-all ${active ? "bg-white shadow-sm border border-[#dfdfdf] text-[#171717] font-medium" : "hover:bg-white/60 text-[#707070] hover:text-[#171717] border border-transparent"}`,
886
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center gap-2.5", children: [
887
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-base", children: w.icon }),
888
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
889
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center gap-1.5", children: [
890
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-sm text-[#171717] font-medium", children: w.name }),
891
+ w.id === "zucchini" && available && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-[9px] uppercase font-mono px-1.5 py-0.2 rounded bg-emerald-100 text-emerald-800 font-bold", children: "Detected" })
892
+ ] }),
893
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-[11px] text-[#9a9a9a] line-clamp-1", children: w.category === "extension" ? "Browser Extension" : w.category === "mobile" ? "Mobile / QR" : w.category === "read-only" ? "Auditor View" : "Dev Session" })
894
+ ] })
895
+ ] })
896
+ },
897
+ w.id
898
+ );
899
+ })
900
+ ] }),
901
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "md:col-span-7 p-6 flex flex-col justify-between bg-white", children: [
902
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "space-y-4", children: [
903
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex items-start justify-between pb-4 border-b border-[#ededed]", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center gap-2.5", children: [
904
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-2xl", children: selectedWallet.icon }),
905
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
906
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h4", { className: "text-base font-semibold text-[#171717]", children: selectedWallet.name }),
907
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "text-xs text-[#707070] mt-0.5", children: selectedWallet.description })
908
+ ] })
909
+ ] }) }),
910
+ error && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "p-3 rounded-md bg-rose-50 border border-rose-200 text-rose-800 text-xs flex items-start gap-2", children: [
911
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.AlertCircle, { className: "w-4 h-4 text-rose-600 flex-shrink-0 mt-0.5" }),
912
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: error })
913
+ ] }),
914
+ selectedWallet.id === "zucchini" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "space-y-4 py-2", children: isAvailable ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "p-4 rounded-lg bg-emerald-50 border border-emerald-200 text-xs text-emerald-950 space-y-2", children: [
915
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center gap-2 font-semibold", children: [
916
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.Sparkles, { className: "w-4 h-4 text-[#24b47e]" }),
917
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Extension Detected & Ready" })
918
+ ] }),
919
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "text-emerald-800 leading-relaxed", children: "Clicking connect will prompt your Zucchini Wallet side-panel to authorize access." })
920
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "p-4 rounded-lg bg-[#fafafa] border border-[#ededed] text-xs text-[#707070] space-y-3", children: [
921
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: "Zucchini Wallet extension was not detected in this browser. Install it to enable 1-click in-browser approvals." }),
922
+ selectedWallet.downloadUrl && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
923
+ "a",
924
+ {
925
+ href: selectedWallet.downloadUrl,
926
+ target: "_blank",
927
+ rel: "noopener noreferrer",
928
+ className: "inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md bg-[#171717] text-white text-xs font-medium hover:bg-[#212121]",
929
+ children: [
930
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Install from Chrome Web Store" }),
931
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.ExternalLink, { className: "w-3.5 h-3.5" })
932
+ ]
933
+ }
934
+ )
935
+ ] }) }),
936
+ (selectedWallet.id === "zashi" || selectedWallet.id === "ywallet") && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "text-center space-y-3 py-1", children: [
937
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
938
+ CiceroQRCode,
939
+ {
940
+ value: `zcash:u1demo?message=Connect%20to%20${encodeURIComponent(appName || "Cicero App")}`,
941
+ size: 150
942
+ }
943
+ ) }),
944
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
945
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "text-xs font-medium text-[#171717]", children: [
946
+ "Scan with ",
947
+ selectedWallet.name,
948
+ " app"
949
+ ] }),
950
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "text-[11px] text-[#707070] mt-0.5", children: [
951
+ "Open ",
952
+ selectedWallet.name,
953
+ " on iOS/Android and scan this QR code to authenticate."
954
+ ] })
955
+ ] })
956
+ ] }),
957
+ selectedWallet.id === "viewing-key" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "space-y-3 py-2 text-xs", children: [
958
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
959
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { className: "font-medium text-[#171717] block mb-1", children: "Unified Address or Viewing Key" }),
960
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
961
+ "textarea",
962
+ {
963
+ rows: 3,
964
+ value: customKeyInput,
965
+ onChange: (e) => setCustomKeyInput(e.target.value),
966
+ placeholder: "Paste u1... address, zxviews... or uview... key",
967
+ className: "w-full p-2.5 rounded-md bg-white border border-[#dfdfdf] font-mono text-xs text-[#171717] focus:outline-none focus:border-[#3ecf8e]"
968
+ }
969
+ )
970
+ ] }),
971
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "text-[11px] text-[#707070]", children: "Read-only connection for tax calculation, accounting reconciliation, or proof-of-reserves." })
972
+ ] }),
973
+ selectedWallet.id === "burner" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "space-y-3 py-2 text-xs", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "p-3.5 rounded-lg bg-[#fafafa] border border-[#ededed] space-y-1.5", children: [
974
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "font-semibold text-[#171717]", children: "Ephemeral Shielded Test Wallet" }),
975
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "text-[#707070] leading-relaxed", children: "Instantly creates an in-memory session wallet pre-funded with simulated testnet ZEC. Perfect for testing dApps without needing external extensions." })
976
+ ] }) })
977
+ ] }),
978
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "pt-4 border-t border-[#ededed] mt-4 flex items-center justify-between", children: [
979
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-[11px] text-[#9a9a9a]", children: "End-to-End Encrypted" }),
980
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
981
+ "button",
982
+ {
983
+ onClick: handleConnectAction,
984
+ disabled: isSubmitting,
985
+ className: "inline-flex items-center gap-2 px-5 py-2.5 rounded-md bg-[#3ecf8e] text-[#171717] font-semibold text-xs hover:bg-[#24b47e] transition-colors disabled:opacity-50 shadow-sm",
986
+ children: isSubmitting ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
987
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "w-3.5 h-3.5 border-2 border-[#171717]/30 border-t-[#171717] rounded-full animate-spin" }),
988
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Connecting..." })
989
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
990
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: selectedWallet.id === "viewing-key" ? "Connect Read-Only" : selectedWallet.id === "burner" ? "Launch Dev Session" : `Connect ${selectedWallet.name}` }),
991
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.ArrowRight, { className: "w-3.5 h-3.5" })
992
+ ] })
993
+ }
994
+ )
995
+ ] })
996
+ ] })
997
+ ] })
998
+ ] })
999
+ ] }),
1000
+ document.body
1001
+ );
1002
+ };
1003
+
1004
+ // src/components/CiceroAccountModal.tsx
1005
+ var import_react3 = require("react");
1006
+ var import_react_dom2 = require("react-dom");
1007
+ var import_lucide_react2 = require("lucide-react");
1008
+
1009
+ // src/utils/address.ts
1010
+ function getAddressType(address) {
1011
+ if (!address || typeof address !== "string") {
1012
+ return "unknown";
1013
+ }
1014
+ const clean = address.trim();
1015
+ if (clean.startsWith("u1") || clean.startsWith("utest1")) {
1016
+ return "unified";
1017
+ }
1018
+ if (clean.startsWith("zs1") || clean.startsWith("ztestsapling1")) {
1019
+ return "sapling";
1020
+ }
1021
+ if (clean.startsWith("t1") || clean.startsWith("t3") || clean.startsWith("tm")) {
1022
+ return "transparent";
1023
+ }
1024
+ return "unknown";
1025
+ }
1026
+ function isShieldedAddress(address) {
1027
+ const type = getAddressType(address);
1028
+ return type === "unified" || type === "sapling";
1029
+ }
1030
+ function truncateAddress(address, start = 8, end = 8) {
1031
+ if (!address) return "";
1032
+ const clean = address.trim();
1033
+ if (clean.length <= start + end + 3) {
1034
+ return clean;
1035
+ }
1036
+ return `${clean.slice(0, start)}...${clean.slice(-end)}`;
1037
+ }
1038
+ function validateMemoSupport(address, memo) {
1039
+ const byteLength = memo ? new TextEncoder().encode(memo).length : 0;
1040
+ const isAddressShielded = isShieldedAddress(address);
1041
+ if (byteLength > 512) {
1042
+ return {
1043
+ valid: false,
1044
+ warning: `Memo exceeds Zcash protocol limit of 512 bytes (current: ${byteLength} bytes).`,
1045
+ byteLength
1046
+ };
1047
+ }
1048
+ if (memo && !isAddressShielded) {
1049
+ return {
1050
+ valid: true,
1051
+ warning: "Warning: Transparent addresses (t-addr) do not support shielded encrypted memos. Use a Unified (u1) or Sapling (zs1) address to protect your memo.",
1052
+ byteLength
1053
+ };
1054
+ }
1055
+ return {
1056
+ valid: true,
1057
+ byteLength
1058
+ };
1059
+ }
1060
+
1061
+ // src/components/CiceroAccountModal.tsx
1062
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1063
+ var CiceroAccountModal = ({
1064
+ isOpen: propIsOpen,
1065
+ onClose: propOnClose
1066
+ }) => {
1067
+ const {
1068
+ isAccountModalOpen,
1069
+ closeAccountModal,
1070
+ address,
1071
+ wallet,
1072
+ network,
1073
+ switchNetwork,
1074
+ balance,
1075
+ refetchBalance,
1076
+ disconnect
1077
+ } = useCicero();
1078
+ const isOpen = propIsOpen !== void 0 ? propIsOpen : isAccountModalOpen;
1079
+ const handleClose = propOnClose || closeAccountModal;
1080
+ const [copied, setCopied] = (0, import_react3.useState)(false);
1081
+ const [showQr, setShowQr] = (0, import_react3.useState)(false);
1082
+ const [mounted, setMounted] = (0, import_react3.useState)(false);
1083
+ (0, import_react3.useEffect)(() => {
1084
+ setMounted(true);
1085
+ }, []);
1086
+ (0, import_react3.useEffect)(() => {
1087
+ const handleKeyDown = (e) => {
1088
+ if (e.key === "Escape" && isOpen) {
1089
+ handleClose();
1090
+ }
1091
+ };
1092
+ window.addEventListener("keydown", handleKeyDown);
1093
+ return () => window.removeEventListener("keydown", handleKeyDown);
1094
+ }, [isOpen, handleClose]);
1095
+ if (!isOpen || !mounted) return null;
1096
+ const copyAddress = async () => {
1097
+ if (!address) return;
1098
+ try {
1099
+ await navigator.clipboard.writeText(address);
1100
+ setCopied(true);
1101
+ setTimeout(() => setCopied(false), 2e3);
1102
+ } catch {
1103
+ }
1104
+ };
1105
+ return (0, import_react_dom2.createPortal)(
1106
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "fixed inset-0 z-[99999] flex items-center justify-center p-4 sm:p-6 overflow-y-auto font-sans", children: [
1107
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1108
+ "div",
1109
+ {
1110
+ className: "fixed inset-0 bg-[#171717]/60 backdrop-blur-sm transition-opacity z-[99999]",
1111
+ onClick: handleClose
1112
+ }
1113
+ ),
1114
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "relative w-full max-w-md bg-white rounded-xl border border-[#ededed] shadow-2xl overflow-hidden z-[100000] text-[#171717] animate-in fade-in zoom-in-95 duration-150", children: [
1115
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center justify-between px-6 py-4 border-b border-[#ededed] bg-[#fafafa]", children: [
1116
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-2", children: [
1117
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-xl", children: wallet?.icon || "\u{1F6E1}\uFE0F" }),
1118
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
1119
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "font-semibold text-sm text-[#171717]", children: wallet?.name || "Zcash Wallet" }),
1120
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-1.5 text-[11px] text-[#707070]", children: [
1121
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "w-1.5 h-1.5 rounded-full bg-[#24b47e]" }),
1122
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "Connected" })
1123
+ ] })
1124
+ ] })
1125
+ ] }),
1126
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1127
+ "button",
1128
+ {
1129
+ onClick: handleClose,
1130
+ className: "p-1 rounded-md text-[#707070] hover:text-[#171717] hover:bg-[#ededed] transition-colors",
1131
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_lucide_react2.X, { className: "w-4 h-4" })
1132
+ }
1133
+ )
1134
+ ] }),
1135
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "p-6 space-y-5", children: [
1136
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "p-4 rounded-lg bg-[#fafafa] border border-[#ededed] text-center space-y-1", children: [
1137
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center justify-center gap-1.5 text-xs text-[#707070]", children: [
1138
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "Shielded Balance" }),
1139
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1140
+ "button",
1141
+ {
1142
+ onClick: () => refetchBalance(),
1143
+ className: "hover:text-[#171717] p-0.5",
1144
+ title: "Refresh balance",
1145
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1146
+ import_lucide_react2.RefreshCw,
1147
+ {
1148
+ className: `w-3 h-3 ${balance.isLoading ? "animate-spin text-[#3ecf8e]" : ""}`
1149
+ }
1150
+ )
1151
+ }
1152
+ )
1153
+ ] }),
1154
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-baseline justify-center gap-1.5", children: [
1155
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-3xl font-bold font-mono text-[#171717] tracking-tight", children: balance.zec }),
1156
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-sm font-medium text-[#707070]", children: "ZEC" })
1157
+ ] }),
1158
+ balance.usd && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: "text-xs text-[#707070] font-mono", children: [
1159
+ "\u2248 $",
1160
+ balance.usd,
1161
+ " USD"
1162
+ ] })
1163
+ ] }),
1164
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "space-y-2 text-xs", children: [
1165
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center justify-between text-[#707070]", children: [
1166
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "Your Shielded Address" }),
1167
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1168
+ "button",
1169
+ {
1170
+ onClick: () => setShowQr(!showQr),
1171
+ className: "flex items-center gap-1 text-[#24b47e] hover:underline",
1172
+ children: [
1173
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_lucide_react2.QrCode, { className: "w-3.5 h-3.5" }),
1174
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: showQr ? "Hide QR" : "Show QR" })
1175
+ ]
1176
+ }
1177
+ )
1178
+ ] }),
1179
+ address ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "p-3 bg-[#fafafa] rounded-md border border-[#ededed] font-mono text-xs text-[#171717] break-all select-all flex items-center justify-between gap-2", children: [
1180
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "truncate", children: truncateAddress(address, 16, 12) }),
1181
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1182
+ "button",
1183
+ {
1184
+ onClick: copyAddress,
1185
+ className: "p-1 rounded hover:bg-white text-[#707070] hover:text-[#171717] transition-colors flex-shrink-0",
1186
+ title: "Copy full address",
1187
+ children: copied ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_lucide_react2.Check, { className: "w-3.5 h-3.5 text-[#24b47e]" }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_lucide_react2.Copy, { className: "w-3.5 h-3.5" })
1188
+ }
1189
+ )
1190
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "p-3 bg-[#fafafa] rounded-md border border-[#ededed] text-xs text-[#707070]", children: "Connected in Read-Only Mode" }),
1191
+ showQr && address && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "pt-2 flex justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CiceroQRCode, { value: `zcash:${address}`, size: 160 }) }),
1192
+ address && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center justify-between text-[11px] pt-1", children: [
1193
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "flex items-center gap-1 text-[#707070]", children: [
1194
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_lucide_react2.Shield, { className: "w-3 h-3 text-[#3ecf8e]" }),
1195
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "zk-Shielded Address" })
1196
+ ] }),
1197
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1198
+ "a",
1199
+ {
1200
+ href: network === "testnet" ? `https://blockexplorer.one/zcash/testnet/address/${address}` : `https://blockchair.com/zcash/address/${address}`,
1201
+ target: "_blank",
1202
+ rel: "noopener noreferrer",
1203
+ className: "flex items-center gap-1 text-[#24b47e] hover:underline",
1204
+ children: [
1205
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "View on Explorer" }),
1206
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_lucide_react2.ExternalLink, { className: "w-3 h-3" })
1207
+ ]
1208
+ }
1209
+ )
1210
+ ] })
1211
+ ] }),
1212
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center justify-between p-3 rounded-lg border border-[#ededed] bg-white text-xs", children: [
1213
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-2", children: [
1214
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_lucide_react2.ArrowRightLeft, { className: "w-4 h-4 text-[#707070]" }),
1215
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-[#171717] font-medium", children: "Network" })
1216
+ ] }),
1217
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-1 p-0.5 rounded bg-[#fafafa] border border-[#dfdfdf]", children: [
1218
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1219
+ "button",
1220
+ {
1221
+ onClick: () => switchNetwork("mainnet"),
1222
+ className: `px-2 py-1 rounded text-[11px] font-medium transition-colors ${network === "mainnet" ? "bg-white shadow-sm text-[#24b47e] font-semibold" : "text-[#707070]"}`,
1223
+ children: "Mainnet"
1224
+ }
1225
+ ),
1226
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1227
+ "button",
1228
+ {
1229
+ onClick: () => switchNetwork("testnet"),
1230
+ className: `px-2 py-1 rounded text-[11px] font-medium transition-colors ${network === "testnet" ? "bg-white shadow-sm text-amber-700 font-semibold" : "text-[#707070]"}`,
1231
+ children: "Testnet"
1232
+ }
1233
+ )
1234
+ ] })
1235
+ ] })
1236
+ ] }),
1237
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "px-6 py-3.5 bg-[#fafafa] border-t border-[#ededed] flex items-center justify-between", children: [
1238
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1239
+ "button",
1240
+ {
1241
+ onClick: disconnect,
1242
+ className: "flex items-center gap-1.5 text-xs text-rose-600 hover:text-rose-700 font-medium transition-colors",
1243
+ children: [
1244
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_lucide_react2.LogOut, { className: "w-3.5 h-3.5" }),
1245
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "Disconnect Wallet" })
1246
+ ]
1247
+ }
1248
+ ),
1249
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1250
+ "button",
1251
+ {
1252
+ onClick: handleClose,
1253
+ className: "px-3.5 py-1.5 rounded-md border border-[#dfdfdf] bg-white hover:bg-[#fafafa] text-xs font-medium text-[#171717] transition-colors",
1254
+ children: "Done"
1255
+ }
1256
+ )
1257
+ ] })
1258
+ ] })
1259
+ ] }),
1260
+ document.body
1261
+ );
1262
+ };
1263
+
1264
+ // src/context/CiceroContext.tsx
1265
+ var import_jsx_runtime4 = require("react/jsx-runtime");
1266
+ var CiceroContext = (0, import_react4.createContext)(null);
1267
+ var CiceroProvider = ({
1268
+ children,
1269
+ initialNetwork = "mainnet",
1270
+ wallets = getDefaultWallets(),
1271
+ appName = "Zcash App",
1272
+ appLogo,
1273
+ autoConnect = true
1274
+ }) => {
1275
+ const [network, setNetwork] = (0, import_react4.useState)(initialNetwork);
1276
+ const [account, setAccount] = (0, import_react4.useState)({
1277
+ address: null,
1278
+ viewingKey: null,
1279
+ isConnected: false,
1280
+ isConnecting: false,
1281
+ status: "disconnected",
1282
+ wallet: null,
1283
+ error: null
1284
+ });
1285
+ const [balance, setBalance] = (0, import_react4.useState)({
1286
+ zec: 0,
1287
+ usd: null,
1288
+ isLoading: false
1289
+ });
1290
+ const [isConnectModalOpen, setIsConnectModalOpen] = (0, import_react4.useState)(false);
1291
+ const [isAccountModalOpen, setIsAccountModalOpen] = (0, import_react4.useState)(false);
1292
+ const { convertZecToUsd } = useZcashPrice(true);
1293
+ const convertZecToUsdRef = (0, import_react4.useRef)(convertZecToUsd);
1294
+ convertZecToUsdRef.current = convertZecToUsd;
1295
+ const walletsRef = (0, import_react4.useRef)(wallets);
1296
+ walletsRef.current = wallets;
1297
+ (0, import_react4.useEffect)(() => {
1298
+ if (typeof window === "undefined") return;
1299
+ const savedWalletId = localStorage.getItem("cicero_wallet_id");
1300
+ const savedAddress = localStorage.getItem("cicero_address");
1301
+ const savedNetwork = localStorage.getItem("cicero_network");
1302
+ if (savedNetwork) {
1303
+ setNetwork(savedNetwork);
1304
+ }
1305
+ if (autoConnect && savedWalletId) {
1306
+ const targetWallet = walletsRef.current.find((w) => w.id === savedWalletId);
1307
+ if (targetWallet && (savedAddress || targetWallet.isAvailable())) {
1308
+ const savedBal = localStorage.getItem("cicero_balance");
1309
+ const parsedBal = savedBal ? parseFloat(savedBal) : null;
1310
+ const activeZec = parsedBal !== null && !isNaN(parsedBal) ? parsedBal : 0;
1311
+ const initialUsd = convertZecToUsdRef.current(activeZec);
1312
+ setAccount({
1313
+ address: savedAddress || null,
1314
+ viewingKey: null,
1315
+ isConnected: true,
1316
+ isConnecting: false,
1317
+ status: "connected",
1318
+ wallet: targetWallet,
1319
+ error: null
1320
+ });
1321
+ setBalance({
1322
+ zec: activeZec,
1323
+ usd: initialUsd,
1324
+ isLoading: false
1325
+ });
1326
+ if (targetWallet.getBalance) {
1327
+ targetWallet.getBalance({ address: savedAddress || void 0, network }).then((freshBal) => {
1328
+ if (freshBal !== null && !isNaN(freshBal)) {
1329
+ setBalance({
1330
+ zec: freshBal,
1331
+ usd: convertZecToUsdRef.current(freshBal),
1332
+ isLoading: false
1333
+ });
1334
+ localStorage.setItem("cicero_balance", freshBal.toString());
1335
+ }
1336
+ }).catch(() => {
1337
+ });
1338
+ }
1339
+ }
1340
+ }
1341
+ }, [autoConnect]);
1342
+ (0, import_react4.useEffect)(() => {
1343
+ if (typeof window === "undefined") return;
1344
+ const cleanupReady = ZucchiniWalletAdapter.onReady(() => {
1345
+ const savedWalletId = localStorage.getItem("cicero_wallet_id");
1346
+ const savedAddress = localStorage.getItem("cicero_address");
1347
+ if (savedWalletId === "zucchini" && autoConnect) {
1348
+ const zucchini = walletsRef.current.find((w) => w.id === "zucchini");
1349
+ if (zucchini) {
1350
+ setAccount((prev) => {
1351
+ if (prev.isConnected && prev.wallet?.id === "zucchini") return prev;
1352
+ return {
1353
+ address: savedAddress || null,
1354
+ viewingKey: null,
1355
+ isConnected: true,
1356
+ isConnecting: false,
1357
+ status: "connected",
1358
+ wallet: zucchini,
1359
+ error: null
1360
+ };
1361
+ });
1362
+ }
1363
+ }
1364
+ });
1365
+ return () => {
1366
+ cleanupReady();
1367
+ };
1368
+ }, [autoConnect]);
1369
+ (0, import_react4.useEffect)(() => {
1370
+ if (account.isConnected) {
1371
+ setBalance((prev) => {
1372
+ const newUsd = convertZecToUsd(prev.zec);
1373
+ if (prev.usd === newUsd) return prev;
1374
+ return {
1375
+ ...prev,
1376
+ usd: newUsd
1377
+ };
1378
+ });
1379
+ }
1380
+ }, [account.isConnected, balance.zec, convertZecToUsd]);
1381
+ const switchNetwork = (0, import_react4.useCallback)((newNet) => {
1382
+ setNetwork(newNet);
1383
+ if (typeof window !== "undefined") {
1384
+ localStorage.setItem("cicero_network", newNet);
1385
+ }
1386
+ }, []);
1387
+ const connect = (0, import_react4.useCallback)(
1388
+ async (walletId, customAddressOrKey) => {
1389
+ const targetWallet = wallets.find((w) => w.id === walletId);
1390
+ if (!targetWallet) {
1391
+ throw new Error(`Wallet ${walletId} not found in registered wallets`);
1392
+ }
1393
+ setAccount((prev) => ({
1394
+ ...prev,
1395
+ isConnecting: true,
1396
+ status: "connecting",
1397
+ error: null
1398
+ }));
1399
+ try {
1400
+ let session;
1401
+ if (walletId === "viewing-key" && customAddressOrKey) {
1402
+ session = {
1403
+ address: customAddressOrKey,
1404
+ viewingKey: customAddressOrKey.startsWith("zx") || customAddressOrKey.startsWith("uview") ? customAddressOrKey : void 0,
1405
+ connected: true,
1406
+ network,
1407
+ walletId: "viewing-key"
1408
+ };
1409
+ } else {
1410
+ session = await targetWallet.connect({ network });
1411
+ }
1412
+ const resolvedAddress = session.address || customAddressOrKey || null;
1413
+ setAccount({
1414
+ address: resolvedAddress,
1415
+ viewingKey: session.viewingKey || null,
1416
+ isConnected: true,
1417
+ isConnecting: false,
1418
+ status: "connected",
1419
+ wallet: targetWallet,
1420
+ error: null
1421
+ });
1422
+ let resolvedZec = session.balance ?? null;
1423
+ if (resolvedZec === null && targetWallet.getBalance) {
1424
+ try {
1425
+ resolvedZec = await targetWallet.getBalance({
1426
+ address: resolvedAddress || void 0,
1427
+ network
1428
+ });
1429
+ } catch {
1430
+ }
1431
+ }
1432
+ if (resolvedZec === null && typeof window !== "undefined") {
1433
+ const cached = localStorage.getItem("cicero_balance");
1434
+ if (cached && !isNaN(parseFloat(cached))) {
1435
+ resolvedZec = parseFloat(cached);
1436
+ }
1437
+ }
1438
+ const activeZec = resolvedZec !== null && !isNaN(resolvedZec) ? resolvedZec : 0;
1439
+ setBalance({
1440
+ zec: activeZec,
1441
+ usd: convertZecToUsd(activeZec),
1442
+ isLoading: false
1443
+ });
1444
+ if (typeof window !== "undefined" && resolvedZec !== null) {
1445
+ localStorage.setItem("cicero_balance", resolvedZec.toString());
1446
+ }
1447
+ if (typeof window !== "undefined") {
1448
+ localStorage.setItem("cicero_wallet_id", walletId);
1449
+ if (resolvedAddress) {
1450
+ localStorage.setItem("cicero_address", resolvedAddress);
1451
+ }
1452
+ }
1453
+ setIsConnectModalOpen(false);
1454
+ } catch (err) {
1455
+ const msg = err instanceof Error ? err.message : "Connection failed";
1456
+ setAccount((prev) => ({
1457
+ ...prev,
1458
+ isConnecting: false,
1459
+ status: "error",
1460
+ error: msg
1461
+ }));
1462
+ throw err;
1463
+ }
1464
+ },
1465
+ [wallets, network, convertZecToUsd]
1466
+ );
1467
+ const disconnect = (0, import_react4.useCallback)(async () => {
1468
+ if (account.wallet?.disconnect) {
1469
+ try {
1470
+ await account.wallet.disconnect();
1471
+ } catch {
1472
+ }
1473
+ }
1474
+ setAccount({
1475
+ address: null,
1476
+ viewingKey: null,
1477
+ isConnected: false,
1478
+ isConnecting: false,
1479
+ status: "disconnected",
1480
+ wallet: null,
1481
+ error: null
1482
+ });
1483
+ setBalance({
1484
+ zec: 0,
1485
+ usd: null,
1486
+ isLoading: false
1487
+ });
1488
+ if (typeof window !== "undefined") {
1489
+ localStorage.removeItem("cicero_wallet_id");
1490
+ localStorage.removeItem("cicero_address");
1491
+ localStorage.removeItem("cicero_balance");
1492
+ }
1493
+ setIsAccountModalOpen(false);
1494
+ }, [account.wallet]);
1495
+ const sendPayment = (0, import_react4.useCallback)(
1496
+ async (params) => {
1497
+ if (!account.wallet) {
1498
+ throw new Error("No wallet connected. Please connect a Zcash wallet first.");
1499
+ }
1500
+ if (account.wallet.sendPayment) {
1501
+ return account.wallet.sendPayment(params);
1502
+ }
1503
+ throw new Error(`Wallet ${account.wallet.name} does not support programmatic send.`);
1504
+ },
1505
+ [account.wallet]
1506
+ );
1507
+ const refetchBalance = (0, import_react4.useCallback)(async () => {
1508
+ if (!account.wallet) return;
1509
+ setBalance((prev) => ({ ...prev, isLoading: true }));
1510
+ try {
1511
+ let freshZec = null;
1512
+ if (account.wallet.getBalance) {
1513
+ freshZec = await account.wallet.getBalance({
1514
+ address: account.address || void 0,
1515
+ network
1516
+ });
1517
+ }
1518
+ if (freshZec !== null && !isNaN(freshZec)) {
1519
+ setBalance({
1520
+ zec: freshZec,
1521
+ usd: convertZecToUsd(freshZec),
1522
+ isLoading: false
1523
+ });
1524
+ if (typeof window !== "undefined") {
1525
+ localStorage.setItem("cicero_balance", freshZec.toString());
1526
+ }
1527
+ return;
1528
+ }
1529
+ } catch {
1530
+ }
1531
+ setBalance((prev) => ({
1532
+ ...prev,
1533
+ isLoading: false,
1534
+ usd: convertZecToUsd(prev.zec)
1535
+ }));
1536
+ }, [account.wallet, account.address, network, convertZecToUsd]);
1537
+ const openConnectModal = (0, import_react4.useCallback)(() => setIsConnectModalOpen(true), []);
1538
+ const closeConnectModal = (0, import_react4.useCallback)(() => setIsConnectModalOpen(false), []);
1539
+ const openAccountModal = (0, import_react4.useCallback)(() => setIsAccountModalOpen(true), []);
1540
+ const closeAccountModal = (0, import_react4.useCallback)(() => setIsAccountModalOpen(false), []);
1541
+ const value = (0, import_react4.useMemo)(
1542
+ () => ({
1543
+ account,
1544
+ address: account.address,
1545
+ isConnected: account.isConnected,
1546
+ isConnecting: account.isConnecting,
1547
+ wallet: account.wallet,
1548
+ network,
1549
+ switchNetwork,
1550
+ balance,
1551
+ refetchBalance,
1552
+ connect,
1553
+ disconnect,
1554
+ sendPayment,
1555
+ isConnectModalOpen,
1556
+ openConnectModal,
1557
+ closeConnectModal,
1558
+ isAccountModalOpen,
1559
+ openAccountModal,
1560
+ closeAccountModal,
1561
+ wallets,
1562
+ appName,
1563
+ appLogo
1564
+ }),
1565
+ [
1566
+ account,
1567
+ network,
1568
+ switchNetwork,
1569
+ balance,
1570
+ refetchBalance,
1571
+ connect,
1572
+ disconnect,
1573
+ sendPayment,
1574
+ isConnectModalOpen,
1575
+ openConnectModal,
1576
+ closeConnectModal,
1577
+ isAccountModalOpen,
1578
+ openAccountModal,
1579
+ closeAccountModal,
1580
+ wallets,
1581
+ appName,
1582
+ appLogo
1583
+ ]
1584
+ );
1585
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(CiceroContext.Provider, { value, children: [
1586
+ children,
1587
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CiceroConnectModal, {}),
1588
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CiceroAccountModal, {})
1589
+ ] });
1590
+ };
1591
+ function useCicero() {
1592
+ const ctx = (0, import_react4.useContext)(CiceroContext);
1593
+ if (!ctx) {
1594
+ throw new Error("useCicero must be used within a <CiceroProvider>");
1595
+ }
1596
+ return ctx;
1597
+ }
1598
+ var useAccount = () => {
1599
+ const { account, address, isConnected, isConnecting, wallet, disconnect } = useCicero();
1600
+ return { ...account, address, isConnected, isConnecting, wallet, disconnect };
1601
+ };
1602
+ var useBalance = () => {
1603
+ const { balance, refetchBalance } = useCicero();
1604
+ return { ...balance, refetch: refetchBalance };
1605
+ };
1606
+ var useConnectModal = () => {
1607
+ const { isConnectModalOpen, openConnectModal, closeConnectModal } = useCicero();
1608
+ return {
1609
+ isOpen: isConnectModalOpen,
1610
+ openConnectModal,
1611
+ closeConnectModal
1612
+ };
1613
+ };
1614
+ var useAccountModal = () => {
1615
+ const { isAccountModalOpen, openAccountModal, closeAccountModal } = useCicero();
1616
+ return {
1617
+ isOpen: isAccountModalOpen,
1618
+ openAccountModal,
1619
+ closeAccountModal
1620
+ };
1621
+ };
1622
+
1623
+ // src/components/CiceroConnectButton.tsx
1624
+ var import_lucide_react3 = require("lucide-react");
1625
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1626
+ var CiceroConnectButton = ({
1627
+ label = "Connect Zcash Wallet",
1628
+ variant = "primary",
1629
+ size = "md",
1630
+ showBalance = true,
1631
+ showNetwork = true,
1632
+ className = ""
1633
+ }) => {
1634
+ const {
1635
+ account,
1636
+ address,
1637
+ isConnected,
1638
+ isConnecting,
1639
+ network,
1640
+ balance,
1641
+ openConnectModal,
1642
+ openAccountModal
1643
+ } = useCicero();
1644
+ const sizeClasses = {
1645
+ sm: "text-xs px-2.5 py-1.5 gap-1.5",
1646
+ md: "text-sm px-3.5 py-2 gap-2",
1647
+ lg: "text-base px-4.5 py-2.5 gap-2.5"
1648
+ }[size];
1649
+ const variantClasses = {
1650
+ primary: "bg-[#3ecf8e] text-[#171717] hover:bg-[#24b47e] font-semibold shadow-sm",
1651
+ outline: "bg-white text-[#171717] border border-[#dfdfdf] hover:border-[#c7c7c7] hover:bg-[#fafafa] font-medium shadow-sm",
1652
+ dark: "bg-[#1c1c1c] text-white hover:bg-[#242424] font-medium shadow-sm"
1653
+ }[variant];
1654
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: !isConnected ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1655
+ "button",
1656
+ {
1657
+ type: "button",
1658
+ onClick: openConnectModal,
1659
+ disabled: isConnecting,
1660
+ className: `inline-flex items-center justify-center rounded-[6px] transition-all select-none ${sizeClasses} ${variantClasses} ${className}`,
1661
+ children: [
1662
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1663
+ import_lucide_react3.Shield,
1664
+ {
1665
+ className: `flex-shrink-0 ${size === "sm" ? "w-3.5 h-3.5" : size === "lg" ? "w-5 h-5" : "w-4 h-4"} ${variant === "primary" ? "fill-[#171717]/20" : "text-[#3ecf8e]"}`
1666
+ }
1667
+ ),
1668
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: isConnecting ? "Connecting..." : label })
1669
+ ]
1670
+ }
1671
+ ) : (
1672
+ /* Connected State Pill (RainbowKit style) */
1673
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `inline-flex items-center rounded-[6px] border border-[#dfdfdf] bg-white p-0.5 shadow-sm text-xs ${className}`, children: [
1674
+ showNetwork && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-1.5 px-2.5 py-1 text-[11px] font-medium text-[#707070] border-r border-[#ededed]", children: [
1675
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1676
+ "span",
1677
+ {
1678
+ className: `w-2 h-2 rounded-full ${network === "mainnet" ? "bg-[#3ecf8e]" : "bg-amber-400"}`
1679
+ }
1680
+ ),
1681
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "capitalize", children: network })
1682
+ ] }),
1683
+ showBalance && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "px-2.5 py-1 font-mono font-medium text-[#171717] border-r border-[#ededed]", children: [
1684
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: balance.zec }),
1685
+ " ",
1686
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-[#707070] font-normal", children: "ZEC" })
1687
+ ] }),
1688
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1689
+ "button",
1690
+ {
1691
+ type: "button",
1692
+ onClick: openAccountModal,
1693
+ className: "flex items-center gap-1.5 px-2.5 py-1 rounded-[4px] hover:bg-[#fafafa] text-[#171717] font-medium transition-colors",
1694
+ children: [
1695
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-sm", children: account.wallet?.icon || "\u{1F6E1}\uFE0F" }),
1696
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "font-mono text-[11px]", children: address ? truncateAddress(address, 6, 4) : "Connected" }),
1697
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react3.ChevronDown, { className: "w-3 h-3 text-[#707070]" })
1698
+ ]
1699
+ }
1700
+ )
1701
+ ] })
1702
+ ) });
1703
+ };
1704
+
1705
+ // src/components/CiceroPayButton.tsx
1706
+ var import_lucide_react5 = require("lucide-react");
1707
+
1708
+ // src/hooks/useCiceroPayment.ts
1709
+ var import_react5 = require("react");
1710
+ function useCiceroPayment({
1711
+ recipient,
1712
+ amount,
1713
+ memo,
1714
+ message,
1715
+ network = "mainnet",
1716
+ expiresInSeconds = 900,
1717
+ // 15 mins
1718
+ invoiceId,
1719
+ customRpcUrl,
1720
+ onSuccess,
1721
+ onError,
1722
+ onStatusChange
1723
+ }) {
1724
+ const onSuccessRef = (0, import_react5.useRef)(onSuccess);
1725
+ onSuccessRef.current = onSuccess;
1726
+ const onErrorRef = (0, import_react5.useRef)(onError);
1727
+ onErrorRef.current = onError;
1728
+ const onStatusChangeRef = (0, import_react5.useRef)(onStatusChange);
1729
+ onStatusChangeRef.current = onStatusChange;
1730
+ const [status, setStatus] = (0, import_react5.useState)("pending");
1731
+ const [txId, setTxId] = (0, import_react5.useState)(null);
1732
+ const [secondsRemaining, setSecondsRemaining] = (0, import_react5.useState)(expiresInSeconds);
1733
+ const [isModalOpen, setIsModalOpen] = (0, import_react5.useState)(false);
1734
+ const [zucchiniAvailable, setZucchiniAvailable] = (0, import_react5.useState)(false);
1735
+ const [zucchiniAdapter] = (0, import_react5.useState)(() => new ZucchiniWalletAdapter());
1736
+ const [zucchiniPaying, setZucchiniPaying] = (0, import_react5.useState)(false);
1737
+ (0, import_react5.useEffect)(() => {
1738
+ setZucchiniAvailable(ZucchiniWalletAdapter.isAvailable());
1739
+ }, []);
1740
+ const addressType = (0, import_react5.useMemo)(() => getAddressType(recipient), [recipient]);
1741
+ const isShielded = (0, import_react5.useMemo)(() => isShieldedAddress(recipient), [recipient]);
1742
+ const memoValidation = (0, import_react5.useMemo)(
1743
+ () => validateMemoSupport(recipient, memo),
1744
+ [recipient, memo]
1745
+ );
1746
+ const lastWarningRef = (0, import_react5.useRef)(null);
1747
+ (0, import_react5.useEffect)(() => {
1748
+ if (!memoValidation.valid && memoValidation.warning) {
1749
+ if (lastWarningRef.current !== memoValidation.warning) {
1750
+ lastWarningRef.current = memoValidation.warning;
1751
+ onErrorRef.current?.(new Error(memoValidation.warning));
1752
+ }
1753
+ } else {
1754
+ lastWarningRef.current = null;
1755
+ }
1756
+ }, [memoValidation.valid, memoValidation.warning]);
1757
+ const zip321Uri = (0, import_react5.useMemo)(() => {
1758
+ return generateZip321Uri({
1759
+ address: recipient,
1760
+ amount,
1761
+ memo,
1762
+ message
1763
+ });
1764
+ }, [recipient, amount, memo, message]);
1765
+ const deepLinks = (0, import_react5.useMemo)(() => getWalletDeepLinks(zip321Uri), [zip321Uri]);
1766
+ const updateStatus = (0, import_react5.useCallback)((newStatus) => {
1767
+ setStatus(newStatus);
1768
+ onStatusChangeRef.current?.(newStatus);
1769
+ }, []);
1770
+ (0, import_react5.useEffect)(() => {
1771
+ if (status !== "pending") return;
1772
+ const timer = setInterval(() => {
1773
+ setSecondsRemaining((prev) => {
1774
+ if (prev <= 1) {
1775
+ clearInterval(timer);
1776
+ updateStatus("expired");
1777
+ return 0;
1778
+ }
1779
+ return prev - 1;
1780
+ });
1781
+ }, 1e3);
1782
+ return () => clearInterval(timer);
1783
+ }, [status, updateStatus]);
1784
+ const resetPayment = (0, import_react5.useCallback)(() => {
1785
+ setStatus("pending");
1786
+ setTxId(null);
1787
+ setSecondsRemaining(expiresInSeconds);
1788
+ setZucchiniPaying(false);
1789
+ }, [expiresInSeconds]);
1790
+ const openModal = (0, import_react5.useCallback)(() => {
1791
+ resetPayment();
1792
+ setIsModalOpen(true);
1793
+ }, [resetPayment]);
1794
+ const closeModal = (0, import_react5.useCallback)(() => {
1795
+ setIsModalOpen(false);
1796
+ }, []);
1797
+ const payWithZucchini = (0, import_react5.useCallback)(async () => {
1798
+ setZucchiniPaying(true);
1799
+ try {
1800
+ await zucchiniAdapter.connect();
1801
+ const numAmount = typeof amount === "number" ? amount : parseFloat(amount);
1802
+ const result = await zucchiniAdapter.requestPayment({
1803
+ recipient,
1804
+ amount: numAmount,
1805
+ memo
1806
+ });
1807
+ updateStatus("detected");
1808
+ setTxId(result.txId);
1809
+ setTimeout(() => {
1810
+ updateStatus("confirmed");
1811
+ onSuccessRef.current?.({
1812
+ txId: result.txId,
1813
+ amount: isNaN(numAmount) ? 0 : numAmount,
1814
+ memo
1815
+ });
1816
+ setZucchiniPaying(false);
1817
+ }, 1500);
1818
+ } catch (err) {
1819
+ const error = err instanceof Error ? err : new Error("Zucchini payment failed");
1820
+ onErrorRef.current?.(error);
1821
+ setZucchiniPaying(false);
1822
+ }
1823
+ }, [recipient, amount, memo, zucchiniAdapter, updateStatus]);
1824
+ const simulateDetection = (0, import_react5.useCallback)(() => {
1825
+ updateStatus("detected");
1826
+ setTimeout(() => {
1827
+ const mockTxId = `0x${Array.from(
1828
+ { length: 64 },
1829
+ () => Math.floor(Math.random() * 16).toString(16)
1830
+ ).join("")}`;
1831
+ setTxId(mockTxId);
1832
+ updateStatus("confirmed");
1833
+ const numAmount = typeof amount === "number" ? amount : parseFloat(amount);
1834
+ onSuccessRef.current?.({
1835
+ txId: mockTxId,
1836
+ amount: isNaN(numAmount) ? 0 : numAmount,
1837
+ memo
1838
+ });
1839
+ }, 2e3);
1840
+ }, [amount, memo, updateStatus]);
1841
+ return {
1842
+ status,
1843
+ txId,
1844
+ secondsRemaining,
1845
+ isModalOpen,
1846
+ openModal,
1847
+ closeModal,
1848
+ resetPayment,
1849
+ zip321Uri,
1850
+ deepLinks,
1851
+ addressType,
1852
+ isShielded,
1853
+ memoValidation,
1854
+ simulateDetection,
1855
+ invoiceId,
1856
+ network,
1857
+ customRpcUrl,
1858
+ // Zucchini Wallet
1859
+ zucchiniAvailable,
1860
+ zucchiniPaying,
1861
+ payWithZucchini
1862
+ };
1863
+ }
1864
+
1865
+ // src/components/CiceroModal.tsx
1866
+ var import_react6 = require("react");
1867
+ var import_react_dom3 = require("react-dom");
1868
+ var import_lucide_react4 = require("lucide-react");
1869
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1870
+ var CiceroModal = ({
1871
+ isOpen,
1872
+ onClose,
1873
+ recipient,
1874
+ amount,
1875
+ memo,
1876
+ message,
1877
+ network = "mainnet",
1878
+ status,
1879
+ txId,
1880
+ secondsRemaining,
1881
+ zip321Uri,
1882
+ addressType,
1883
+ isShielded,
1884
+ memoValidation,
1885
+ onSimulateDetection,
1886
+ onResetPayment,
1887
+ title = "Pay with Shielded Zcash",
1888
+ subtitle = "Zero-Knowledge, Confidential Checkout",
1889
+ showUsd = true,
1890
+ zucchiniAvailable = false,
1891
+ zucchiniPaying = false,
1892
+ onPayWithZucchini
1893
+ }) => {
1894
+ const [copiedType, setCopiedType] = (0, import_react6.useState)(null);
1895
+ const { convertZecToUsd } = useZcashPrice(showUsd);
1896
+ (0, import_react6.useEffect)(() => {
1897
+ const handleKeyDown = (e) => {
1898
+ if (e.key === "Escape" && isOpen) {
1899
+ onClose();
1900
+ }
1901
+ };
1902
+ window.addEventListener("keydown", handleKeyDown);
1903
+ return () => window.removeEventListener("keydown", handleKeyDown);
1904
+ }, [isOpen, onClose]);
1905
+ const [mounted, setMounted] = (0, import_react6.useState)(false);
1906
+ (0, import_react6.useEffect)(() => {
1907
+ setMounted(true);
1908
+ }, []);
1909
+ if (!isOpen || !mounted) return null;
1910
+ const copyToClipboard = async (text, type) => {
1911
+ try {
1912
+ await navigator.clipboard.writeText(text);
1913
+ setCopiedType(type);
1914
+ setTimeout(() => setCopiedType(null), 2e3);
1915
+ } catch {
1916
+ }
1917
+ };
1918
+ const formatTime = (secs) => {
1919
+ const m = Math.floor(secs / 60);
1920
+ const s = secs % 60;
1921
+ return `${m}:${s < 10 ? "0" : ""}${s}`;
1922
+ };
1923
+ const usdValue = convertZecToUsd(amount);
1924
+ return (0, import_react_dom3.createPortal)(
1925
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "fixed inset-0 z-[99999] flex items-center justify-center p-4 sm:p-6 overflow-y-auto", children: [
1926
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1927
+ "div",
1928
+ {
1929
+ className: "fixed inset-0 bg-[#171717]/60 backdrop-blur-sm transition-opacity z-[99999]",
1930
+ onClick: onClose
1931
+ }
1932
+ ),
1933
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "relative w-full max-w-lg bg-white rounded-xl border border-[#ededed] shadow-2xl overflow-hidden z-[100000] text-[#171717] font-sans animate-in fade-in zoom-in-95 duration-150", children: [
1934
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center justify-between px-6 py-4 border-b border-[#ededed] bg-[#fafafa]", children: [
1935
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center gap-2.5", children: [
1936
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "w-8 h-8 rounded-md bg-[#171717] flex items-center justify-center text-[#3ecf8e]", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.Shield, { className: "w-4 h-4 fill-[#3ecf8e]" }) }),
1937
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
1938
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center gap-2", children: [
1939
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "font-medium text-sm text-[#171717]", children: title }),
1940
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-[10px] uppercase tracking-wider font-semibold px-2 py-0.5 rounded-full bg-[#3ecf8e]/15 text-[#24b47e] border border-[#3ecf8e]/30", children: isShielded ? "zk-Shielded" : "Transparent" }),
1941
+ network === "testnet" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-[10px] uppercase tracking-wider font-semibold px-2 py-0.5 rounded-full bg-amber-100 text-amber-800 border border-amber-200", children: "Testnet" })
1942
+ ] }),
1943
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "text-xs text-[#707070] mt-0.5", children: subtitle })
1944
+ ] })
1945
+ ] }),
1946
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1947
+ "button",
1948
+ {
1949
+ onClick: onClose,
1950
+ className: "p-1 rounded-md text-[#707070] hover:text-[#171717] hover:bg-[#ededed] transition-colors",
1951
+ "aria-label": "Close modal",
1952
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.X, { className: "w-4 h-4" })
1953
+ }
1954
+ )
1955
+ ] }),
1956
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "px-6 py-2.5 bg-white border-b border-[#ededed] flex items-center justify-between text-xs", children: [
1957
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center gap-2", children: [
1958
+ status === "pending" && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
1959
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "relative flex h-2 w-2", children: [
1960
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "animate-ping absolute inline-flex h-full w-full rounded-full bg-[#3ecf8e] opacity-75" }),
1961
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "relative inline-flex rounded-full h-2 w-2 bg-[#24b47e]" })
1962
+ ] }),
1963
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-[#707070]", children: "Listening for transaction..." })
1964
+ ] }),
1965
+ status === "detected" && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
1966
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "relative flex h-2 w-2", children: [
1967
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75" }),
1968
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "relative inline-flex rounded-full h-2 w-2 bg-amber-500" })
1969
+ ] }),
1970
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-amber-800 font-medium", children: "Transaction spotted in mempool! Confirming..." })
1971
+ ] }),
1972
+ status === "confirmed" && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
1973
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.CheckCircle2, { className: "w-4 h-4 text-[#24b47e]" }),
1974
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-[#24b47e] font-medium", children: "Payment Confirmed On-Chain!" })
1975
+ ] }),
1976
+ status === "expired" && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
1977
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.AlertCircle, { className: "w-4 h-4 text-rose-500" }),
1978
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-rose-600 font-medium", children: "Payment window expired" })
1979
+ ] })
1980
+ ] }),
1981
+ status === "pending" && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center gap-1 text-[#707070] font-mono text-[11px]", children: [
1982
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.Clock, { className: "w-3 h-3" }),
1983
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: formatTime(secondsRemaining) })
1984
+ ] })
1985
+ ] }),
1986
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "p-6 space-y-5", children: status === "confirmed" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "py-6 text-center space-y-4", children: [
1987
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "w-16 h-16 mx-auto rounded-full bg-[#3ecf8e]/15 border border-[#3ecf8e]/40 flex items-center justify-center text-[#24b47e] animate-bounce", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.CheckCircle2, { className: "w-8 h-8" }) }),
1988
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
1989
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h3", { className: "text-lg font-medium text-[#171717]", children: "Payment Received & Shielded!" }),
1990
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "text-xs text-[#707070] max-w-sm mx-auto mt-1", children: "Your transaction has been verified using zero-knowledge proofs. No sender or recipient address was leaked." })
1991
+ ] }),
1992
+ txId && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "p-3 bg-[#fafafa] rounded-md border border-[#ededed] text-left", children: [
1993
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center justify-between text-[11px] text-[#707070] mb-1", children: [
1994
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Transaction Hash" }),
1995
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-[#24b47e] font-mono", children: "Shielded Note" })
1996
+ ] }),
1997
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "font-mono text-xs text-[#171717] break-all", children: txId })
1998
+ ] }),
1999
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2000
+ "button",
2001
+ {
2002
+ onClick: onClose,
2003
+ className: "w-full py-2.5 px-4 rounded-md bg-[#3ecf8e] text-[#171717] font-medium text-sm hover:bg-[#24b47e] transition-colors",
2004
+ children: "Close & Return"
2005
+ }
2006
+ )
2007
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2008
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center justify-between p-4 bg-[#fafafa] rounded-lg border border-[#ededed]", children: [
2009
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
2010
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-xs text-[#707070] uppercase font-mono tracking-wider", children: "Total Amount" }),
2011
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-baseline gap-2 mt-0.5", children: [
2012
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "text-2xl font-semibold tracking-tight text-[#171717] font-mono", children: [
2013
+ amount,
2014
+ " ",
2015
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-sm font-normal text-[#707070]", children: "ZEC" })
2016
+ ] }),
2017
+ usdValue && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "text-xs text-[#707070] font-mono", children: [
2018
+ "\u2248 $",
2019
+ usdValue,
2020
+ " USD"
2021
+ ] })
2022
+ ] })
2023
+ ] }),
2024
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "text-right", children: [
2025
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-[11px] text-[#707070] block font-mono", children: "Address Standard" }),
2026
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "inline-block mt-0.5 px-2 py-0.5 text-xs font-mono font-medium rounded bg-white border border-[#dfdfdf] text-[#171717]", children: addressType === "unified" ? "Unified (ZIP-316)" : addressType === "sapling" ? "Sapling (Shielded)" : "Transparent" })
2027
+ ] })
2028
+ ] }),
2029
+ message && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "px-3.5 py-2 bg-[#fafafa] rounded-md border border-[#ededed] text-xs text-[#707070]", children: [
2030
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "font-medium text-[#171717]", children: "Order Note: " }),
2031
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: message })
2032
+ ] }),
2033
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex flex-col sm:flex-row items-center gap-5 p-4 rounded-lg border border-[#ededed] bg-white", children: [
2034
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "flex-shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CiceroQRCode, { value: zip321Uri, size: 150 }) }),
2035
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "space-y-3 w-full text-center sm:text-left", children: [
2036
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
2037
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("h4", { className: "text-sm font-medium text-[#171717] flex items-center justify-center sm:justify-start gap-1.5", children: [
2038
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Scan with Shielded Wallet" }),
2039
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.Sparkles, { className: "w-3.5 h-3.5 text-[#3ecf8e]" })
2040
+ ] }),
2041
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "text-xs text-[#707070] mt-0.5 leading-relaxed", children: [
2042
+ "Compatible with ",
2043
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("strong", { className: "text-[#171717]", children: "Zashi" }),
2044
+ ", ",
2045
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("strong", { className: "text-[#171717]", children: "Ywallet" }),
2046
+ ", or any ZIP-321 compliant Zcash wallet."
2047
+ ] })
2048
+ ] }),
2049
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2050
+ "a",
2051
+ {
2052
+ href: zip321Uri,
2053
+ className: "inline-flex items-center justify-center gap-1.5 w-full py-2 px-3 rounded-md bg-[#171717] text-white text-xs font-medium hover:bg-[#212121] transition-colors",
2054
+ children: [
2055
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Open in Mobile / Desktop Wallet" }),
2056
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.ExternalLink, { className: "w-3.5 h-3.5 text-[#3ecf8e]" })
2057
+ ]
2058
+ }
2059
+ ),
2060
+ zucchiniAvailable && onPayWithZucchini && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2061
+ "button",
2062
+ {
2063
+ onClick: onPayWithZucchini,
2064
+ disabled: zucchiniPaying,
2065
+ className: "inline-flex items-center justify-center gap-2 w-full py-2.5 px-3 rounded-md bg-[#3ecf8e] text-[#171717] text-xs font-semibold hover:bg-[#24b47e] transition-colors disabled:opacity-60 disabled:cursor-wait shadow-sm",
2066
+ children: zucchiniPaying ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2067
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "w-3.5 h-3.5 border-2 border-[#171717]/30 border-t-[#171717] rounded-full animate-spin" }),
2068
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Confirming in Zucchini..." })
2069
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2070
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-sm", children: "\u{1F952}" }),
2071
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Pay with Zucchini Wallet" })
2072
+ ] })
2073
+ }
2074
+ ),
2075
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center gap-2", children: [
2076
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2077
+ "button",
2078
+ {
2079
+ onClick: () => copyToClipboard(zip321Uri, "uri"),
2080
+ className: "flex-1 py-1.5 px-2.5 rounded-md border border-[#ededed] hover:border-[#dfdfdf] hover:bg-[#fafafa] text-xs font-medium text-[#171717] transition-colors flex items-center justify-center gap-1",
2081
+ children: copiedType === "uri" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2082
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.Check, { className: "w-3 h-3 text-[#24b47e]" }),
2083
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-[#24b47e]", children: "Copied URI" })
2084
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2085
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.Copy, { className: "w-3 h-3 text-[#707070]" }),
2086
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Copy ZIP-321 URI" })
2087
+ ] })
2088
+ }
2089
+ ),
2090
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2091
+ "button",
2092
+ {
2093
+ onClick: () => copyToClipboard(recipient, "address"),
2094
+ className: "flex-1 py-1.5 px-2.5 rounded-md border border-[#ededed] hover:border-[#dfdfdf] hover:bg-[#fafafa] text-xs font-medium text-[#171717] transition-colors flex items-center justify-center gap-1",
2095
+ children: copiedType === "address" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2096
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.Check, { className: "w-3 h-3 text-[#24b47e]" }),
2097
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-[#24b47e]", children: "Copied Address" })
2098
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2099
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.Copy, { className: "w-3 h-3 text-[#707070]" }),
2100
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Copy Address" })
2101
+ ] })
2102
+ }
2103
+ )
2104
+ ] })
2105
+ ] })
2106
+ ] }),
2107
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "space-y-1.5 text-xs", children: [
2108
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center justify-between text-[#707070]", children: [
2109
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Recipient Address" }),
2110
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "font-mono text-[11px]", children: truncateAddress(recipient, 12, 10) })
2111
+ ] }),
2112
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "p-2 bg-[#fafafa] rounded-md border border-[#ededed] font-mono text-[11px] text-[#171717] break-all select-all", children: recipient })
2113
+ ] }),
2114
+ memo && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "space-y-1.5 text-xs p-3 rounded-md bg-[#fafafa] border border-[#ededed]", children: [
2115
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center justify-between", children: [
2116
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "flex items-center gap-1.5 font-medium text-[#171717]", children: [
2117
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.Lock, { className: "w-3 h-3 text-[#3ecf8e]" }),
2118
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Encrypted Memo" })
2119
+ ] }),
2120
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "text-[10px] font-mono text-[#707070]", children: [
2121
+ memoValidation.byteLength,
2122
+ "/512 bytes"
2123
+ ] })
2124
+ ] }),
2125
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "font-mono text-xs text-[#171717] bg-white p-2 rounded border border-[#dfdfdf]", children: memo }),
2126
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "text-[11px] text-[#707070]", children: "Only the recipient holding the viewing/spending key can decrypt this message on-chain." })
2127
+ ] }),
2128
+ memoValidation.warning && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "p-2.5 rounded-md bg-amber-50 border border-amber-200 text-amber-800 text-xs flex items-start gap-2", children: [
2129
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.AlertCircle, { className: "w-4 h-4 flex-shrink-0 mt-0.5 text-amber-600" }),
2130
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: memoValidation.warning })
2131
+ ] }),
2132
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "pt-2 border-t border-[#ededed] flex items-center justify-between", children: [
2133
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center gap-1.5 text-[11px] text-[#707070]", children: [
2134
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react4.Zap, { className: "w-3 h-3 text-[#3ecf8e]" }),
2135
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Demo Controls:" })
2136
+ ] }),
2137
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center gap-2", children: [
2138
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2139
+ "button",
2140
+ {
2141
+ onClick: onSimulateDetection,
2142
+ className: "px-2.5 py-1 text-[11px] font-medium rounded border border-[#dfdfdf] hover:border-[#3ecf8e] hover:text-[#24b47e] bg-white text-[#171717] transition-colors",
2143
+ children: "Simulate Payment"
2144
+ }
2145
+ ),
2146
+ status === "expired" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2147
+ "button",
2148
+ {
2149
+ onClick: onResetPayment,
2150
+ className: "px-2.5 py-1 text-[11px] font-medium rounded bg-[#171717] text-white hover:bg-[#212121] transition-colors",
2151
+ children: "Refresh"
2152
+ }
2153
+ )
2154
+ ] })
2155
+ ] })
2156
+ ] }) })
2157
+ ] })
2158
+ ] }),
2159
+ document.body
2160
+ );
2161
+ };
2162
+
2163
+ // src/components/CiceroPayButton.tsx
2164
+ var import_jsx_runtime7 = require("react/jsx-runtime");
2165
+ var CiceroPayButton = ({
2166
+ recipient,
2167
+ amount,
2168
+ memo,
2169
+ message,
2170
+ label = "Pay with Zcash",
2171
+ network = "mainnet",
2172
+ variant = "primary",
2173
+ size = "md",
2174
+ showUsd = true,
2175
+ modalTitle,
2176
+ modalSubtitle,
2177
+ expiresInSeconds = 900,
2178
+ customRpcUrl,
2179
+ invoiceId,
2180
+ onSuccess,
2181
+ onError,
2182
+ onStatusChange,
2183
+ className = "",
2184
+ disabled = false
2185
+ }) => {
2186
+ const {
2187
+ status,
2188
+ txId,
2189
+ secondsRemaining,
2190
+ isModalOpen,
2191
+ openModal,
2192
+ closeModal,
2193
+ resetPayment,
2194
+ zip321Uri,
2195
+ addressType,
2196
+ isShielded,
2197
+ memoValidation,
2198
+ simulateDetection,
2199
+ zucchiniAvailable,
2200
+ zucchiniPaying,
2201
+ payWithZucchini
2202
+ } = useCiceroPayment({
2203
+ recipient,
2204
+ amount,
2205
+ memo,
2206
+ message,
2207
+ network,
2208
+ expiresInSeconds,
2209
+ invoiceId,
2210
+ customRpcUrl,
2211
+ onSuccess,
2212
+ onError,
2213
+ onStatusChange
2214
+ });
2215
+ const sizeClasses = {
2216
+ sm: "text-xs px-3 py-1.5 gap-1.5",
2217
+ md: "text-sm px-4 py-2 gap-2",
2218
+ lg: "text-base px-5 py-2.5 gap-2.5"
2219
+ }[size];
2220
+ const variantClasses = {
2221
+ // Signature Supabase emerald CTA: #3ecf8e background, #171717 text, 6px radius
2222
+ primary: "bg-[#3ecf8e] text-[#171717] hover:bg-[#24b47e] active:bg-[#24b47e] shadow-sm font-medium",
2223
+ // Secondary outline on white
2224
+ outline: "bg-white text-[#171717] border border-[#dfdfdf] hover:border-[#c7c7c7] hover:bg-[#fafafa] font-medium shadow-sm",
2225
+ // Dark canvas-night
2226
+ dark: "bg-[#1c1c1c] text-white hover:bg-[#242424] font-medium shadow-sm"
2227
+ }[variant];
2228
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2229
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2230
+ "button",
2231
+ {
2232
+ type: "button",
2233
+ onClick: openModal,
2234
+ disabled,
2235
+ className: `inline-flex items-center justify-center rounded-[6px] transition-all duration-150 select-none disabled:opacity-50 disabled:cursor-not-allowed ${sizeClasses} ${variantClasses} ${className}`,
2236
+ children: [
2237
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2238
+ import_lucide_react5.Shield,
2239
+ {
2240
+ className: `flex-shrink-0 ${size === "sm" ? "w-3.5 h-3.5" : size === "lg" ? "w-5 h-5" : "w-4 h-4"} ${variant === "primary" ? "fill-[#171717]/20" : "text-[#3ecf8e]"}`
2241
+ }
2242
+ ),
2243
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: label })
2244
+ ]
2245
+ }
2246
+ ),
2247
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2248
+ CiceroModal,
2249
+ {
2250
+ isOpen: isModalOpen,
2251
+ onClose: closeModal,
2252
+ recipient,
2253
+ amount,
2254
+ memo,
2255
+ message,
2256
+ network,
2257
+ status,
2258
+ txId,
2259
+ secondsRemaining,
2260
+ zip321Uri,
2261
+ addressType,
2262
+ isShielded,
2263
+ memoValidation,
2264
+ onSimulateDetection: simulateDetection,
2265
+ onResetPayment: resetPayment,
2266
+ title: modalTitle,
2267
+ subtitle: modalSubtitle,
2268
+ showUsd,
2269
+ zucchiniAvailable,
2270
+ zucchiniPaying,
2271
+ onPayWithZucchini: payWithZucchini
2272
+ }
2273
+ )
2274
+ ] });
2275
+ };
2276
+
2277
+ // src/components/CiceroInvoice.tsx
2278
+ var import_react7 = require("react");
2279
+ var import_lucide_react6 = require("lucide-react");
2280
+ var import_jsx_runtime8 = require("react/jsx-runtime");
2281
+ var CiceroInvoice = ({
2282
+ recipient,
2283
+ amount,
2284
+ memo,
2285
+ message,
2286
+ network = "mainnet",
2287
+ expiresInSeconds = 900,
2288
+ showUsd = true,
2289
+ invoiceId,
2290
+ customRpcUrl,
2291
+ onSuccess,
2292
+ onError,
2293
+ onStatusChange,
2294
+ className = ""
2295
+ }) => {
2296
+ const [copiedType, setCopiedType] = (0, import_react7.useState)(null);
2297
+ const { convertZecToUsd } = useZcashPrice(showUsd);
2298
+ const {
2299
+ status,
2300
+ txId,
2301
+ secondsRemaining,
2302
+ zip321Uri,
2303
+ addressType,
2304
+ isShielded,
2305
+ memoValidation,
2306
+ simulateDetection,
2307
+ resetPayment,
2308
+ zucchiniAvailable,
2309
+ zucchiniPaying,
2310
+ payWithZucchini
2311
+ } = useCiceroPayment({
2312
+ recipient,
2313
+ amount,
2314
+ memo,
2315
+ message,
2316
+ network,
2317
+ expiresInSeconds,
2318
+ invoiceId,
2319
+ customRpcUrl,
2320
+ onSuccess,
2321
+ onError,
2322
+ onStatusChange
2323
+ });
2324
+ const copyToClipboard = async (text, type) => {
2325
+ try {
2326
+ await navigator.clipboard.writeText(text);
2327
+ setCopiedType(type);
2328
+ setTimeout(() => setCopiedType(null), 2e3);
2329
+ } catch {
2330
+ }
2331
+ };
2332
+ const formatTime = (secs) => {
2333
+ const m = Math.floor(secs / 60);
2334
+ const s = secs % 60;
2335
+ return `${m}:${s < 10 ? "0" : ""}${s}`;
2336
+ };
2337
+ const usdValue = convertZecToUsd(amount);
2338
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
2339
+ "div",
2340
+ {
2341
+ className: `bg-white rounded-xl border border-[#ededed] shadow-sm overflow-hidden text-[#171717] font-sans ${className}`,
2342
+ children: [
2343
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex items-center justify-between px-5 py-3.5 border-b border-[#ededed] bg-[#fafafa]", children: [
2344
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex items-center gap-2", children: [
2345
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "w-7 h-7 rounded-md bg-[#171717] flex items-center justify-center text-[#3ecf8e]", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.Shield, { className: "w-3.5 h-3.5 fill-[#3ecf8e]" }) }),
2346
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { children: [
2347
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "font-medium text-xs text-[#171717]", children: "Shielded Zcash Invoice" }),
2348
+ invoiceId && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "text-[10px] text-[#707070] ml-2 font-mono", children: [
2349
+ "#",
2350
+ invoiceId
2351
+ ] })
2352
+ ] })
2353
+ ] }),
2354
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex items-center gap-2", children: [
2355
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "text-[10px] font-mono px-1.5 py-0.5 rounded bg-white border border-[#dfdfdf] text-[#171717]", children: addressType === "unified" ? "Unified" : addressType === "sapling" ? "Sapling" : "Transparent" }),
2356
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "text-[10px] uppercase tracking-wider font-semibold px-2 py-0.5 rounded-full bg-[#3ecf8e]/15 text-[#24b47e] border border-[#3ecf8e]/30", children: isShielded ? "zk-Shielded" : "Transparent" }),
2357
+ network === "testnet" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "text-[10px] uppercase tracking-wider font-semibold px-2 py-0.5 rounded-full bg-amber-100 text-amber-800 border border-amber-200", children: "Testnet" })
2358
+ ] })
2359
+ ] }),
2360
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "p-5 space-y-4", children: status === "confirmed" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "py-6 text-center space-y-3", children: [
2361
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "w-12 h-12 mx-auto rounded-full bg-[#3ecf8e]/15 border border-[#3ecf8e]/40 flex items-center justify-center text-[#24b47e]", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.CheckCircle2, { className: "w-6 h-6" }) }),
2362
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { children: [
2363
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h4", { className: "font-medium text-sm text-[#171717]", children: "Payment Verified!" }),
2364
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "text-xs text-[#707070] mt-0.5", children: "Shielded transaction detected and settled on-chain." })
2365
+ ] }),
2366
+ txId && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "font-mono text-[11px] p-2 bg-[#fafafa] rounded border border-[#ededed] text-[#707070] break-all", children: txId })
2367
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
2368
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex items-center justify-between p-3.5 bg-[#fafafa] rounded-lg border border-[#ededed]", children: [
2369
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { children: [
2370
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "text-[10px] text-[#707070] uppercase font-mono tracking-wider", children: "Amount Due" }),
2371
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex items-baseline gap-2 mt-0.5", children: [
2372
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "text-xl font-semibold tracking-tight text-[#171717] font-mono", children: [
2373
+ amount,
2374
+ " ",
2375
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "text-xs font-normal text-[#707070]", children: "ZEC" })
2376
+ ] }),
2377
+ usdValue && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "text-xs text-[#707070] font-mono", children: [
2378
+ "\u2248 $",
2379
+ usdValue,
2380
+ " USD"
2381
+ ] })
2382
+ ] })
2383
+ ] }),
2384
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex items-center gap-1.5 text-[#707070] font-mono text-xs", children: [
2385
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.Clock, { className: "w-3.5 h-3.5" }),
2386
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: formatTime(secondsRemaining) })
2387
+ ] })
2388
+ ] }),
2389
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex flex-col sm:flex-row items-center gap-4", children: [
2390
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CiceroQRCode, { value: zip321Uri, size: 140 }),
2391
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "space-y-2.5 w-full", children: [
2392
+ zucchiniAvailable && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2393
+ "button",
2394
+ {
2395
+ onClick: payWithZucchini,
2396
+ disabled: zucchiniPaying,
2397
+ className: "inline-flex items-center justify-center gap-1.5 w-full py-2 px-3 rounded-md bg-[#3ecf8e] text-[#171717] text-xs font-semibold hover:bg-[#24b47e] transition-colors disabled:opacity-60 shadow-sm",
2398
+ children: zucchiniPaying ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
2399
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "w-3.5 h-3.5 border-2 border-[#171717]/30 border-t-[#171717] rounded-full animate-spin" }),
2400
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "Confirming in Zucchini..." })
2401
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
2402
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "\u{1F952}" }),
2403
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "Pay with Zucchini Wallet" })
2404
+ ] })
2405
+ }
2406
+ ),
2407
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
2408
+ "a",
2409
+ {
2410
+ href: zip321Uri,
2411
+ className: "inline-flex items-center justify-center gap-1.5 w-full py-2 px-3 rounded-md bg-[#171717] text-white text-xs font-medium hover:bg-[#212121] transition-colors",
2412
+ children: [
2413
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "Pay with Wallet App" }),
2414
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.ExternalLink, { className: "w-3.5 h-3.5 text-[#3ecf8e]" })
2415
+ ]
2416
+ }
2417
+ ),
2418
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "grid grid-cols-2 gap-2", children: [
2419
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
2420
+ "button",
2421
+ {
2422
+ onClick: () => copyToClipboard(zip321Uri, "uri"),
2423
+ className: "py-1.5 px-2 rounded-md border border-[#ededed] hover:bg-[#fafafa] text-[11px] font-medium text-[#171717] transition-colors flex items-center justify-center gap-1",
2424
+ children: [
2425
+ copiedType === "uri" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.Check, { className: "w-3 h-3 text-[#24b47e]" }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.Copy, { className: "w-3 h-3 text-[#707070]" }),
2426
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: copiedType === "uri" ? "Copied" : "Copy URI" })
2427
+ ]
2428
+ }
2429
+ ),
2430
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
2431
+ "button",
2432
+ {
2433
+ onClick: () => copyToClipboard(recipient, "address"),
2434
+ className: "py-1.5 px-2 rounded-md border border-[#ededed] hover:bg-[#fafafa] text-[11px] font-medium text-[#171717] transition-colors flex items-center justify-center gap-1",
2435
+ children: [
2436
+ copiedType === "address" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.Check, { className: "w-3 h-3 text-[#24b47e]" }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.Copy, { className: "w-3 h-3 text-[#707070]" }),
2437
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: copiedType === "address" ? "Copied" : "Copy Addr" })
2438
+ ]
2439
+ }
2440
+ )
2441
+ ] }),
2442
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "text-[11px] text-[#707070] font-mono truncate", children: [
2443
+ "To: ",
2444
+ truncateAddress(recipient, 10, 8)
2445
+ ] })
2446
+ ] })
2447
+ ] }),
2448
+ memo && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "p-2.5 bg-[#fafafa] rounded-md border border-[#ededed] text-xs", children: [
2449
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex items-center gap-1 text-[11px] font-medium text-[#171717] mb-0.5", children: [
2450
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.Lock, { className: "w-3 h-3 text-[#3ecf8e]" }),
2451
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "Encrypted Memo" })
2452
+ ] }),
2453
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "font-mono text-[11px] text-[#171717]", children: memo })
2454
+ ] }),
2455
+ memoValidation.warning && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "p-2 rounded bg-amber-50 border border-amber-200 text-amber-800 text-[11px] flex items-start gap-1.5", children: [
2456
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.AlertCircle, { className: "w-3.5 h-3.5 flex-shrink-0 mt-0.5 text-amber-600" }),
2457
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: memoValidation.warning })
2458
+ ] }),
2459
+ status === "expired" && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "p-2 rounded bg-rose-50 border border-rose-200 text-rose-800 text-xs flex items-center justify-between", children: [
2460
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex items-center gap-1.5", children: [
2461
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.AlertCircle, { className: "w-3.5 h-3.5 text-rose-600" }),
2462
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "Invoice has expired" })
2463
+ ] }),
2464
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2465
+ "button",
2466
+ {
2467
+ onClick: resetPayment,
2468
+ className: "px-2 py-0.5 text-[11px] font-medium rounded bg-[#171717] text-white hover:bg-[#212121]",
2469
+ children: "Reset"
2470
+ }
2471
+ )
2472
+ ] }),
2473
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "pt-2 border-t border-[#ededed] flex items-center justify-between text-[11px] text-[#707070]", children: [
2474
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "flex items-center gap-1", children: [
2475
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react6.Sparkles, { className: "w-3 h-3 text-[#3ecf8e]" }),
2476
+ "Demo test"
2477
+ ] }),
2478
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2479
+ "button",
2480
+ {
2481
+ onClick: simulateDetection,
2482
+ className: "px-2 py-0.5 rounded border border-[#dfdfdf] hover:border-[#3ecf8e] text-[#171717] bg-white transition-colors",
2483
+ children: "Simulate Success"
2484
+ }
2485
+ )
2486
+ ] })
2487
+ ] }) })
2488
+ ]
2489
+ }
2490
+ );
2491
+ };
2492
+
2493
+ // src/hooks/useZucchiniWallet.ts
2494
+ var import_react8 = require("react");
2495
+ function useZucchiniWallet(options = {}) {
2496
+ const { autoConnect = false } = options;
2497
+ const [adapter2] = (0, import_react8.useState)(() => new ZucchiniWalletAdapter());
2498
+ const [isAvailable, setIsAvailable] = (0, import_react8.useState)(false);
2499
+ const [connectionStatus, setConnectionStatus] = (0, import_react8.useState)("disconnected");
2500
+ const [paymentStatus, setPaymentStatus] = (0, import_react8.useState)("idle");
2501
+ const [session, setSession] = (0, import_react8.useState)(null);
2502
+ const [error, setError] = (0, import_react8.useState)(null);
2503
+ (0, import_react8.useEffect)(() => {
2504
+ const detected = ZucchiniWalletAdapter.isAvailable();
2505
+ setIsAvailable(detected);
2506
+ if (detected && autoConnect) {
2507
+ connect();
2508
+ }
2509
+ }, []);
2510
+ const connect = (0, import_react8.useCallback)(async () => {
2511
+ setConnectionStatus("connecting");
2512
+ setError(null);
2513
+ try {
2514
+ const sess = await adapter2.connect();
2515
+ setSession(sess);
2516
+ setConnectionStatus("connected");
2517
+ return sess;
2518
+ } catch (err) {
2519
+ const msg = err instanceof Error ? err.message : "Failed to connect to Zucchini Wallet";
2520
+ setError(msg);
2521
+ setConnectionStatus("error");
2522
+ throw err;
2523
+ }
2524
+ }, [adapter2]);
2525
+ const requestPayment = (0, import_react8.useCallback)(
2526
+ async (params) => {
2527
+ setPaymentStatus("requesting");
2528
+ setError(null);
2529
+ try {
2530
+ const result = await adapter2.requestPayment(params);
2531
+ setPaymentStatus("submitted");
2532
+ return result;
2533
+ } catch (err) {
2534
+ const msg = err instanceof Error ? err.message : "Payment request failed";
2535
+ setError(msg);
2536
+ setPaymentStatus("error");
2537
+ throw err;
2538
+ }
2539
+ },
2540
+ [adapter2]
2541
+ );
2542
+ const disconnect = (0, import_react8.useCallback)(async () => {
2543
+ await adapter2.disconnect();
2544
+ setSession(null);
2545
+ setConnectionStatus("disconnected");
2546
+ setPaymentStatus("idle");
2547
+ }, [adapter2]);
2548
+ return {
2549
+ /** Whether the Zucchini extension is installed in this browser */
2550
+ isAvailable,
2551
+ /** Current wallet connection lifecycle state */
2552
+ connectionStatus,
2553
+ /** Current payment request lifecycle state */
2554
+ paymentStatus,
2555
+ /** Active session info (address, etc.) */
2556
+ session,
2557
+ /** Last error message (if any) */
2558
+ error,
2559
+ /** Prompt the user to connect their Zucchini Wallet */
2560
+ connect,
2561
+ /** Send a ZIP-321 payment request for user review & approval */
2562
+ requestPayment,
2563
+ /** Disconnect the current session */
2564
+ disconnect
2565
+ };
2566
+ }
2567
+ // Annotate the CommonJS export names for ESM import in node:
2568
+ 0 && (module.exports = {
2569
+ CiceroAccountModal,
2570
+ CiceroConnectButton,
2571
+ CiceroConnectModal,
2572
+ CiceroInvoice,
2573
+ CiceroModal,
2574
+ CiceroPayButton,
2575
+ CiceroProvider,
2576
+ CiceroQRCode,
2577
+ ZucchiniWalletAdapter,
2578
+ burnerWallet,
2579
+ decodeBase64Url,
2580
+ encodeBase64Url,
2581
+ generateZip321Uri,
2582
+ getAddressType,
2583
+ getDefaultWallets,
2584
+ getWalletDeepLinks,
2585
+ isShieldedAddress,
2586
+ parseZip321Uri,
2587
+ truncateAddress,
2588
+ useAccount,
2589
+ useAccountModal,
2590
+ useBalance,
2591
+ useCicero,
2592
+ useCiceroPayment,
2593
+ useConnectModal,
2594
+ useZcashPrice,
2595
+ useZucchiniWallet,
2596
+ validateMemoSupport,
2597
+ viewingKeyWallet,
2598
+ ywallet,
2599
+ zashiWallet,
2600
+ zucchiniWallet
2601
+ });
2602
+ //# sourceMappingURL=index.js.map