@edel-finance/swap-widget 0.1.5-alpha → 0.1.7-alpha

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/widget.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { EdelClient, type EdelNetwork, type SwapOrder, type SwapOrderStatus, type SwapQuote } from "@edel-finance/sdk";
1
+ import { EdelClient, type EdelNetwork, type MarketSummary, type SwapOrder, type SwapOrderStatus, type SwapQuote } from "@edel-finance/sdk";
2
2
  import type { CSSProperties } from "react";
3
3
  import { type SwapWidgetTheme } from "./theme.js";
4
4
  export declare const SWAP_STATUS_STEPS: ReadonlyArray<{
5
5
  status: SwapOrderStatus;
6
6
  label: string;
7
7
  }>;
8
+ export declare const SWAP_RAIL_STEPS: readonly ["Quote", "Review", "Sign", "Settled"];
8
9
  export declare const DEFAULT_SWAP_ASSETS: readonly ["CC", "USDCx", "EDELx", "NVDAe", "SPYe", "QQQe", "SPCXe", "ANTe", "TTWOe"];
9
10
  /** Alpine Forest II slippage presets: 1.0% (default), 2.0%, 3.0%. */
10
11
  export declare const SLIPPAGE_PRESETS_BPS: readonly [100, 200, 300];
@@ -21,6 +22,14 @@ export declare function resolveInitialSlippageBps(bps?: number): number;
21
22
  * Returns null if the input is outside 0.01%..50.00% (1..5000 bps).
22
23
  */
23
24
  export declare function parseCustomSlippagePercent(raw: string): number | null;
25
+ export interface SwapRailProgress {
26
+ index: 0 | 1 | 2 | 3;
27
+ complete: boolean;
28
+ }
29
+ /**
30
+ * Map current swap quote / order state to the 4-step top progress rail.
31
+ */
32
+ export declare function getSwapRailProgress(quote: SwapQuote | null, order: SwapOrder | null): SwapRailProgress;
24
33
  export interface EdelSwapWidgetProps {
25
34
  /** Integrator / partner identifier for fee attribution (SuperNova, Loop, etc.). */
26
35
  integratorId?: string;
@@ -50,6 +59,8 @@ export interface EdelSwapWidgetProps {
50
59
  initialQuote?: SwapQuote | null;
51
60
  /** Optional initial active order (useful for SSR preview or testing). */
52
61
  initialOrder?: SwapOrder | null;
62
+ /** Optional initial baseAsset -> HTTPS logoUrl map (useful for SSR preview or testing). */
63
+ initialLogoUrls?: Readonly<Record<string, string>>;
53
64
  /** Callback fired whenever a live quote is fetched. */
54
65
  onQuote?: (quote: SwapQuote) => void;
55
66
  /** Callback fired when the user updates max slippage (in basis points). */
@@ -66,4 +77,13 @@ export interface EdelSwapWidgetProps {
66
77
  export declare function getStepState(stepStatus: SwapOrderStatus, currentStatus: SwapOrderStatus): "done" | "active" | "pending";
67
78
  export declare function formatBps(bps: number): string;
68
79
  export declare function formatPresetPercent(bps: number): string;
80
+ /**
81
+ * Extract a baseAsset -> HTTPS logoUrl map from Edel Markets API summaries.
82
+ * Ignores markets with logoUnavailable === true or non-HTTPS URLs.
83
+ */
84
+ export declare function extractMarketLogoUrls(markets: readonly MarketSummary[]): Record<string, string>;
85
+ /**
86
+ * Filter token options by symbol or display name (case-insensitive).
87
+ */
88
+ export declare function filterTokenOptions(options: readonly string[], query: string, assetNames?: Readonly<Record<string, string>>): string[];
69
89
  export declare function EdelSwapWidget(props: EdelSwapWidgetProps): import("react").JSX.Element;
package/dist/widget.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { DEFAULT_MAX_SLIPPAGE_BPS, DEFAULT_QUOTE_TTL_SECONDS, EdelClient, MAX_SLIPPAGE_BPS, MIN_SLIPPAGE_BPS, } from "@edel-finance/sdk";
3
3
  import { useEffect, useMemo, useRef, useState } from "react";
4
- import { EdelBrandMark, TokenLogo } from "./logos.js";
4
+ import { EdelBrandMark, getTokenDisplayName, isValidHttpsLogoUrl, TokenOnChainLogo, } from "./logos.js";
5
5
  import { getIsolatedWidgetCss } from "./theme.js";
6
6
  export const SWAP_STATUS_STEPS = [
7
7
  { status: "quoted", label: "Quoted" },
@@ -10,6 +10,7 @@ export const SWAP_STATUS_STEPS = [
10
10
  { status: "filled", label: "Filled" },
11
11
  { status: "settled", label: "Settled" },
12
12
  ];
13
+ export const SWAP_RAIL_STEPS = ["Quote", "Review", "Sign", "Settled"];
13
14
  export const DEFAULT_SWAP_ASSETS = [
14
15
  "CC",
15
16
  "USDCx",
@@ -56,6 +57,21 @@ export function parseCustomSlippagePercent(raw) {
56
57
  return null;
57
58
  return bps;
58
59
  }
60
+ /**
61
+ * Map current swap quote / order state to the 4-step top progress rail.
62
+ */
63
+ export function getSwapRailProgress(quote, order) {
64
+ if (order) {
65
+ if (order.status === "settled")
66
+ return { index: 3, complete: true };
67
+ if (order.status === "filled")
68
+ return { index: 3, complete: false };
69
+ return { index: 2, complete: false };
70
+ }
71
+ if (quote)
72
+ return { index: 1, complete: false };
73
+ return { index: 0, complete: false };
74
+ }
59
75
  export function getStepState(stepStatus, currentStatus) {
60
76
  const order = SWAP_STATUS_STEPS.map((s) => s.status);
61
77
  const stepIdx = order.indexOf(stepStatus);
@@ -74,48 +90,78 @@ export function formatBps(bps) {
74
90
  export function formatPresetPercent(bps) {
75
91
  return `${(bps / 100).toFixed(1)}%`;
76
92
  }
77
- function TokenSelector({ ariaLabel, value, options, onChange, testId }) {
78
- const [open, setOpen] = useState(false);
79
- const containerRef = useRef(null);
93
+ /**
94
+ * Extract a baseAsset -> HTTPS logoUrl map from Edel Markets API summaries.
95
+ * Ignores markets with logoUnavailable === true or non-HTTPS URLs.
96
+ */
97
+ export function extractMarketLogoUrls(markets) {
98
+ const map = {};
99
+ for (const market of markets) {
100
+ const info = market && typeof market.info === "object" && market.info !== null
101
+ ? market.info
102
+ : null;
103
+ if (!info || info.logoUnavailable === true)
104
+ continue;
105
+ if (!isValidHttpsLogoUrl(info.logoUrl))
106
+ continue;
107
+ const logoUrl = info.logoUrl.trim();
108
+ const baseAsset = typeof info.baseAsset === "string" ? info.baseAsset.trim() : "";
109
+ const marketBase = typeof market.base === "string" ? market.base.trim() : "";
110
+ if (baseAsset && !(baseAsset in map)) {
111
+ map[baseAsset] = logoUrl;
112
+ }
113
+ if (marketBase && !(marketBase in map)) {
114
+ map[marketBase] = logoUrl;
115
+ }
116
+ }
117
+ return map;
118
+ }
119
+ /**
120
+ * Filter token options by symbol or display name (case-insensitive).
121
+ */
122
+ export function filterTokenOptions(options, query, assetNames) {
123
+ const q = query.trim().toLowerCase();
124
+ if (!q)
125
+ return [...options];
126
+ return options.filter((sym) => {
127
+ const name = getTokenDisplayName(sym, assetNames?.[sym]).toLowerCase();
128
+ return sym.toLowerCase().includes(q) || name.includes(q);
129
+ });
130
+ }
131
+ function TokenPickerButton({ ariaLabel, value, open, logoUrls, onToggle, testId, }) {
132
+ return (_jsx("div", { className: "edel-sw-token-picker", "data-testid": testId, children: _jsxs("button", { type: "button", className: "edel-sw-token-trigger", "aria-label": ariaLabel, "aria-haspopup": "listbox", "aria-expanded": open, "data-selected-asset": value, onClick: onToggle, children: [_jsx(TokenOnChainLogo, { symbol: value, size: 24, className: "edel-sw-token-icon", logoUrl: logoUrls?.[value] }), _jsx("span", { className: "edel-sw-token-symbol", children: value }), _jsx("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: "edel-sw-token-chevron", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M4 6L8 10L12 6", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round" }) })] }) }));
133
+ }
134
+ function TokenDropdown({ ariaLabel, value, options, assetNames, logoUrls, onSelect, onClose, testId, }) {
135
+ const [query, setQuery] = useState("");
136
+ const inputRef = useRef(null);
80
137
  useEffect(() => {
81
- if (!open)
82
- return;
83
- const handlePointerDown = (event) => {
84
- const container = containerRef.current;
85
- if (!container)
86
- return;
87
- const path = typeof event.composedPath === "function" ? event.composedPath() : [];
88
- if (path.length > 0 ? !path.includes(container) : !container.contains(event.target)) {
89
- setOpen(false);
90
- }
91
- };
92
- const handleKeyDown = (event) => {
93
- if (event.key === "Escape") {
94
- setOpen(false);
95
- }
96
- };
97
- document.addEventListener("pointerdown", handlePointerDown);
98
- document.addEventListener("keydown", handleKeyDown);
99
- return () => {
100
- document.removeEventListener("pointerdown", handlePointerDown);
101
- document.removeEventListener("keydown", handleKeyDown);
102
- };
103
- }, [open]);
104
- return (_jsxs("div", { className: "edel-sw-token-picker", ref: containerRef, "data-testid": testId, children: [_jsxs("button", { type: "button", className: "edel-sw-token-trigger", "aria-label": ariaLabel, "aria-haspopup": "listbox", "aria-expanded": open, "data-selected-asset": value, onClick: () => setOpen((prev) => !prev), children: [_jsx(TokenLogo, { symbol: value, size: 22, className: "edel-sw-token-icon" }), _jsx("span", { className: "edel-sw-token-symbol", children: value }), _jsx("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: "edel-sw-token-chevron", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M3 4.5L6 7.5L9 4.5", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round" }) })] }), open && (_jsx("div", { className: "edel-sw-token-menu", role: "listbox", "aria-label": ariaLabel, children: options.map((sym) => {
138
+ inputRef.current?.focus();
139
+ }, []);
140
+ const filtered = useMemo(() => filterTokenOptions(options, query, assetNames), [options, query, assetNames]);
141
+ return (_jsxs("div", { className: "edel-sw-token-menu", role: "listbox", "aria-label": ariaLabel, "data-testid": testId, children: [_jsxs("div", { className: "edel-sw-token-search", children: [_jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", focusable: "false", children: [_jsx("circle", { cx: "11", cy: "11", r: "7", stroke: "currentColor", strokeWidth: "2" }), _jsx("path", { d: "M20 20L16.65 16.65", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })] }), _jsx("input", { ref: inputRef, type: "search", placeholder: "Search token...", "aria-label": "Search token", value: query, onChange: (e) => setQuery(e.target.value), onKeyDown: (e) => {
142
+ if (e.key === "Escape") {
143
+ e.stopPropagation();
144
+ onClose();
145
+ }
146
+ } })] }), _jsx("div", { className: "edel-sw-token-list", children: filtered.length === 0 ? (_jsxs("div", { className: "edel-sw-token-empty", children: ["No tokens matching \u201C", query.trim(), "\u201D"] })) : (filtered.map((sym) => {
105
147
  const selected = sym === value;
148
+ const displayName = getTokenDisplayName(sym, assetNames?.[sym]);
106
149
  return (_jsxs("button", { type: "button", role: "option", "aria-selected": selected, className: "edel-sw-token-option", "data-token-option": sym, onClick: () => {
107
- onChange(sym);
108
- setOpen(false);
109
- }, children: [_jsxs("span", { className: "edel-sw-token-option-main", children: [_jsx(TokenLogo, { symbol: sym, size: 20, className: "edel-sw-token-icon" }), _jsx("span", { children: sym })] }), selected && (_jsx("span", { className: "edel-sw-token-check", "aria-hidden": "true", children: "\u2713" }))] }, sym));
110
- }) }))] }));
150
+ onSelect(sym);
151
+ onClose();
152
+ }, children: [_jsx(TokenOnChainLogo, { symbol: sym, size: 28, className: "edel-sw-token-icon", logoUrl: logoUrls?.[sym] }), _jsxs("span", { className: "edel-sw-token-option-text", children: [_jsx("strong", { children: sym }), _jsx("span", { children: displayName })] }), _jsx("span", { className: "edel-sw-token-option-aside", children: "Canton" }), _jsx("span", { className: "edel-sw-token-check", "aria-hidden": "true", children: selected ? (_jsx("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M5 13L9.5 17.5L19 7.5", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round" }) })) : null })] }, sym));
153
+ })) })] }));
111
154
  }
112
155
  export function EdelSwapWidget(props) {
113
- const { integratorId, partnerId, theme = "dark", network = "mainnet", defaultFrom, defaultTo, defaultFromAsset, defaultToAsset, defaultMaxSlippageBps, recipientAddress = "", integratorFeeBps, client: providedClient, initialQuote = null, initialOrder = null, onQuote, onSlippageChange, onSwapComplete, onOrderSubmitted, onError, style, } = props;
156
+ const { integratorId, partnerId, theme = "dark", network = "mainnet", defaultFrom, defaultTo, defaultFromAsset, defaultToAsset, defaultMaxSlippageBps, recipientAddress = "", integratorFeeBps, client: providedClient, initialQuote = null, initialOrder = null, initialLogoUrls, onQuote, onSlippageChange, onSwapComplete, onOrderSubmitted, onError, style, } = props;
114
157
  const effectiveIntegratorId = integratorId ?? partnerId;
115
158
  const client = useMemo(() => providedClient ?? new EdelClient({ network }), [providedClient, network]);
116
159
  const initialSlippage = resolveInitialSlippageBps(defaultMaxSlippageBps);
117
160
  const isInitialPreset = SLIPPAGE_PRESETS_BPS.includes(initialSlippage);
118
161
  const [pairs, setPairs] = useState([]);
162
+ const [logoUrls, setLogoUrls] = useState(() => ({
163
+ ...initialLogoUrls,
164
+ }));
119
165
  const [fromAsset, setFromAsset] = useState(defaultFrom ?? defaultFromAsset ?? "CC");
120
166
  const [toAsset, setToAsset] = useState(defaultTo ?? defaultToAsset ?? "USDCx");
121
167
  const [fromAmount, setFromAmount] = useState("100");
@@ -130,20 +176,60 @@ export function EdelSwapWidget(props) {
130
176
  const [submittingSigned, setSubmittingSigned] = useState(false);
131
177
  const [errorMessage, setErrorMessage] = useState(null);
132
178
  const [remainingSec, setRemainingSec] = useState(initialQuote?.ttlSeconds ?? DEFAULT_WIDGET_QUOTE_TTL_SECONDS);
179
+ const [openPicker, setOpenPicker] = useState(null);
180
+ const [flipCount, setFlipCount] = useState(0);
133
181
  const completedRef = useRef(null);
134
- const assetSymbols = useMemo(() => {
135
- if (pairs.length === 0)
136
- return [...DEFAULT_SWAP_ASSETS];
182
+ const pairRef = useRef(null);
183
+ // Close open token dropdown on outside click or Escape
184
+ useEffect(() => {
185
+ if (!openPicker)
186
+ return;
187
+ const handlePointerDown = (event) => {
188
+ const container = pairRef.current;
189
+ if (!container)
190
+ return;
191
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
192
+ if (path.length > 0 ? !path.includes(container) : !container.contains(event.target)) {
193
+ setOpenPicker(null);
194
+ }
195
+ };
196
+ const handleKeyDown = (event) => {
197
+ if (event.key === "Escape") {
198
+ setOpenPicker(null);
199
+ }
200
+ };
201
+ document.addEventListener("pointerdown", handlePointerDown);
202
+ document.addEventListener("keydown", handleKeyDown);
203
+ return () => {
204
+ document.removeEventListener("pointerdown", handlePointerDown);
205
+ document.removeEventListener("keydown", handleKeyDown);
206
+ };
207
+ }, [openPicker]);
208
+ const { assetSymbols, assetNames } = useMemo(() => {
209
+ if (pairs.length === 0) {
210
+ return {
211
+ assetSymbols: [...DEFAULT_SWAP_ASSETS],
212
+ assetNames: {},
213
+ };
214
+ }
137
215
  const set = new Set();
216
+ const names = {};
138
217
  for (const pair of pairs) {
139
218
  if (pair.active) {
140
219
  set.add(pair.fromAsset.symbol);
141
220
  set.add(pair.toAsset.symbol);
221
+ if (pair.fromAsset.name)
222
+ names[pair.fromAsset.symbol] = pair.fromAsset.name;
223
+ if (pair.toAsset.name)
224
+ names[pair.toAsset.symbol] = pair.toAsset.name;
142
225
  }
143
226
  }
144
- return set.size > 0 ? Array.from(set) : [...DEFAULT_SWAP_ASSETS];
227
+ return {
228
+ assetSymbols: set.size > 0 ? Array.from(set) : [...DEFAULT_SWAP_ASSETS],
229
+ assetNames: names,
230
+ };
145
231
  }, [pairs]);
146
- // Hydrate tradable swap pairs from @edel-finance/sdk
232
+ // Hydrate tradable swap pairs and official token logos from @edel-finance/sdk
147
233
  useEffect(() => {
148
234
  let active = true;
149
235
  client
@@ -156,6 +242,19 @@ export function EdelSwapWidget(props) {
156
242
  .catch(() => {
157
243
  // Fallback to DEFAULT_SWAP_ASSETS if endpoint is unreachable during offline preview
158
244
  });
245
+ if (typeof client.getMarkets === "function") {
246
+ client
247
+ .getMarkets()
248
+ .catch(() => [])
249
+ .then((markets) => {
250
+ if (!active || !Array.isArray(markets))
251
+ return;
252
+ const next = extractMarketLogoUrls(markets);
253
+ if (Object.keys(next).length > 0) {
254
+ setLogoUrls((prev) => ({ ...prev, ...next }));
255
+ }
256
+ });
257
+ }
159
258
  return () => {
160
259
  active = false;
161
260
  };
@@ -263,8 +362,24 @@ export function EdelSwapWidget(props) {
263
362
  };
264
363
  }, [client, activeOrderId, activeOrderStatus, onSwapComplete]);
265
364
  const handleFlip = () => {
266
- setFromAsset(toAsset);
267
- setToAsset(fromAsset);
365
+ const prevFrom = fromAsset;
366
+ const prevTo = toAsset;
367
+ setFromAsset(prevTo);
368
+ setToAsset(prevFrom);
369
+ setFlipCount((c) => c + 1);
370
+ setOpenPicker(null);
371
+ };
372
+ const handleSelectFromAsset = (next) => {
373
+ if (next === toAsset) {
374
+ setToAsset(fromAsset);
375
+ }
376
+ setFromAsset(next);
377
+ };
378
+ const handleSelectToAsset = (next) => {
379
+ if (next === fromAsset) {
380
+ setFromAsset(toAsset);
381
+ }
382
+ setToAsset(next);
268
383
  };
269
384
  const handleSelectPreset = (bps) => {
270
385
  setCustomMode(false);
@@ -338,13 +453,21 @@ export function EdelSwapWidget(props) {
338
453
  const ttlPercent = quote && effectiveTtlSeconds > 0
339
454
  ? Math.max(0, Math.min(100, (remainingSec / effectiveTtlSeconds) * 100))
340
455
  : 0;
456
+ const parsedFromAmount = Number(fromAmount);
457
+ const hasPositiveAmount = Number.isFinite(parsedFromAmount) && parsedFromAmount > 0;
341
458
  const canSubmitOrder = order !== null && (order.status === "quoted" || order.status === "awaiting_lock");
342
- return (_jsxs("div", { className: "edel-sw-root", "data-edel-theme": theme, "data-edel-network": network, "data-max-slippage-bps": maxSlippageBps, style: style, children: [_jsx("style", { children: getIsolatedWidgetCss(theme) }), _jsxs("div", { className: "edel-sw-header", children: [_jsxs("span", { className: "edel-sw-brand", children: [_jsx(EdelBrandMark, { size: 22, className: "edel-sw-brand-mark" }), _jsx("span", { className: "edel-sw-title", children: "Edel Swap" })] }), _jsx("span", { className: "edel-sw-badge", children: network === "mainnet" ? "MainNet" : "TestNet" })] }), _jsxs("div", { className: "edel-sw-box", children: [_jsx("div", { className: "edel-sw-label", children: "You pay" }), _jsxs("div", { className: "edel-sw-row", children: [_jsx("input", { "aria-label": "From amount", className: "edel-sw-input", inputMode: "decimal", value: fromAmount, onChange: (e) => setFromAmount(e.target.value), placeholder: "0.00" }), _jsx(TokenSelector, { ariaLabel: "From asset", testId: "from-asset-selector", value: fromAsset, options: assetSymbols, onChange: setFromAsset })] })] }), _jsx("div", { className: "edel-sw-flip-wrap", children: _jsx("button", { type: "button", className: "edel-sw-flip", "aria-label": "Flip swap pair", onClick: handleFlip, children: "\u2195" }) }), _jsxs("div", { className: "edel-sw-box", children: [_jsx("div", { className: "edel-sw-label", children: "You receive" }), _jsxs("div", { className: "edel-sw-row", children: [_jsx("input", { "aria-label": "To amount", className: "edel-sw-input", readOnly: true, value: loadingQuote ? "..." : (quote?.toAmount ?? "0.00") }), _jsx(TokenSelector, { ariaLabel: "To asset", testId: "to-asset-selector", value: toAsset, options: assetSymbols, onChange: setToAsset })] })] }), _jsxs("div", { className: "edel-sw-slippage", "data-testid": "slippage-selector", children: [_jsxs("div", { className: "edel-sw-slippage-header", children: [_jsx("span", { children: "Max slippage" }), _jsx("strong", { children: formatBps(maxSlippageBps) })] }), _jsxs("fieldset", { className: "edel-sw-slippage-pills", "aria-label": "Max slippage presets", children: [SLIPPAGE_PRESETS_BPS.map((bps) => {
459
+ const rail = getSwapRailProgress(quote, order);
460
+ return (_jsxs("div", { className: "edel-sw-root", "data-edel-theme": theme, "data-edel-network": network, "data-max-slippage-bps": maxSlippageBps, style: style, children: [_jsx("style", { children: getIsolatedWidgetCss(theme) }), _jsxs("div", { className: "edel-sw-header", children: [_jsxs("span", { className: "edel-sw-brand", children: [_jsx(EdelBrandMark, { size: 20, className: "edel-sw-brand-mark" }), _jsx("span", { className: "edel-sw-title", children: "Edel Swap" })] }), _jsx("span", { className: "edel-sw-badge", children: network === "mainnet" ? "MainNet" : "TestNet" })] }), _jsx("ol", { className: "edel-sw-rail", "aria-label": "Swap steps", "data-testid": "swap-step-rail", children: SWAP_RAIL_STEPS.map((label, idx) => {
461
+ const state = rail.complete || idx < rail.index ? "done" : idx === rail.index ? "current" : "next";
462
+ return (_jsx("li", { className: "edel-sw-rail-step", "data-state": state, "aria-current": state === "current" ? "step" : undefined, children: _jsxs("span", { className: "edel-sw-rail-inner", children: [_jsx("span", { className: "edel-sw-rail-marker", "aria-hidden": "true", children: state === "done" ? (_jsx("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M5 13L9.5 17.5L19 7.5", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round" }) })) : (idx + 1) }), _jsx("span", { className: "edel-sw-rail-label", children: label })] }) }, label));
463
+ }) }), _jsxs("div", { className: "edel-sw-pair", ref: pairRef, children: [_jsxs("div", { className: "edel-sw-box-wrap", children: [_jsxs("div", { className: "edel-sw-box", "data-pay": "true", children: [_jsxs("div", { className: "edel-sw-label", children: [_jsx("span", { children: "You send" }), _jsx("span", { className: "edel-sw-label-meta", children: "Canton Network" })] }), _jsxs("div", { className: "edel-sw-row", children: [_jsx("input", { "aria-label": "From amount", className: "edel-sw-input", inputMode: "decimal", value: fromAmount, onChange: (e) => setFromAmount(e.target.value), placeholder: "0" }), _jsx(TokenPickerButton, { ariaLabel: "From asset", testId: "from-asset-selector", value: fromAsset, open: openPicker === "from", logoUrls: logoUrls, onToggle: () => setOpenPicker((prev) => (prev === "from" ? null : "from")) })] }), _jsx("div", { className: "edel-sw-box-sub", children: _jsx("span", { children: getTokenDisplayName(fromAsset, assetNames[fromAsset]) }) })] }), openPicker === "from" && (_jsx(TokenDropdown, { ariaLabel: "Select token to send", testId: "from-asset-dropdown", value: fromAsset, options: assetSymbols, assetNames: assetNames, logoUrls: logoUrls, onSelect: handleSelectFromAsset, onClose: () => setOpenPicker(null) }))] }), _jsx("button", { type: "button", className: "edel-sw-flip", "aria-label": "Flip swap pair", "data-testid": "flip-pair-btn", "data-flip-count": flipCount, onClick: handleFlip, children: _jsx("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: "edel-sw-flip-icon", style: { transform: `rotate(${flipCount * 180}deg)` }, "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M7 4V20M7 4L3.5 7.5M7 4L10.5 7.5M17 20V4M17 20L13.5 16.5M17 20L20.5 16.5", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) }), _jsxs("div", { className: "edel-sw-box-wrap", children: [_jsxs("div", { className: "edel-sw-box", children: [_jsxs("div", { className: "edel-sw-label", children: [_jsx("span", { children: "You receive" }), quote?.estimatedSeconds !== undefined && (_jsxs("span", { className: "edel-sw-label-meta", children: ["~", quote.estimatedSeconds, "s"] }))] }), _jsxs("div", { className: "edel-sw-row", children: [_jsx("input", { "aria-label": "To amount", className: "edel-sw-input", "data-empty": !quote && !loadingQuote ? "true" : undefined, readOnly: true, value: loadingQuote ? "..." : (quote?.toAmount ?? "0") }), _jsx(TokenPickerButton, { ariaLabel: "To asset", testId: "to-asset-selector", value: toAsset, open: openPicker === "to", logoUrls: logoUrls, onToggle: () => setOpenPicker((prev) => (prev === "to" ? null : "to")) })] }), _jsx("div", { className: "edel-sw-box-sub", children: _jsx("span", { children: getTokenDisplayName(toAsset, assetNames[toAsset]) }) })] }), openPicker === "to" && (_jsx(TokenDropdown, { ariaLabel: "Select token to receive", testId: "to-asset-dropdown", value: toAsset, options: assetSymbols, assetNames: assetNames, logoUrls: logoUrls, onSelect: handleSelectToAsset, onClose: () => setOpenPicker(null) }))] })] }), _jsxs("div", { className: "edel-sw-slippage", "data-testid": "slippage-selector", children: [_jsxs("div", { className: "edel-sw-slippage-header", children: [_jsx("span", { children: "Max slippage" }), _jsx("strong", { children: formatBps(maxSlippageBps) })] }), _jsxs("fieldset", { className: "edel-sw-slippage-pills", "aria-label": "Max slippage presets", children: [SLIPPAGE_PRESETS_BPS.map((bps) => {
343
464
  const isActive = !customMode && maxSlippageBps === bps;
344
465
  return (_jsx("button", { type: "button", className: "edel-sw-pill", "data-slippage-bps": bps, "data-active": isActive ? "true" : "false", "aria-pressed": isActive, onClick: () => handleSelectPreset(bps), children: formatPresetPercent(bps) }, bps));
345
- }), _jsxs("div", { className: "edel-sw-custom-wrap", "data-active": customMode ? "true" : "false", children: [_jsx("input", { "aria-label": "Custom slippage percent", className: "edel-sw-custom-input", inputMode: "decimal", placeholder: "Custom", value: customSlippageInput, onFocus: () => setCustomMode(true), onChange: (e) => handleCustomSlippageChange(e.target.value) }), _jsx("span", { className: "edel-sw-custom-suffix", children: "%" })] })] })] }), quote && (_jsxs("div", { className: "edel-sw-fees", "data-testid": "quote-fee-breakdown", "data-min-amount-out-atoms": quote.minAmountOutAtoms, children: [_jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Rate" }), _jsxs("strong", { children: ["1 ", quote.fromAsset, " = ", quote.rate, " ", quote.toAsset] })] }), _jsxs("div", { className: "edel-sw-fee-line", children: [_jsxs("span", { children: ["Edel RFQ fee (", formatBps(quote.fees.edelRfqFeeBps), ")"] }), _jsxs("strong", { children: [quote.fees.edelRfqFeeAmount, " ", quote.toAsset] })] }), _jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Network fee" }), _jsxs("strong", { children: [quote.fees.networkFeeAmount, " ", quote.fees.networkFeeAsset] })] }), _jsxs("div", { className: "edel-sw-fee-line", children: [_jsxs("span", { children: ["Integrator markup (", formatBps(quote.fees.integratorFeeBps), ")"] }), _jsxs("strong", { children: [quote.fees.integratorFeeAmount, " ", quote.toAsset] })] }), _jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Price impact" }), _jsx("strong", { children: formatBps(quote.priceImpactBps) })] }), _jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Min received" }), _jsxs("strong", { children: [quote.minReceived, " ", quote.toAsset] })] }), quote.minAmountOutAtoms !== undefined && (_jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Min output (atoms)" }), _jsx("strong", { children: quote.minAmountOutAtoms })] })), quote.estimatedSeconds !== undefined && (_jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Estimated settlement" }), _jsxs("strong", { children: ["~", quote.estimatedSeconds, "s"] })] })), _jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Quote expires in" }), _jsxs("strong", { children: [remainingSec, "s"] })] }), _jsx("div", { className: "edel-sw-ttl-bar", children: _jsx("div", { className: "edel-sw-ttl-fill", style: { width: `${ttlPercent}%` } }) })] })), order && (_jsxs("div", { className: "edel-sw-tracker", "data-testid": "swap-status-tracker", children: [_jsxs("div", { className: "edel-sw-fee-line", children: [_jsxs("span", { children: ["Order ", order.swapId ?? order.orderId] }), _jsx("strong", { children: order.status })] }), _jsx("div", { className: "edel-sw-steps", children: SWAP_STATUS_STEPS.map((step) => (_jsx("div", { className: "edel-sw-step", "data-status": step.status, "data-state": getStepState(step.status, order.status), children: step.label }, step.status))) }), canSubmitOrder && (_jsx("button", { type: "button", className: "edel-sw-submit-btn", "data-testid": "submit-swap-order-btn", disabled: submittingSigned, onClick: handleSubmitOrder, children: submittingSigned ? "Submitting swap..." : "Submit Swap Order" }))] })), errorMessage && (_jsx("div", { className: "edel-sw-error", role: "alert", children: errorMessage })), _jsx("button", { type: "button", className: "edel-sw-cta", disabled: !quote || submitting || remainingSec === 0, onClick: handleSwap, children: submitting
346
- ? "Executing swap..."
347
- : loadingQuote
348
- ? "Fetching live quote..."
349
- : `Swap ${fromAsset} to ${toAsset}` })] }));
466
+ }), _jsxs("div", { className: "edel-sw-custom-wrap", "data-active": customMode ? "true" : "false", children: [_jsx("input", { "aria-label": "Custom slippage percent", className: "edel-sw-custom-input", inputMode: "decimal", placeholder: "Custom", value: customSlippageInput, onFocus: () => setCustomMode(true), onChange: (e) => handleCustomSlippageChange(e.target.value) }), _jsx("span", { className: "edel-sw-custom-suffix", children: "%" })] })] })] }), quote && (_jsxs("div", { className: "edel-sw-fees", "data-testid": "quote-fee-breakdown", "data-min-amount-out-atoms": quote.minAmountOutAtoms, children: [_jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Rate" }), _jsxs("strong", { children: ["1 ", quote.fromAsset, " = ", quote.rate, " ", quote.toAsset] })] }), _jsxs("div", { className: "edel-sw-fee-line", children: [_jsxs("span", { children: ["Edel RFQ fee (", formatBps(quote.fees.edelRfqFeeBps), ")"] }), _jsxs("strong", { children: [quote.fees.edelRfqFeeAmount, " ", quote.toAsset] })] }), _jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Network fee" }), _jsxs("strong", { children: [quote.fees.networkFeeAmount, " ", quote.fees.networkFeeAsset] })] }), _jsxs("div", { className: "edel-sw-fee-line", children: [_jsxs("span", { children: ["Integrator markup (", formatBps(quote.fees.integratorFeeBps), ")"] }), _jsxs("strong", { children: [quote.fees.integratorFeeAmount, " ", quote.toAsset] })] }), _jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Price impact" }), _jsx("strong", { children: formatBps(quote.priceImpactBps) })] }), _jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Min received" }), _jsxs("strong", { children: [quote.minReceived, " ", quote.toAsset] })] }), quote.minAmountOutAtoms !== undefined && (_jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Min output (atoms)" }), _jsx("strong", { children: quote.minAmountOutAtoms })] })), quote.estimatedSeconds !== undefined && (_jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Estimated settlement" }), _jsxs("strong", { children: ["~", quote.estimatedSeconds, "s"] })] })), _jsxs("div", { className: "edel-sw-fee-line", children: [_jsx("span", { children: "Quote expires in" }), _jsxs("strong", { children: [remainingSec, "s"] })] }), _jsx("div", { className: "edel-sw-ttl-bar", children: _jsx("div", { className: "edel-sw-ttl-fill", style: { width: `${ttlPercent}%` } }) })] })), order && (_jsxs("div", { className: "edel-sw-tracker", "data-testid": "swap-status-tracker", children: [_jsxs("div", { className: "edel-sw-fee-line", children: [_jsxs("span", { children: ["Order ", order.swapId ?? order.orderId] }), _jsx("strong", { children: order.status })] }), _jsx("div", { className: "edel-sw-steps", children: SWAP_STATUS_STEPS.map((step) => (_jsx("div", { className: "edel-sw-step", "data-status": step.status, "data-state": getStepState(step.status, order.status), children: step.label }, step.status))) }), canSubmitOrder && (_jsx("button", { type: "button", className: "edel-sw-submit-btn", "data-testid": "submit-swap-order-btn", disabled: submittingSigned, onClick: handleSubmitOrder, children: submittingSigned ? "Submitting swap..." : "Submit Swap Order" }))] })), errorMessage && (_jsx("div", { className: "edel-sw-error", role: "alert", children: errorMessage })), _jsx("button", { type: "button", className: "edel-sw-cta", disabled: !hasPositiveAmount || !quote || submitting || remainingSec === 0, onClick: handleSwap, children: !hasPositiveAmount
467
+ ? "Enter an amount"
468
+ : submitting
469
+ ? "Executing swap..."
470
+ : loadingQuote
471
+ ? "Fetching live quote..."
472
+ : `Swap ${fromAsset} to ${toAsset}` })] }));
350
473
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edel-finance/swap-widget",
3
- "version": "0.1.5-alpha",
3
+ "version": "0.1.7-alpha",
4
4
  "description": "Embeddable React, Vue 3, Svelte 5, Angular, SolidJS, Shadow DOM Web Component, and iframe Swap Widget for Edel Markets.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -32,7 +32,7 @@
32
32
  "README.md"
33
33
  ],
34
34
  "dependencies": {
35
- "@edel-finance/sdk": "0.1.5-alpha"
35
+ "@edel-finance/sdk": "0.1.7-alpha"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "react": ">=18.2.0",