@vulcx/widget 0.2.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/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # @vulcx/widget
2
+
3
+ Embeddable swap widget for the Vulcx DEX aggregator. Framework-agnostic Web Component that works in React, Vue, Svelte, Angular, or plain HTML.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @vulcx/widget
9
+ ```
10
+
11
+ Or via CDN (no build step needed):
12
+
13
+ ```html
14
+ <script src="https://cdn.vulcx.xyz/vulcx-widget.umd.js"></script>
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### HTML / CDN
20
+
21
+ ```html
22
+ <script src="https://cdn.vulcx.xyz/vulcx-widget.umd.js"></script>
23
+
24
+ <vulcx-swap
25
+ api-key="vulcx_your_api_key"
26
+ chain="solana"
27
+ default-input-mint="So11111111111111111111111111111111111111112"
28
+ default-output-mint="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
29
+ theme="dark"
30
+ ></vulcx-swap>
31
+ ```
32
+
33
+ ### React
34
+
35
+ ```tsx
36
+ import "@vulcx/widget";
37
+
38
+ function App() {
39
+ return (
40
+ <vulcx-swap
41
+ api-key="vulcx_your_api_key"
42
+ chain="solana"
43
+ default-input-mint="So11111111111111111111111111111111111111112"
44
+ default-output-mint="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
45
+ theme="dark"
46
+ />
47
+ );
48
+ }
49
+ ```
50
+
51
+ For TypeScript, add to your `global.d.ts`:
52
+
53
+ ```typescript
54
+ declare namespace JSX {
55
+ interface IntrinsicElements {
56
+ "vulcx-swap": React.DetailedHTMLProps<
57
+ React.HTMLAttributes<HTMLElement> & {
58
+ "api-key"?: string;
59
+ chain?: string;
60
+ "default-input-mint"?: string;
61
+ "default-output-mint"?: string;
62
+ theme?: "dark" | "light";
63
+ },
64
+ HTMLElement
65
+ >;
66
+ }
67
+ }
68
+ ```
69
+
70
+ ### Vue
71
+
72
+ ```vue
73
+ <template>
74
+ <vulcx-swap
75
+ api-key="vulcx_your_api_key"
76
+ chain="solana"
77
+ default-input-mint="So11111111111111111111111111111111111111112"
78
+ default-output-mint="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
79
+ theme="dark"
80
+ @quote-update="onQuote"
81
+ @swap-complete="onSwap"
82
+ />
83
+ </template>
84
+
85
+ <script setup>
86
+ import "@vulcx/widget";
87
+
88
+ function onQuote(e) {
89
+ console.log("Quote:", e.detail);
90
+ }
91
+ function onSwap(e) {
92
+ console.log("Swap:", e.detail);
93
+ }
94
+ </script>
95
+ ```
96
+
97
+ ### Next.js
98
+
99
+ ```tsx
100
+ "use client";
101
+ import { useEffect, useRef } from "react";
102
+
103
+ export default function SwapWidget() {
104
+ const ref = useRef<HTMLElement>(null);
105
+
106
+ useEffect(() => {
107
+ import("@vulcx/widget");
108
+ }, []);
109
+
110
+ return (
111
+ <vulcx-swap
112
+ ref={ref}
113
+ api-key="vulcx_your_api_key"
114
+ chain="solana"
115
+ theme="dark"
116
+ />
117
+ );
118
+ }
119
+ ```
120
+
121
+ ## Attributes
122
+
123
+ | Attribute | Type | Default | Description |
124
+ | --------------------- | ------------------ | ---------- | ------------------------------ |
125
+ | `api-key` | `string` | — | **Required.** Your API key |
126
+ | `chain` | `"solana"\|"fogo"` | `"solana"` | Target chain |
127
+ | `base-url` | `string` | Production | API base URL override |
128
+ | `default-input-mint` | `string` | — | Pre-selected input token mint |
129
+ | `default-output-mint` | `string` | — | Pre-selected output token mint |
130
+ | `theme` | `"dark"\|"light"` | `"dark"` | Color theme |
131
+
132
+ ## Events
133
+
134
+ | Event | Detail | Description |
135
+ | ----------------- | ----------------------------------------- | ----------------------------- |
136
+ | `quote-update` | `QuoteResponse` | Fired when a new quote loads |
137
+ | `swap-initiated` | `{ inputMint, outputMint, amount }` | Fired when swap starts |
138
+ | `swap-complete` | `SwapResponse` | Fired on successful swap |
139
+ | `swap-error` | `{ error: string }` | Fired on swap failure |
140
+ | `connect-wallet` | `{}` | Fired when user clicks swap without wallet |
141
+
142
+ ## Wallet Integration
143
+
144
+ Set the wallet address programmatically:
145
+
146
+ ```javascript
147
+ const widget = document.querySelector("vulcx-swap");
148
+ widget.setWallet("9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM");
149
+ ```
150
+
151
+ Listen for the `connect-wallet` event to trigger your wallet adapter:
152
+
153
+ ```javascript
154
+ widget.addEventListener("connect-wallet", async () => {
155
+ const wallet = await connectWallet(); // your wallet adapter
156
+ widget.setWallet(wallet.publicKey.toString());
157
+ });
158
+ ```
159
+
160
+ ## Customization
161
+
162
+ Override CSS custom properties on the host element:
163
+
164
+ ```css
165
+ vulcx-swap {
166
+ --vulcx-bg: #0d0d12;
167
+ --vulcx-accent: #00ff88;
168
+ --vulcx-radius: 20px;
169
+ }
170
+ ```
171
+
172
+ Available CSS variables:
173
+
174
+ | Variable | Default (dark) | Description |
175
+ | --------------------------- | -------------- | ------------------ |
176
+ | `--vulcx-bg` | `#0a0a0f` | Background |
177
+ | `--vulcx-surface` | `#141419` | Card/panel bg |
178
+ | `--vulcx-surface-hover` | `#1c1c24` | Hover state |
179
+ | `--vulcx-border` | `#2a2a35` | Borders |
180
+ | `--vulcx-text` | `#e8e8ed` | Primary text |
181
+ | `--vulcx-text-secondary` | `#8b8b9a` | Secondary text |
182
+ | `--vulcx-accent` | `#c8ff00` | Accent / CTA |
183
+ | `--vulcx-error` | `#ff4d6a` | Error color |
184
+ | `--vulcx-radius` | `16px` | Border radius |