@zucchinifi/dapp-sdk 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -555,14 +555,26 @@ async function generateQRCode(text, options = {}) {
555
555
  logoHeight = 60
556
556
  } = options;
557
557
  try {
558
- const qrDataUrl = await QRCode.toDataURL(text, {
559
- width,
560
- margin,
561
- color,
562
- errorCorrectionLevel: "H"
563
- // High error correction for logo overlay
564
- });
565
- if (!logoUrl) {
558
+ let qrDataUrl = "";
559
+ if (typeof document === "undefined") {
560
+ const svgString = await QRCode.toString(text, {
561
+ type: "svg",
562
+ width,
563
+ margin,
564
+ color,
565
+ errorCorrectionLevel: "H"
566
+ });
567
+ const base64 = typeof Buffer !== "undefined" ? Buffer.from(svgString).toString("base64") : btoa(unescape(encodeURIComponent(svgString)));
568
+ qrDataUrl = `data:image/svg+xml;base64,${base64}`;
569
+ } else {
570
+ qrDataUrl = await QRCode.toDataURL(text, {
571
+ width,
572
+ margin,
573
+ color,
574
+ errorCorrectionLevel: "H"
575
+ });
576
+ }
577
+ if (!logoUrl || typeof document === "undefined") {
566
578
  return qrDataUrl;
567
579
  }
568
580
  if (typeof document === "undefined") {
@@ -605,6 +617,90 @@ async function generateQRCode(text, options = {}) {
605
617
 
606
618
  // src/index.ts
607
619
  var ZucchiniSDK = class {
620
+ constructor(config) {
621
+ this._apiUrl = "https://api.zucchinifi.xyz";
622
+ this.swap = {
623
+ getQuote: async (args) => {
624
+ const { from, to, amount, recipient, refundAddress, dry } = args;
625
+ const params = new URLSearchParams({
626
+ from,
627
+ to,
628
+ amount,
629
+ recipient: recipient || "0x0000000000000000000000000000000000000000",
630
+ refundAddress: refundAddress || "0x0000000000000000000000000000000000000000",
631
+ dry: dry !== void 0 ? dry.toString() : "true"
632
+ });
633
+ const res = await fetch(`${this.apiUrl}/swap/quote?${params.toString()}`);
634
+ const data = await res.json();
635
+ if (data.error) {
636
+ throw new Error(data.error);
637
+ }
638
+ const quote = data.quote;
639
+ return {
640
+ ...quote,
641
+ deadline: quote.deadline || data.quoteRequest?.deadline
642
+ };
643
+ },
644
+ submitDepositHash: async (args) => {
645
+ const res = await fetch(`${this.apiUrl}/swap/submit-deposit`, {
646
+ method: "POST",
647
+ headers: { "Content-Type": "application/json" },
648
+ body: JSON.stringify(args)
649
+ });
650
+ const data = await res.json();
651
+ if (data.error) throw new Error(data.error);
652
+ return data;
653
+ },
654
+ getStatus: async (depositAddress, memo) => {
655
+ const params = new URLSearchParams({ depositAddress });
656
+ if (memo) params.append("memo", memo);
657
+ const res = await fetch(`${this.apiUrl}/swap/status?${params.toString()}`);
658
+ const data = await res.json();
659
+ if (data.error) throw new Error(data.error);
660
+ return data;
661
+ },
662
+ getWithdrawals: async (depositAddress, options = {}) => {
663
+ const params = new URLSearchParams({ depositAddress });
664
+ if (options.memo) params.append("memo", options.memo);
665
+ if (options.timestampFrom) params.append("timestampFrom", options.timestampFrom);
666
+ if (options.page) params.append("page", options.page.toString());
667
+ if (options.limit) params.append("limit", options.limit.toString());
668
+ if (options.sortOrder) params.append("sortOrder", options.sortOrder);
669
+ const res = await fetch(`${this.apiUrl}/swap/withdrawals?${params.toString()}`);
670
+ const data = await res.json();
671
+ if (data.error) throw new Error(data.error);
672
+ return data;
673
+ }
674
+ };
675
+ this.explorer = {
676
+ getTransactions: async (params = {}) => {
677
+ const searchParams = new URLSearchParams();
678
+ Object.entries(params).forEach(([key, value]) => {
679
+ if (value !== void 0 && value !== null) searchParams.append(key, value.toString());
680
+ });
681
+ const res = await fetch(`${this.apiUrl}/explorer/transactions?${searchParams.toString()}`);
682
+ const data = await res.json();
683
+ if (data.error) throw new Error(data.error);
684
+ return data;
685
+ }
686
+ };
687
+ if (config) {
688
+ this.configure(config);
689
+ }
690
+ }
691
+ /**
692
+ * Configure the SDK at runtime.
693
+ */
694
+ configure(config) {
695
+ if (config.apiUrl) {
696
+ this._apiUrl = config.apiUrl;
697
+ } else if (config.dev) {
698
+ this._apiUrl = "http://localhost:3001";
699
+ }
700
+ }
701
+ get apiUrl() {
702
+ return this._apiUrl;
703
+ }
608
704
  /**
609
705
  * Check if the Zucchini extension is installed and the provider is injected.
610
706
  */
@@ -686,29 +782,10 @@ var ZucchiniSDK = class {
686
782
  return this.request({ method: "getWalletStatus" });
687
783
  }
688
784
  async getTokens() {
689
- const API_BASE_URL = "https://api.zucchinifi.xyz";
690
- const res = await fetch(`${API_BASE_URL}/tokens`);
785
+ const res = await fetch(`${this.apiUrl}/tokens`);
691
786
  if (!res.ok) throw new Error("Failed to fetch tokens");
692
787
  return res.json();
693
788
  }
694
- async getSwapQuote(args) {
695
- const API_BASE_URL = "https://api.zucchinifi.xyz";
696
- const { from, to, amount, recipient, refundAddress } = args;
697
- const params = new URLSearchParams({
698
- from,
699
- to,
700
- amount,
701
- recipient: recipient || "0x0000000000000000000000000000000000000000",
702
- refundAddress: refundAddress || "0x0000000000000000000000000000000000000000",
703
- dry: "true"
704
- });
705
- const res = await fetch(`${API_BASE_URL}/swap/quote?${params.toString()}`);
706
- const data = await res.json();
707
- if (data.error) {
708
- throw new Error(data.error);
709
- }
710
- return data.quote;
711
- }
712
789
  };
713
790
  var zucchini = new ZucchiniSDK();
714
791
  export {
package/dist/types.d.ts CHANGED
@@ -56,24 +56,21 @@ export interface DetailedKey {
56
56
  }
57
57
  export interface Token {
58
58
  symbol: string;
59
- name: string;
60
- icon: string;
59
+ assetId: string;
61
60
  decimals: number;
62
- assetId?: string;
61
+ blockchain: string;
62
+ price?: string;
63
+ name?: string;
64
+ icon?: string;
63
65
  }
64
66
  export interface SwapQuote {
65
- quote: {
66
- amountOutFormatted: string;
67
- amountIn: string;
68
- amountOut: string;
69
- depositAddress?: string;
70
- depositMemo?: string;
71
- timeEstimate: number;
72
- };
73
- quoteRequest: {
74
- deadline: string;
75
- };
67
+ amountOutFormatted: string;
68
+ amountIn: string;
69
+ amountOut: string;
76
70
  depositAddress?: string;
71
+ depositMemo?: string;
72
+ timeEstimate: number;
73
+ deadline?: string;
77
74
  }
78
75
  export interface QuoteRequestArgs {
79
76
  from: string;
@@ -81,6 +78,35 @@ export interface QuoteRequestArgs {
81
78
  amount: string;
82
79
  recipient?: string;
83
80
  refundAddress?: string;
81
+ dry?: boolean;
82
+ }
83
+ export interface DepositSubmitArgs {
84
+ transactionHash: string;
85
+ depositAddress: string;
86
+ memo?: string;
87
+ userAccount?: string;
88
+ }
89
+ export interface SwapStatus {
90
+ status: 'KNOWN_DEPOSIT_TX' | 'PENDING_DEPOSIT' | 'INCOMPLETE_DEPOSIT' | 'PROCESSING' | 'SUCCESS' | 'REFUNDED' | 'FAILED';
91
+ depositAddress: string;
92
+ depositMemo?: string;
93
+ swaps?: any[];
94
+ }
95
+ export interface Withdrawal {
96
+ id: string;
97
+ status: string;
98
+ amount: string;
99
+ assetId: string;
100
+ timestamp: string;
101
+ }
102
+ export interface ExplorerTransaction {
103
+ depositAddressAndMemo: string;
104
+ status: string;
105
+ originAsset: string;
106
+ destinationAsset: string;
107
+ amountIn: string;
108
+ amountOut: string;
109
+ timestamp: string;
84
110
  }
85
111
  declare global {
86
112
  interface Window {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zucchinifi/dapp-sdk",
3
- "version": "0.1.0",
4
- "description": "TypeScript SDK for Zucchini Wallet",
3
+ "version": "0.1.2",
4
+ "description": "TypeScript SDK for Zcash self-custody browser wallet Zucchini",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",