@edel-finance/swap-widget 0.1.5-alpha → 0.1.6-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/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/logos.d.ts +10 -3
- package/dist/logos.js +33 -4
- package/dist/widget.d.ts +8 -1
- package/dist/widget.js +49 -7
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { buildSwapWidgetEmbedSnippet, buildSwapWidgetUrl, EDEL_SWAP_WIDGET_EVENTS, EDEL_SWAP_WIDGET_TAG, type EdelSwapWidgetElement, type EdelSwapWidgetErrorDetail, type EdelSwapWidgetEventMap, type EdelSwapWidgetSlippageDetail, type MountEdelSwapWidgetOptions, type MountedEdelSwapWidget, mountEdelSwapWidget, registerEdelSwapWidgetElement, SWAP_WIDGET_ORIGINS, type SwapWidgetEmbedOptions, type WidgetRootLike, } from "./embed.js";
|
|
2
|
-
export { EdelBrandMark, type EdelBrandMarkProps, getTokenMonogram, KNOWN_TOKEN_LOGO_SYMBOLS, type KnownTokenLogoSymbol, TokenLogo, type TokenLogoProps, } from "./logos.js";
|
|
2
|
+
export { EdelBrandMark, type EdelBrandMarkProps, getTokenMonogram, isValidHttpsLogoUrl, KNOWN_TOKEN_LOGO_SYMBOLS, type KnownTokenLogoSymbol, TokenLogo, type TokenLogoProps, } from "./logos.js";
|
|
3
3
|
export { ALPINE_FOREST_THEMES, type AlpineThemeTokens, getIsolatedWidgetCss, type SwapWidgetTheme, } from "./theme.js";
|
|
4
|
-
export { DEFAULT_SWAP_ASSETS, DEFAULT_WIDGET_QUOTE_TTL_SECONDS, DEFAULT_WIDGET_SLIPPAGE_BPS, EdelSwapWidget, type EdelSwapWidgetProps, formatBps, formatPresetPercent, getStepState, parseCustomSlippagePercent, resolveInitialSlippageBps, SLIPPAGE_PRESETS_BPS, SWAP_STATUS_STEPS, } from "./widget.js";
|
|
4
|
+
export { DEFAULT_SWAP_ASSETS, DEFAULT_WIDGET_QUOTE_TTL_SECONDS, DEFAULT_WIDGET_SLIPPAGE_BPS, EdelSwapWidget, type EdelSwapWidgetProps, extractMarketLogoUrls, formatBps, formatPresetPercent, getStepState, parseCustomSlippagePercent, resolveInitialSlippageBps, SLIPPAGE_PRESETS_BPS, SWAP_STATUS_STEPS, } from "./widget.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { buildSwapWidgetEmbedSnippet, buildSwapWidgetUrl, EDEL_SWAP_WIDGET_EVENTS, EDEL_SWAP_WIDGET_TAG, mountEdelSwapWidget, registerEdelSwapWidgetElement, SWAP_WIDGET_ORIGINS, } from "./embed.js";
|
|
2
|
-
export { EdelBrandMark, getTokenMonogram, KNOWN_TOKEN_LOGO_SYMBOLS, TokenLogo, } from "./logos.js";
|
|
2
|
+
export { EdelBrandMark, getTokenMonogram, isValidHttpsLogoUrl, KNOWN_TOKEN_LOGO_SYMBOLS, TokenLogo, } from "./logos.js";
|
|
3
3
|
export { ALPINE_FOREST_THEMES, getIsolatedWidgetCss, } from "./theme.js";
|
|
4
|
-
export { DEFAULT_SWAP_ASSETS, DEFAULT_WIDGET_QUOTE_TTL_SECONDS, DEFAULT_WIDGET_SLIPPAGE_BPS, EdelSwapWidget, formatBps, formatPresetPercent, getStepState, parseCustomSlippagePercent, resolveInitialSlippageBps, SLIPPAGE_PRESETS_BPS, SWAP_STATUS_STEPS, } from "./widget.js";
|
|
4
|
+
export { DEFAULT_SWAP_ASSETS, DEFAULT_WIDGET_QUOTE_TTL_SECONDS, DEFAULT_WIDGET_SLIPPAGE_BPS, EdelSwapWidget, extractMarketLogoUrls, formatBps, formatPresetPercent, getStepState, parseCustomSlippagePercent, resolveInitialSlippageBps, SLIPPAGE_PRESETS_BPS, SWAP_STATUS_STEPS, } from "./widget.js";
|
package/dist/logos.d.ts
CHANGED
|
@@ -17,9 +17,16 @@ export interface TokenLogoProps {
|
|
|
17
17
|
symbol: string;
|
|
18
18
|
size?: number;
|
|
19
19
|
className?: string;
|
|
20
|
+
/** Optional HTTPS token logo URL from Edel Markets API; falls back to inline SVG on error. */
|
|
21
|
+
logoUrl?: string | null;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
23
|
-
* Renders offline and inside Shadow DOM with zero external image requests.
|
|
24
|
+
* Validate that a remote token logo URL uses the HTTPS protocol.
|
|
24
25
|
*/
|
|
25
|
-
export declare function
|
|
26
|
+
export declare function isValidHttpsLogoUrl(url: unknown): url is string;
|
|
27
|
+
/**
|
|
28
|
+
* Circular token logo for Edel Markets assets.
|
|
29
|
+
* Renders the official remote HTTPS logo when provided and falls back to the
|
|
30
|
+
* self-contained inline SVG on load error or when no logoUrl is available.
|
|
31
|
+
*/
|
|
32
|
+
export declare function TokenLogo({ symbol, size, className, logoUrl }: TokenLogoProps): import("react").JSX.Element;
|
package/dist/logos.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useId } from "react";
|
|
2
|
+
import { useId, useState } from "react";
|
|
3
3
|
export const KNOWN_TOKEN_LOGO_SYMBOLS = [
|
|
4
4
|
"USDCx",
|
|
5
5
|
"CC",
|
|
@@ -31,11 +31,40 @@ export function EdelBrandMark({ size = 22, className }) {
|
|
|
31
31
|
return (_jsxs("svg", { width: size, height: Math.round((size * 69) / 78), viewBox: "0 0 78 69", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: className, "aria-hidden": "true", focusable: "false", "data-edel-brand-mark": "true", children: [_jsx("path", { d: "M21.1645 7.51419C21.9479 8.67468 22.9488 9.80616 24.1093 10.8796C25.2843 11.9386 26.6334 12.925 28.1275 13.7954L38.9201 20.091C38.9926 20.1345 39.0796 20.1781 39.1522 20.2216C39.2247 20.2651 39.3117 20.2941 39.3843 20.3231C39.4568 20.3521 39.5438 20.3811 39.6164 20.3957C39.6889 20.4102 39.7759 20.4392 39.8485 20.4537C40.2546 20.5262 40.6318 20.4972 40.9509 20.3811C41.2701 20.2651 41.5312 20.062 41.7052 19.8154C41.8793 19.5688 41.9664 19.2642 41.9373 18.945C41.9083 18.6259 41.7633 18.2632 41.4876 17.9151L34.8438 9.51604C34.075 8.54413 33.1901 7.63024 32.2182 6.78888C31.2463 5.94753 30.1874 5.1787 29.0414 4.4679C27.8954 3.7716 26.6624 3.13333 25.3713 2.5821C24.0658 2.03087 22.6732 1.55216 21.2371 1.175C21.063 1.13148 20.8889 1.08797 20.7003 1.04445C20.5263 1.00093 20.3377 0.95741 20.1636 0.913892C19.9895 0.870373 19.801 0.826855 19.6269 0.797842C19.4383 0.754324 19.2642 0.725312 19.0756 0.681793C18.9741 1.76975 19.1047 2.88673 19.4528 4.03271C19.801 5.19321 20.3812 6.38271 21.15 7.5287", fill: "currentColor" }), _jsx("path", { d: "M52.0916 22.4555C52.3962 22.6731 52.7298 22.8327 53.0925 22.9052C53.1505 22.9052 53.223 22.9197 53.2811 22.9342C53.3391 22.9342 53.4116 22.9342 53.4696 22.9342C53.5277 22.9342 53.6002 22.9342 53.6582 22.9197C53.7163 22.9052 53.7888 22.9052 53.8468 22.8762L61.6076 20.8018C62.565 20.5407 63.3773 20.1635 64.0591 19.6558C64.7264 19.1626 65.2631 18.5824 65.6548 17.9006C66.0465 17.2478 66.2931 16.508 66.4091 15.7102C66.5252 14.9268 66.5107 14.0855 66.3656 13.2151C66.2496 13.1716 66.148 13.1426 66.032 13.0991C65.9159 13.0555 65.8144 13.0265 65.6983 12.983C65.5823 12.954 65.4807 12.9105 65.3647 12.8815C65.2486 12.8524 65.1471 12.8234 65.0311 12.7944C64.1462 12.5623 63.2903 12.4173 62.4635 12.3737C61.6221 12.3302 60.8243 12.3737 60.0699 12.5043C59.3011 12.6494 58.5903 12.896 57.923 13.2296C57.2558 13.5778 56.6465 14.042 56.1388 14.6077L51.3082 19.8734C51.0906 20.1055 51.0036 20.3956 51.0036 20.7003C51.0036 21.0049 51.1197 21.324 51.3082 21.6287C51.4968 21.9333 51.7579 22.2089 52.048 22.4265", fill: "currentColor" }), _jsx("path", { d: "M71.6314 30.4194C70.5144 29.6651 69.354 29.0413 68.179 28.5481C67.004 28.0549 65.7999 27.6922 64.6104 27.5037C64.6104 27.5037 64.5814 27.5037 64.5669 27.5037H64.5379C64.5379 27.5037 64.5089 27.5037 64.4944 27.5037H64.4654L54.9493 25.995C54.4561 25.9225 54.079 26.0095 53.8034 26.2271C53.5277 26.4447 53.3537 26.7638 53.3102 27.141C53.2666 27.5182 53.3392 27.9388 53.5568 28.3595C53.7743 28.7657 54.108 29.1574 54.6012 29.462L64.5524 35.5546C65.1617 35.9317 65.7564 36.2509 66.3657 36.5555C66.9604 36.8456 67.5697 37.1067 68.1645 37.3098C68.7592 37.5274 69.3395 37.7015 69.9052 37.832C70.4709 37.9626 71.0367 38.0641 71.5734 38.1222C72.2262 38.1947 72.8499 38.2092 73.4592 38.1657C74.054 38.1222 74.6197 38.0351 75.1564 37.8756C75.6931 37.7305 76.1863 37.5274 76.6505 37.2808C77.1147 37.0342 77.5209 36.7441 77.9126 36.3959C76.9552 35.1774 75.9397 34.0604 74.8808 33.0595C73.8364 32.0731 72.7339 31.2027 71.6169 30.4484", fill: "currentColor" }), _jsx("path", { d: "M38.891 27.0975C39.4422 26.9379 39.8049 26.6188 40.008 26.2416C40.2111 25.8645 40.2401 25.4293 40.1385 24.9941C40.037 24.5589 39.7904 24.1382 39.4277 23.8046C39.0651 23.471 38.5864 23.2098 37.9916 23.0938L24.791 20.7293C24.791 20.7293 24.7475 20.7293 24.7185 20.7293C24.6895 20.7293 24.675 20.7293 24.646 20.7293C24.6169 20.7293 24.6024 20.7293 24.5734 20.7293C24.5444 20.7293 24.5299 20.7293 24.5009 20.7293C22.5861 20.4102 20.6132 20.2796 18.6404 20.3376C16.6095 20.3957 14.5497 20.6568 12.5188 21.121C10.4009 21.5997 8.29752 22.296 6.23764 23.2098C4.09073 24.1527 2.00185 25.3422 0 26.7784C1.00092 27.5037 2.07438 28.1564 3.20586 28.7512C4.33734 29.3314 5.51234 29.8537 6.73085 30.2888C7.93486 30.724 9.18239 31.0867 10.4589 31.3768C11.7065 31.6669 12.983 31.87 14.2595 32.0006C15.2895 32.1021 16.3194 32.1746 17.3494 32.1746C18.3648 32.1746 19.3802 32.1456 20.3666 32.0586C21.3531 31.9716 22.325 31.841 23.2679 31.6524C24.2108 31.4784 25.1247 31.2463 26.0095 30.9851L38.891 27.1265V27.0975Z", fill: "currentColor" }), _jsx("path", { d: "M44.8675 30.724C44.6499 30.4629 44.3743 30.2453 44.0697 30.0712C43.7651 29.9117 43.4459 29.7956 43.1123 29.7521C42.9527 29.7376 42.8076 29.7231 42.6481 29.7376C42.4885 29.7376 42.3435 29.7811 42.1984 29.8246C42.0533 29.8682 41.9083 29.9407 41.7777 30.0132C41.6472 30.1003 41.5021 30.2018 41.386 30.3324L32.2037 39.7759C30.7385 41.2845 29.433 43.0252 28.345 44.9401C27.199 46.9564 26.2561 49.1613 25.5743 51.5403C24.849 54.0209 24.4139 56.661 24.2688 59.3882C24.1237 62.2314 24.3123 65.1616 24.878 68.0919C27.5472 66.8588 29.9842 65.3357 32.1456 63.5805C34.2055 61.9123 36.0188 60.041 37.5564 58.0536C39.0215 56.1533 40.2256 54.1224 41.1539 52.0481C42.0533 50.0462 42.6916 47.9863 43.0688 45.8975L45.4623 32.6969C45.5348 32.3197 45.5058 31.957 45.3897 31.6234C45.2882 31.2898 45.1141 30.9851 44.882 30.724", fill: "currentColor" }), _jsx("path", { d: "M66.5687 52.0336C65.9305 50.1333 65.1471 48.32 64.2187 46.6228C63.3049 44.9546 62.2604 43.3879 61.0854 41.9518L52.7734 31.841C52.6428 31.696 52.5268 31.5654 52.3962 31.4493C52.2657 31.3333 52.1206 31.2318 51.9901 31.1592C51.845 31.0722 51.7144 31.0142 51.5694 30.9706C51.4243 30.9271 51.2793 30.8836 51.1487 30.8691C50.8441 30.8256 50.5539 30.8691 50.2928 30.9416C50.0317 31.0287 49.7996 31.1737 49.611 31.3768C49.4225 31.5799 49.2919 31.841 49.2339 32.1311C49.1759 32.4358 49.1904 32.7839 49.2919 33.1756L52.991 46.3617C53.5567 48.3635 54.3401 50.3218 55.312 52.2076C56.3129 54.1225 57.5024 55.9357 58.8515 57.5894C60.215 59.2576 61.7237 60.7373 63.3339 61.9848C64.944 63.2323 66.6413 64.2332 68.382 64.9295C68.4836 62.6231 68.353 60.3456 68.0339 58.1552C67.7292 56.0373 67.236 53.9919 66.5832 52.0336", fill: "currentColor" }), _jsx("path", { d: "M49.9301 7.96388C49.8141 7.04999 49.5385 6.1361 49.1468 5.20771C48.7551 4.30833 48.2474 3.40895 47.6091 2.53858C46.9854 1.66821 46.2456 0.826851 45.3897 0C44.5919 0.319135 43.9101 0.739814 43.3443 1.27654C42.7641 1.81327 42.3144 2.45154 41.9953 3.19135C41.6761 3.94567 41.502 4.78703 41.473 5.70092C41.4585 6.64382 41.6036 7.65925 41.9372 8.7182L44.5773 17.2768C44.6499 17.4944 44.7514 17.6975 44.882 17.8861C45.0125 18.0747 45.1721 18.2342 45.3462 18.3793C45.5202 18.5244 45.7088 18.6404 45.9119 18.7274C46.115 18.8145 46.3181 18.887 46.5212 18.9305C46.7243 18.974 46.9273 18.9886 47.1159 18.974C47.3045 18.974 47.4786 18.916 47.6381 18.8435C47.7977 18.771 47.9283 18.6694 48.0443 18.5389C48.1459 18.4083 48.2329 18.2487 48.2764 18.0457L49.8141 10.7055C50.0026 9.82066 50.0172 8.89227 49.9011 7.96388", fill: "currentColor" })] }));
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
* Renders offline and inside Shadow DOM with zero external image requests.
|
|
34
|
+
* Validate that a remote token logo URL uses the HTTPS protocol.
|
|
36
35
|
*/
|
|
37
|
-
export function
|
|
36
|
+
export function isValidHttpsLogoUrl(url) {
|
|
37
|
+
if (typeof url !== "string")
|
|
38
|
+
return false;
|
|
39
|
+
const trimmed = url.trim();
|
|
40
|
+
if (!trimmed)
|
|
41
|
+
return false;
|
|
42
|
+
try {
|
|
43
|
+
return new URL(trimmed).protocol === "https:";
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Circular token logo for Edel Markets assets.
|
|
51
|
+
* Renders the official remote HTTPS logo when provided and falls back to the
|
|
52
|
+
* self-contained inline SVG on load error or when no logoUrl is available.
|
|
53
|
+
*/
|
|
54
|
+
export function TokenLogo({ symbol, size = 22, className, logoUrl }) {
|
|
38
55
|
const clipId = useId();
|
|
56
|
+
const [failedUrl, setFailedUrl] = useState(null);
|
|
57
|
+
const safeLogoUrl = isValidHttpsLogoUrl(logoUrl) ? logoUrl.trim() : null;
|
|
58
|
+
if (safeLogoUrl && failedUrl !== safeLogoUrl) {
|
|
59
|
+
return (_jsx("img", { src: safeLogoUrl, alt: symbol, width: size, height: size, loading: "lazy", referrerPolicy: "no-referrer", className: className, "data-token-logo": symbol, "data-token-logo-src": "remote", style: {
|
|
60
|
+
width: size,
|
|
61
|
+
height: size,
|
|
62
|
+
borderRadius: "9999px",
|
|
63
|
+
objectFit: "cover",
|
|
64
|
+
display: "block",
|
|
65
|
+
flexShrink: 0,
|
|
66
|
+
}, onError: () => setFailedUrl(safeLogoUrl) }));
|
|
67
|
+
}
|
|
39
68
|
const normalized = symbol.trim().toUpperCase();
|
|
40
69
|
if (normalized === "USDCX" || normalized === "USDC" || normalized === "USD.E") {
|
|
41
70
|
return (_jsx("svg", { width: size, height: size, viewBox: "0 0 32 32", xmlns: "http://www.w3.org/2000/svg", className: className, "aria-hidden": "true", focusable: "false", "data-token-logo": symbol, children: _jsxs("g", { fill: "none", children: [_jsx("circle", { fill: "#3E73C4", cx: "16", cy: "16", r: "16" }), _jsxs("g", { fill: "#FFFFFF", children: [_jsx("path", { d: "M20.022 18.124c0-2.124-1.28-2.852-3.84-3.156-1.828-.243-2.193-.728-2.193-1.578 0-.85.61-1.396 1.828-1.396 1.097 0 1.707.364 2.011 1.275a.458.458 0 00.427.303h.975a.416.416 0 00.427-.425v-.06a3.04 3.04 0 00-2.743-2.489V9.142c0-.243-.183-.425-.487-.486h-.915c-.243 0-.426.182-.487.486v1.396c-1.829.242-2.986 1.456-2.986 2.974 0 2.002 1.218 2.791 3.778 3.095 1.707.303 2.255.668 2.255 1.639 0 .97-.853 1.638-2.011 1.638-1.585 0-2.133-.667-2.316-1.578-.06-.242-.244-.364-.427-.364h-1.036a.416.416 0 00-.426.425v.06c.243 1.518 1.219 2.61 3.23 2.914v1.457c0 .242.183.425.487.485h.915c.243 0 .426-.182.487-.485V21.34c1.829-.303 3.047-1.578 3.047-3.217z" }), _jsx("path", { d: "M12.892 24.497c-4.754-1.7-7.192-6.98-5.424-11.653.914-2.55 2.925-4.491 5.424-5.402.244-.121.365-.303.365-.607v-.85c0-.242-.121-.424-.365-.485-.061 0-.183 0-.244.06a10.895 10.895 0 00-7.13 13.717c1.096 3.4 3.717 6.01 7.13 7.102.244.121.488 0 .548-.243.061-.06.061-.122.061-.243v-.85c0-.182-.182-.424-.365-.546zm6.46-18.936c-.244-.122-.488 0-.548.242-.061.061-.061.122-.061.243v.85c0 .243.182.485.365.607 4.754 1.7 7.192 6.98 5.424 11.653-.914 2.55-2.925 4.491-5.424 5.402-.244.121-.365.303-.365.607v.85c0 .242.121.424.365.485.061 0 .183 0 .244-.06a10.895 10.895 0 007.13-13.717c-1.096-3.46-3.778-6.07-7.13-7.162z" })] })] }) }));
|
package/dist/widget.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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<{
|
|
@@ -50,6 +50,8 @@ export interface EdelSwapWidgetProps {
|
|
|
50
50
|
initialQuote?: SwapQuote | null;
|
|
51
51
|
/** Optional initial active order (useful for SSR preview or testing). */
|
|
52
52
|
initialOrder?: SwapOrder | null;
|
|
53
|
+
/** Optional initial baseAsset -> HTTPS logoUrl map (useful for SSR preview or testing). */
|
|
54
|
+
initialLogoUrls?: Readonly<Record<string, string>>;
|
|
53
55
|
/** Callback fired whenever a live quote is fetched. */
|
|
54
56
|
onQuote?: (quote: SwapQuote) => void;
|
|
55
57
|
/** Callback fired when the user updates max slippage (in basis points). */
|
|
@@ -66,4 +68,9 @@ export interface EdelSwapWidgetProps {
|
|
|
66
68
|
export declare function getStepState(stepStatus: SwapOrderStatus, currentStatus: SwapOrderStatus): "done" | "active" | "pending";
|
|
67
69
|
export declare function formatBps(bps: number): string;
|
|
68
70
|
export declare function formatPresetPercent(bps: number): string;
|
|
71
|
+
/**
|
|
72
|
+
* Extract a baseAsset -> HTTPS logoUrl map from Edel Markets API summaries.
|
|
73
|
+
* Ignores markets with logoUnavailable === true or non-HTTPS URLs.
|
|
74
|
+
*/
|
|
75
|
+
export declare function extractMarketLogoUrls(markets: readonly MarketSummary[]): Record<string, string>;
|
|
69
76
|
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, isValidHttpsLogoUrl, TokenLogo } from "./logos.js";
|
|
5
5
|
import { getIsolatedWidgetCss } from "./theme.js";
|
|
6
6
|
export const SWAP_STATUS_STEPS = [
|
|
7
7
|
{ status: "quoted", label: "Quoted" },
|
|
@@ -74,7 +74,33 @@ export function formatBps(bps) {
|
|
|
74
74
|
export function formatPresetPercent(bps) {
|
|
75
75
|
return `${(bps / 100).toFixed(1)}%`;
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Extract a baseAsset -> HTTPS logoUrl map from Edel Markets API summaries.
|
|
79
|
+
* Ignores markets with logoUnavailable === true or non-HTTPS URLs.
|
|
80
|
+
*/
|
|
81
|
+
export function extractMarketLogoUrls(markets) {
|
|
82
|
+
const map = {};
|
|
83
|
+
for (const market of markets) {
|
|
84
|
+
const info = market && typeof market.info === "object" && market.info !== null
|
|
85
|
+
? market.info
|
|
86
|
+
: null;
|
|
87
|
+
if (!info || info.logoUnavailable === true)
|
|
88
|
+
continue;
|
|
89
|
+
if (!isValidHttpsLogoUrl(info.logoUrl))
|
|
90
|
+
continue;
|
|
91
|
+
const logoUrl = info.logoUrl.trim();
|
|
92
|
+
const baseAsset = typeof info.baseAsset === "string" ? info.baseAsset.trim() : "";
|
|
93
|
+
const marketBase = typeof market.base === "string" ? market.base.trim() : "";
|
|
94
|
+
if (baseAsset && !(baseAsset in map)) {
|
|
95
|
+
map[baseAsset] = logoUrl;
|
|
96
|
+
}
|
|
97
|
+
if (marketBase && !(marketBase in map)) {
|
|
98
|
+
map[marketBase] = logoUrl;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return map;
|
|
102
|
+
}
|
|
103
|
+
function TokenSelector({ ariaLabel, value, options, logoUrls, onChange, testId, }) {
|
|
78
104
|
const [open, setOpen] = useState(false);
|
|
79
105
|
const containerRef = useRef(null);
|
|
80
106
|
useEffect(() => {
|
|
@@ -101,21 +127,24 @@ function TokenSelector({ ariaLabel, value, options, onChange, testId }) {
|
|
|
101
127
|
document.removeEventListener("keydown", handleKeyDown);
|
|
102
128
|
};
|
|
103
129
|
}, [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) => {
|
|
130
|
+
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", logoUrl: logoUrls?.[value] }), _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) => {
|
|
105
131
|
const selected = sym === value;
|
|
106
132
|
return (_jsxs("button", { type: "button", role: "option", "aria-selected": selected, className: "edel-sw-token-option", "data-token-option": sym, onClick: () => {
|
|
107
133
|
onChange(sym);
|
|
108
134
|
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));
|
|
135
|
+
}, children: [_jsxs("span", { className: "edel-sw-token-option-main", children: [_jsx(TokenLogo, { symbol: sym, size: 20, className: "edel-sw-token-icon", logoUrl: logoUrls?.[sym] }), _jsx("span", { children: sym })] }), selected && (_jsx("span", { className: "edel-sw-token-check", "aria-hidden": "true", children: "\u2713" }))] }, sym));
|
|
110
136
|
}) }))] }));
|
|
111
137
|
}
|
|
112
138
|
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;
|
|
139
|
+
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
140
|
const effectiveIntegratorId = integratorId ?? partnerId;
|
|
115
141
|
const client = useMemo(() => providedClient ?? new EdelClient({ network }), [providedClient, network]);
|
|
116
142
|
const initialSlippage = resolveInitialSlippageBps(defaultMaxSlippageBps);
|
|
117
143
|
const isInitialPreset = SLIPPAGE_PRESETS_BPS.includes(initialSlippage);
|
|
118
144
|
const [pairs, setPairs] = useState([]);
|
|
145
|
+
const [logoUrls, setLogoUrls] = useState(() => ({
|
|
146
|
+
...initialLogoUrls,
|
|
147
|
+
}));
|
|
119
148
|
const [fromAsset, setFromAsset] = useState(defaultFrom ?? defaultFromAsset ?? "CC");
|
|
120
149
|
const [toAsset, setToAsset] = useState(defaultTo ?? defaultToAsset ?? "USDCx");
|
|
121
150
|
const [fromAmount, setFromAmount] = useState("100");
|
|
@@ -143,7 +172,7 @@ export function EdelSwapWidget(props) {
|
|
|
143
172
|
}
|
|
144
173
|
return set.size > 0 ? Array.from(set) : [...DEFAULT_SWAP_ASSETS];
|
|
145
174
|
}, [pairs]);
|
|
146
|
-
// Hydrate tradable swap pairs from @edel-finance/sdk
|
|
175
|
+
// Hydrate tradable swap pairs and official token logos from @edel-finance/sdk
|
|
147
176
|
useEffect(() => {
|
|
148
177
|
let active = true;
|
|
149
178
|
client
|
|
@@ -156,6 +185,19 @@ export function EdelSwapWidget(props) {
|
|
|
156
185
|
.catch(() => {
|
|
157
186
|
// Fallback to DEFAULT_SWAP_ASSETS if endpoint is unreachable during offline preview
|
|
158
187
|
});
|
|
188
|
+
if (typeof client.getMarkets === "function") {
|
|
189
|
+
client
|
|
190
|
+
.getMarkets()
|
|
191
|
+
.catch(() => [])
|
|
192
|
+
.then((markets) => {
|
|
193
|
+
if (!active || !Array.isArray(markets))
|
|
194
|
+
return;
|
|
195
|
+
const next = extractMarketLogoUrls(markets);
|
|
196
|
+
if (Object.keys(next).length > 0) {
|
|
197
|
+
setLogoUrls((prev) => ({ ...prev, ...next }));
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
159
201
|
return () => {
|
|
160
202
|
active = false;
|
|
161
203
|
};
|
|
@@ -339,7 +381,7 @@ export function EdelSwapWidget(props) {
|
|
|
339
381
|
? Math.max(0, Math.min(100, (remainingSec / effectiveTtlSeconds) * 100))
|
|
340
382
|
: 0;
|
|
341
383
|
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) => {
|
|
384
|
+
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, logoUrls: logoUrls, 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, logoUrls: logoUrls, 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) => {
|
|
343
385
|
const isActive = !customMode && maxSlippageBps === bps;
|
|
344
386
|
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
387
|
}), _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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edel-finance/swap-widget",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6-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.
|
|
35
|
+
"@edel-finance/sdk": "0.1.6-alpha"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": ">=18.2.0",
|