@edel-finance/swap-widget 0.0.1 → 0.0.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/README.md +175 -0
- package/dist/adapters/angular.d.ts +32 -0
- package/dist/adapters/angular.js +84 -0
- package/dist/adapters/solid.d.ts +56 -0
- package/dist/adapters/solid.js +41 -0
- package/dist/adapters/svelte.d.ts +26 -0
- package/dist/adapters/svelte.js +45 -0
- package/dist/adapters/vue.d.ts +58 -0
- package/dist/adapters/vue.js +124 -0
- package/dist/embed.d.ts +58 -5
- package/dist/embed.js +211 -31
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/logos.d.ts +59 -0
- package/dist/logos.js +161 -0
- package/dist/theme.d.ts +18 -0
- package/dist/theme.js +592 -175
- package/dist/widget.d.ts +26 -2
- package/dist/widget.js +188 -15
- package/package.json +28 -5
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# `@edel-finance/swap-widget`
|
|
2
|
+
|
|
3
|
+
Embeddable Swap Widget for **Edel Markets** (MainNet and TestNet), powered by `@edel-finance/sdk` with Alpine Forest II dark/light theming, Shadow DOM CSS isolation, RFQ slippage presets (`1.0%` / `2.0%` / `3.0%` + Custom), and live 5-step WebSocket settlement tracking.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @edel-finance/swap-widget @edel-finance/sdk react react-dom
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
All framework subpath adapters (`vue`, `svelte`, `angular`, `solid`) have **zero runtime dependency** on the target framework and isolate styles inside an open Shadow DOM root.
|
|
12
|
+
|
|
13
|
+
## React
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { EdelSwapWidget } from "@edel-finance/swap-widget";
|
|
17
|
+
|
|
18
|
+
export function SwapPage() {
|
|
19
|
+
return (
|
|
20
|
+
<EdelSwapWidget
|
|
21
|
+
network="mainnet"
|
|
22
|
+
integratorId="your-integrator-id"
|
|
23
|
+
defaultFrom="CC"
|
|
24
|
+
defaultTo="USDCx"
|
|
25
|
+
defaultMaxSlippageBps={100}
|
|
26
|
+
theme="dark"
|
|
27
|
+
onSwapComplete={(order) => console.log("Settled:", order.swapId)}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Vue >= 3
|
|
34
|
+
|
|
35
|
+
```vue
|
|
36
|
+
<script setup lang="ts">
|
|
37
|
+
import { h } from "vue";
|
|
38
|
+
import { createVueSwapWidget } from "@edel-finance/swap-widget/vue";
|
|
39
|
+
|
|
40
|
+
const EdelSwapWidget = createVueSwapWidget(h);
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<template>
|
|
44
|
+
<EdelSwapWidget
|
|
45
|
+
network="mainnet"
|
|
46
|
+
integrator-id="your-integrator-id"
|
|
47
|
+
default-from="CC"
|
|
48
|
+
default-to="USDCx"
|
|
49
|
+
theme="dark"
|
|
50
|
+
@swap-complete="(order) => console.log('Settled:', order.swapId)"
|
|
51
|
+
/>
|
|
52
|
+
</template>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or use the zero-boilerplate directive `vEdelSwapWidget`:
|
|
56
|
+
|
|
57
|
+
```vue
|
|
58
|
+
<div v-edel-swap-widget="{ network: 'mainnet', theme: 'dark', integratorId: 'loop' }" />
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Svelte >= 5
|
|
62
|
+
|
|
63
|
+
```svelte
|
|
64
|
+
<script lang="ts">
|
|
65
|
+
import { edelSwapWidget } from "@edel-finance/swap-widget/svelte";
|
|
66
|
+
|
|
67
|
+
let theme = $state<"dark" | "light">("dark");
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<div
|
|
71
|
+
use:edelSwapWidget={{
|
|
72
|
+
network: "mainnet",
|
|
73
|
+
integratorId: "your-integrator-id",
|
|
74
|
+
defaultFrom: "CC",
|
|
75
|
+
defaultTo: "USDCx",
|
|
76
|
+
theme,
|
|
77
|
+
}}
|
|
78
|
+
></div>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
For Svelte 5 `$effect` rune mounting, use `mountSvelteSwapWidget(containerEl, props)`.
|
|
82
|
+
|
|
83
|
+
## Angular >= 17
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild } from "@angular/core";
|
|
87
|
+
import { EdelSwapWidgetAngularController } from "@edel-finance/swap-widget/angular";
|
|
88
|
+
|
|
89
|
+
@Component({
|
|
90
|
+
selector: "app-edel-swap",
|
|
91
|
+
standalone: true,
|
|
92
|
+
template: `<div #swapHost></div>`,
|
|
93
|
+
})
|
|
94
|
+
export class EdelSwapComponent implements AfterViewInit, OnDestroy {
|
|
95
|
+
@ViewChild("swapHost", { static: true }) swapHost!: ElementRef<HTMLElement>;
|
|
96
|
+
private readonly controller = new EdelSwapWidgetAngularController();
|
|
97
|
+
|
|
98
|
+
ngAfterViewInit(): void {
|
|
99
|
+
this.controller.attach(this.swapHost.nativeElement, {
|
|
100
|
+
network: "mainnet",
|
|
101
|
+
integratorId: "your-integrator-id",
|
|
102
|
+
defaultFrom: "CC",
|
|
103
|
+
defaultTo: "USDCx",
|
|
104
|
+
theme: "dark",
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
ngOnDestroy(): void {
|
|
109
|
+
this.controller.destroy();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
For Angular `CUSTOM_ELEMENTS_SCHEMA` templates with `<edel-swap-widget>`, call `registerEdelSwapWidgetElement()` and bind typed listeners with `bindEdelSwapWidgetEvents(element, handlers)`.
|
|
115
|
+
|
|
116
|
+
## SolidJS
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
import { onCleanup } from "solid-js";
|
|
120
|
+
import { createSolidSwapWidget } from "@edel-finance/swap-widget/solid";
|
|
121
|
+
|
|
122
|
+
export function SwapPanel() {
|
|
123
|
+
const widget = createSolidSwapWidget({
|
|
124
|
+
network: "mainnet",
|
|
125
|
+
integratorId: "your-integrator-id",
|
|
126
|
+
defaultFrom: "CC",
|
|
127
|
+
defaultTo: "USDCx",
|
|
128
|
+
theme: "dark",
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
onCleanup(() => widget.cleanup());
|
|
132
|
+
return <div ref={widget.ref} />;
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Shadow DOM Web Component (`<edel-swap-widget>`)
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { registerEdelSwapWidgetElement } from "@edel-finance/swap-widget";
|
|
140
|
+
|
|
141
|
+
registerEdelSwapWidgetElement();
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```html
|
|
145
|
+
<edel-swap-widget
|
|
146
|
+
network="mainnet"
|
|
147
|
+
integrator-id="your-integrator-id"
|
|
148
|
+
from="CC"
|
|
149
|
+
to="USDCx"
|
|
150
|
+
max-slippage-bps="100"
|
|
151
|
+
theme="dark"
|
|
152
|
+
></edel-swap-widget>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Dispatched bubbling, composed `CustomEvent`s:
|
|
156
|
+
|
|
157
|
+
- `edel-swap-quote`: `SwapQuote`
|
|
158
|
+
- `edel-swap-complete`: `SwapOrder`
|
|
159
|
+
- `edel-swap-error`: `{ message: string; error: Error }`
|
|
160
|
+
- `edel-swap-slippage-change`: `{ maxSlippageBps: number }`
|
|
161
|
+
|
|
162
|
+
## 3-Line Standalone iframe Embed
|
|
163
|
+
|
|
164
|
+
```html
|
|
165
|
+
<iframe src="https://app.edel.finance/embed/swap?network=mainnet&from=CC&to=USDCx&theme=dark" title="Edel Swap Widget"
|
|
166
|
+
width="100%" height="560" allow="clipboard-write"
|
|
167
|
+
style="border:0;border-radius:18px;overflow:hidden;max-width:440px;"></iframe>
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Interactive Storybook
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
pnpm --filter @edel-finance/swap-widget storybook
|
|
174
|
+
pnpm --filter @edel-finance/swap-widget build-storybook
|
|
175
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { SwapOrder, SwapQuote } from "@edel-finance/sdk";
|
|
2
|
+
import { EDEL_SWAP_WIDGET_EVENTS, EDEL_SWAP_WIDGET_TAG, type EdelSwapWidgetErrorDetail, type EdelSwapWidgetSlippageDetail, type MountEdelSwapWidgetOptions, type MountedEdelSwapWidget, mountEdelSwapWidget, registerEdelSwapWidgetElement } from "../embed.js";
|
|
3
|
+
import type { EdelSwapWidgetProps } from "../widget.js";
|
|
4
|
+
export interface EdelSwapWidgetAngularEventHandlers {
|
|
5
|
+
onQuote?: (quote: SwapQuote) => void;
|
|
6
|
+
onComplete?: (order: SwapOrder) => void;
|
|
7
|
+
onError?: (detail: EdelSwapWidgetErrorDetail) => void;
|
|
8
|
+
onSlippageChange?: (detail: EdelSwapWidgetSlippageDetail) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Typed controller for Angular >= 17 components (compatible with `AfterViewInit`,
|
|
12
|
+
* `OnChanges`, `OnDestroy`, or signal-based `viewChild` + `effect()`).
|
|
13
|
+
* Zero runtime dependency on `@angular/core`.
|
|
14
|
+
*/
|
|
15
|
+
export declare class EdelSwapWidgetAngularController {
|
|
16
|
+
private mounted;
|
|
17
|
+
private readonly defaultOptions;
|
|
18
|
+
constructor(options?: MountEdelSwapWidgetOptions);
|
|
19
|
+
get isMounted(): boolean;
|
|
20
|
+
attach(nativeElement: HTMLElement, props?: EdelSwapWidgetProps, options?: MountEdelSwapWidgetOptions): void;
|
|
21
|
+
update(nextProps: Partial<EdelSwapWidgetProps>): void;
|
|
22
|
+
getProps(): EdelSwapWidgetProps | null;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Binds strongly-typed CustomEvent listeners (`edel-swap-quote`, `edel-swap-complete`,
|
|
27
|
+
* `edel-swap-error`, `edel-swap-slippage-change`) on an `<edel-swap-widget>` element
|
|
28
|
+
* and returns a single unsubscribe callback for `ngOnDestroy` / `DestroyRef.onDestroy`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function bindEdelSwapWidgetEvents(element: EventTarget, handlers: EdelSwapWidgetAngularEventHandlers): () => void;
|
|
31
|
+
export type { EdelSwapWidgetProps } from "../widget.js";
|
|
32
|
+
export { EDEL_SWAP_WIDGET_EVENTS, EDEL_SWAP_WIDGET_TAG, type EdelSwapWidgetErrorDetail, type EdelSwapWidgetSlippageDetail, type MountEdelSwapWidgetOptions, type MountedEdelSwapWidget, mountEdelSwapWidget, registerEdelSwapWidgetElement, };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { EDEL_SWAP_WIDGET_EVENTS, EDEL_SWAP_WIDGET_TAG, mountEdelSwapWidget, registerEdelSwapWidgetElement, } from "../embed.js";
|
|
2
|
+
/**
|
|
3
|
+
* Typed controller for Angular >= 17 components (compatible with `AfterViewInit`,
|
|
4
|
+
* `OnChanges`, `OnDestroy`, or signal-based `viewChild` + `effect()`).
|
|
5
|
+
* Zero runtime dependency on `@angular/core`.
|
|
6
|
+
*/
|
|
7
|
+
export class EdelSwapWidgetAngularController {
|
|
8
|
+
mounted = null;
|
|
9
|
+
defaultOptions;
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this.defaultOptions = options;
|
|
12
|
+
}
|
|
13
|
+
get isMounted() {
|
|
14
|
+
return this.mounted !== null;
|
|
15
|
+
}
|
|
16
|
+
attach(nativeElement, props = {}, options = {}) {
|
|
17
|
+
if (this.mounted) {
|
|
18
|
+
this.mounted.update(props);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.mounted = mountEdelSwapWidget(nativeElement, props, {
|
|
22
|
+
shadowDom: true,
|
|
23
|
+
dispatchEvents: true,
|
|
24
|
+
...this.defaultOptions,
|
|
25
|
+
...options,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
update(nextProps) {
|
|
29
|
+
this.mounted?.update(nextProps);
|
|
30
|
+
}
|
|
31
|
+
getProps() {
|
|
32
|
+
return this.mounted ? this.mounted.getProps() : null;
|
|
33
|
+
}
|
|
34
|
+
destroy() {
|
|
35
|
+
this.mounted?.unmount();
|
|
36
|
+
this.mounted = null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Binds strongly-typed CustomEvent listeners (`edel-swap-quote`, `edel-swap-complete`,
|
|
41
|
+
* `edel-swap-error`, `edel-swap-slippage-change`) on an `<edel-swap-widget>` element
|
|
42
|
+
* and returns a single unsubscribe callback for `ngOnDestroy` / `DestroyRef.onDestroy`.
|
|
43
|
+
*/
|
|
44
|
+
export function bindEdelSwapWidgetEvents(element, handlers) {
|
|
45
|
+
const cleanups = [];
|
|
46
|
+
if (handlers.onQuote) {
|
|
47
|
+
const onQuote = handlers.onQuote;
|
|
48
|
+
const listener = (event) => {
|
|
49
|
+
onQuote(event.detail);
|
|
50
|
+
};
|
|
51
|
+
element.addEventListener(EDEL_SWAP_WIDGET_EVENTS.quote, listener);
|
|
52
|
+
cleanups.push(() => element.removeEventListener(EDEL_SWAP_WIDGET_EVENTS.quote, listener));
|
|
53
|
+
}
|
|
54
|
+
if (handlers.onComplete) {
|
|
55
|
+
const onComplete = handlers.onComplete;
|
|
56
|
+
const listener = (event) => {
|
|
57
|
+
onComplete(event.detail);
|
|
58
|
+
};
|
|
59
|
+
element.addEventListener(EDEL_SWAP_WIDGET_EVENTS.complete, listener);
|
|
60
|
+
cleanups.push(() => element.removeEventListener(EDEL_SWAP_WIDGET_EVENTS.complete, listener));
|
|
61
|
+
}
|
|
62
|
+
if (handlers.onError) {
|
|
63
|
+
const onError = handlers.onError;
|
|
64
|
+
const listener = (event) => {
|
|
65
|
+
onError(event.detail);
|
|
66
|
+
};
|
|
67
|
+
element.addEventListener(EDEL_SWAP_WIDGET_EVENTS.error, listener);
|
|
68
|
+
cleanups.push(() => element.removeEventListener(EDEL_SWAP_WIDGET_EVENTS.error, listener));
|
|
69
|
+
}
|
|
70
|
+
if (handlers.onSlippageChange) {
|
|
71
|
+
const onSlippageChange = handlers.onSlippageChange;
|
|
72
|
+
const listener = (event) => {
|
|
73
|
+
onSlippageChange(event.detail);
|
|
74
|
+
};
|
|
75
|
+
element.addEventListener(EDEL_SWAP_WIDGET_EVENTS.slippageChange, listener);
|
|
76
|
+
cleanups.push(() => element.removeEventListener(EDEL_SWAP_WIDGET_EVENTS.slippageChange, listener));
|
|
77
|
+
}
|
|
78
|
+
return () => {
|
|
79
|
+
for (const cleanup of cleanups) {
|
|
80
|
+
cleanup();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export { EDEL_SWAP_WIDGET_EVENTS, EDEL_SWAP_WIDGET_TAG, mountEdelSwapWidget, registerEdelSwapWidgetElement, };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { EdelNetwork } from "@edel-finance/sdk";
|
|
2
|
+
import { type EdelSwapWidgetEventMap, type MountEdelSwapWidgetOptions, type MountedEdelSwapWidget } from "../embed.js";
|
|
3
|
+
import type { SwapWidgetTheme } from "../theme.js";
|
|
4
|
+
import type { EdelSwapWidgetProps } from "../widget.js";
|
|
5
|
+
export interface SolidSwapWidgetHandle {
|
|
6
|
+
/** Pass directly to Solid's `ref={widget.ref}` attribute. */
|
|
7
|
+
ref(el: HTMLElement): void;
|
|
8
|
+
/** Push reactive prop updates from `createEffect(() => widget.update(props))`. */
|
|
9
|
+
update(nextProps: Partial<EdelSwapWidgetProps>): void;
|
|
10
|
+
/** Unmount the widget inside `onCleanup(() => widget.cleanup())`. */
|
|
11
|
+
cleanup(): void;
|
|
12
|
+
/** Access the underlying mounted widget instance, if attached. */
|
|
13
|
+
getInstance(): MountedEdelSwapWidget | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a typed SolidJS widget handle backed by `mountEdelSwapWidget` with Shadow DOM
|
|
17
|
+
* CSS isolation and zero runtime dependency on `solid-js`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createSolidSwapWidget(initialProps?: EdelSwapWidgetProps, mountOptions?: MountEdelSwapWidgetOptions): SolidSwapWidgetHandle;
|
|
20
|
+
/**
|
|
21
|
+
* SolidJS `use:edelSwapWidget={props}` directive backed by `mountEdelSwapWidget`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function edelSwapWidget(el: HTMLElement, accessor: () => EdelSwapWidgetProps, mountOptions?: MountEdelSwapWidgetOptions): MountedEdelSwapWidget;
|
|
24
|
+
export interface EdelSwapWidgetSolidIntrinsicAttributes {
|
|
25
|
+
network?: EdelNetwork;
|
|
26
|
+
theme?: SwapWidgetTheme;
|
|
27
|
+
"integrator-id"?: string;
|
|
28
|
+
"partner-id"?: string;
|
|
29
|
+
from?: string;
|
|
30
|
+
to?: string;
|
|
31
|
+
"max-slippage-bps"?: number | string;
|
|
32
|
+
"integrator-fee-bps"?: number | string;
|
|
33
|
+
"recipient-address"?: string;
|
|
34
|
+
"on:edel-swap-quote"?: (event: EdelSwapWidgetEventMap["edel-swap-quote"]) => void;
|
|
35
|
+
"on:edel-swap-complete"?: (event: EdelSwapWidgetEventMap["edel-swap-complete"]) => void;
|
|
36
|
+
"on:edel-swap-error"?: (event: EdelSwapWidgetEventMap["edel-swap-error"]) => void;
|
|
37
|
+
"on:edel-swap-slippage-change"?: (event: EdelSwapWidgetEventMap["edel-swap-slippage-change"]) => void;
|
|
38
|
+
}
|
|
39
|
+
export interface SolidSwapWidgetJSXIntrinsicElements {
|
|
40
|
+
"edel-swap-widget": EdelSwapWidgetSolidIntrinsicAttributes;
|
|
41
|
+
}
|
|
42
|
+
export interface SolidSwapWidgetDirectives {
|
|
43
|
+
edelSwapWidget: EdelSwapWidgetProps;
|
|
44
|
+
}
|
|
45
|
+
declare global {
|
|
46
|
+
namespace JSX {
|
|
47
|
+
interface IntrinsicElements {
|
|
48
|
+
"edel-swap-widget": EdelSwapWidgetSolidIntrinsicAttributes;
|
|
49
|
+
}
|
|
50
|
+
interface Directives {
|
|
51
|
+
edelSwapWidget: EdelSwapWidgetProps;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export { EDEL_SWAP_WIDGET_EVENTS, EDEL_SWAP_WIDGET_TAG, type MountEdelSwapWidgetOptions, type MountedEdelSwapWidget, mountEdelSwapWidget, registerEdelSwapWidgetElement, } from "../embed.js";
|
|
56
|
+
export type { EdelSwapWidgetProps } from "../widget.js";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { mountEdelSwapWidget, } from "../embed.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a typed SolidJS widget handle backed by `mountEdelSwapWidget` with Shadow DOM
|
|
4
|
+
* CSS isolation and zero runtime dependency on `solid-js`.
|
|
5
|
+
*/
|
|
6
|
+
export function createSolidSwapWidget(initialProps = {}, mountOptions = {}) {
|
|
7
|
+
let instance = null;
|
|
8
|
+
let pendingProps = { ...initialProps };
|
|
9
|
+
return {
|
|
10
|
+
ref(el) {
|
|
11
|
+
if (instance) {
|
|
12
|
+
instance.unmount();
|
|
13
|
+
}
|
|
14
|
+
instance = mountEdelSwapWidget(el, pendingProps, {
|
|
15
|
+
shadowDom: true,
|
|
16
|
+
...mountOptions,
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
update(nextProps) {
|
|
20
|
+
pendingProps = { ...pendingProps, ...nextProps };
|
|
21
|
+
instance?.update(nextProps);
|
|
22
|
+
},
|
|
23
|
+
cleanup() {
|
|
24
|
+
instance?.unmount();
|
|
25
|
+
instance = null;
|
|
26
|
+
},
|
|
27
|
+
getInstance() {
|
|
28
|
+
return instance;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* SolidJS `use:edelSwapWidget={props}` directive backed by `mountEdelSwapWidget`.
|
|
34
|
+
*/
|
|
35
|
+
export function edelSwapWidget(el, accessor, mountOptions = {}) {
|
|
36
|
+
return mountEdelSwapWidget(el, accessor(), {
|
|
37
|
+
shadowDom: true,
|
|
38
|
+
...mountOptions,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export { EDEL_SWAP_WIDGET_EVENTS, EDEL_SWAP_WIDGET_TAG, mountEdelSwapWidget, registerEdelSwapWidgetElement, } from "../embed.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type MountEdelSwapWidgetOptions } from "../embed.js";
|
|
2
|
+
import type { EdelSwapWidgetProps } from "../widget.js";
|
|
3
|
+
export interface SvelteActionReturn<TParams> {
|
|
4
|
+
update?: (params: TParams) => void;
|
|
5
|
+
destroy?: () => void;
|
|
6
|
+
}
|
|
7
|
+
export type SvelteSwapWidgetAction = (node: HTMLElement, props?: EdelSwapWidgetProps) => SvelteActionReturn<EdelSwapWidgetProps>;
|
|
8
|
+
/**
|
|
9
|
+
* Factory for a typed Svelte action (`use:edelSwapWidget={props}`) with custom mount options.
|
|
10
|
+
* Zero runtime dependency on `svelte`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createSvelteSwapWidgetAction(mountOptions?: MountEdelSwapWidgetOptions): SvelteSwapWidgetAction;
|
|
13
|
+
/**
|
|
14
|
+
* Svelte >= 5 action for mounting the Edel Swap Widget inside a Shadow DOM host.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* `<div use:edelSwapWidget={{ network: "mainnet", theme: "dark", integratorId: "loop" }}></div>`
|
|
18
|
+
*/
|
|
19
|
+
export declare const edelSwapWidget: SvelteSwapWidgetAction;
|
|
20
|
+
/**
|
|
21
|
+
* Svelte 5 `$effect`-friendly mount helper. Returns a cleanup callback directly
|
|
22
|
+
* compatible with `$effect(() => mountSvelteSwapWidget(containerEl, props))`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function mountSvelteSwapWidget(node: HTMLElement | null | undefined, props?: EdelSwapWidgetProps, mountOptions?: MountEdelSwapWidgetOptions): () => void;
|
|
25
|
+
export { type MountEdelSwapWidgetOptions, type MountedEdelSwapWidget, mountEdelSwapWidget, registerEdelSwapWidgetElement, } from "../embed.js";
|
|
26
|
+
export type { EdelSwapWidgetProps } from "../widget.js";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { mountEdelSwapWidget, } from "../embed.js";
|
|
2
|
+
/**
|
|
3
|
+
* Factory for a typed Svelte action (`use:edelSwapWidget={props}`) with custom mount options.
|
|
4
|
+
* Zero runtime dependency on `svelte`.
|
|
5
|
+
*/
|
|
6
|
+
export function createSvelteSwapWidgetAction(mountOptions = {}) {
|
|
7
|
+
return function edelSwapWidgetAction(node, props = {}) {
|
|
8
|
+
const mounted = mountEdelSwapWidget(node, props, {
|
|
9
|
+
shadowDom: true,
|
|
10
|
+
...mountOptions,
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
update(nextProps) {
|
|
14
|
+
mounted.update(nextProps);
|
|
15
|
+
},
|
|
16
|
+
destroy() {
|
|
17
|
+
mounted.unmount();
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Svelte >= 5 action for mounting the Edel Swap Widget inside a Shadow DOM host.
|
|
24
|
+
*
|
|
25
|
+
* Usage:
|
|
26
|
+
* `<div use:edelSwapWidget={{ network: "mainnet", theme: "dark", integratorId: "loop" }}></div>`
|
|
27
|
+
*/
|
|
28
|
+
export const edelSwapWidget = createSvelteSwapWidgetAction();
|
|
29
|
+
/**
|
|
30
|
+
* Svelte 5 `$effect`-friendly mount helper. Returns a cleanup callback directly
|
|
31
|
+
* compatible with `$effect(() => mountSvelteSwapWidget(containerEl, props))`.
|
|
32
|
+
*/
|
|
33
|
+
export function mountSvelteSwapWidget(node, props = {}, mountOptions = {}) {
|
|
34
|
+
if (!node) {
|
|
35
|
+
return () => { };
|
|
36
|
+
}
|
|
37
|
+
const mounted = mountEdelSwapWidget(node, props, {
|
|
38
|
+
shadowDom: true,
|
|
39
|
+
...mountOptions,
|
|
40
|
+
});
|
|
41
|
+
return () => {
|
|
42
|
+
mounted.unmount();
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export { mountEdelSwapWidget, registerEdelSwapWidgetElement, } from "../embed.js";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { SwapOrder, SwapQuote } from "@edel-finance/sdk";
|
|
2
|
+
import { type MountEdelSwapWidgetOptions, type MountedEdelSwapWidget } from "../embed.js";
|
|
3
|
+
import type { EdelSwapWidgetProps } from "../widget.js";
|
|
4
|
+
export type EdelSwapWidgetVueProps = EdelSwapWidgetProps;
|
|
5
|
+
export interface EdelSwapWidgetVueEmits {
|
|
6
|
+
quote: [quote: SwapQuote];
|
|
7
|
+
swapComplete: [order: SwapOrder];
|
|
8
|
+
orderSubmitted: [order: SwapOrder];
|
|
9
|
+
error: [error: Error];
|
|
10
|
+
slippageChange: [maxSlippageBps: number];
|
|
11
|
+
}
|
|
12
|
+
export type VueRenderFactory = (type: string, props?: Record<string, unknown> | null, children?: unknown) => unknown;
|
|
13
|
+
export interface VueWidgetInstanceContext {
|
|
14
|
+
$el?: HTMLElement | null;
|
|
15
|
+
$props?: Partial<EdelSwapWidgetProps>;
|
|
16
|
+
$emit?: (event: string, ...args: unknown[]) => void;
|
|
17
|
+
_edelWidget?: MountedEdelSwapWidget | null;
|
|
18
|
+
}
|
|
19
|
+
export interface VueSwapWidgetComponentDefinition {
|
|
20
|
+
name: string;
|
|
21
|
+
props: readonly (keyof EdelSwapWidgetProps)[];
|
|
22
|
+
emits: readonly (keyof EdelSwapWidgetVueEmits)[];
|
|
23
|
+
mounted(this: VueWidgetInstanceContext): void;
|
|
24
|
+
updated(this: VueWidgetInstanceContext): void;
|
|
25
|
+
beforeUnmount(this: VueWidgetInstanceContext): void;
|
|
26
|
+
render?: () => unknown;
|
|
27
|
+
template?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a typed Vue >= 3 component backed by `mountEdelSwapWidget` with Shadow DOM
|
|
31
|
+
* CSS isolation and zero runtime dependency on `vue`.
|
|
32
|
+
*
|
|
33
|
+
* Pass Vue's `h` render helper for runtime-only builds (Vite default):
|
|
34
|
+
* `const SwapWidget = createVueSwapWidget(h);`
|
|
35
|
+
*/
|
|
36
|
+
export declare function createVueSwapWidget(h?: VueRenderFactory, mountOptions?: MountEdelSwapWidgetOptions): VueSwapWidgetComponentDefinition;
|
|
37
|
+
/**
|
|
38
|
+
* Ready-to-register Vue >= 3 component definition.
|
|
39
|
+
* For runtime-only Vite builds (without the Vue template compiler), prefer
|
|
40
|
+
* `createVueSwapWidget(h)` or the `vEdelSwapWidget` directive.
|
|
41
|
+
*/
|
|
42
|
+
export declare const EdelSwapWidgetVue: VueSwapWidgetComponentDefinition;
|
|
43
|
+
export interface VueDirectiveBinding<T> {
|
|
44
|
+
value?: T;
|
|
45
|
+
}
|
|
46
|
+
export interface VueSwapWidgetDirective {
|
|
47
|
+
mounted(el: HTMLElement, binding: VueDirectiveBinding<EdelSwapWidgetProps>): void;
|
|
48
|
+
updated(el: HTMLElement, binding: VueDirectiveBinding<EdelSwapWidgetProps>): void;
|
|
49
|
+
unmounted(el: HTMLElement): void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates a Vue >= 3 custom directive (`v-edel-swap-widget="props"`) that works in
|
|
53
|
+
* both runtime-only and full Vue builds with zero dependency on `vue`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function createVueSwapWidgetDirective(mountOptions?: MountEdelSwapWidgetOptions): VueSwapWidgetDirective;
|
|
56
|
+
export declare const vEdelSwapWidget: VueSwapWidgetDirective;
|
|
57
|
+
export { type MountEdelSwapWidgetOptions, type MountedEdelSwapWidget, mountEdelSwapWidget, registerEdelSwapWidgetElement, } from "../embed.js";
|
|
58
|
+
export type { EdelSwapWidgetProps } from "../widget.js";
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { mountEdelSwapWidget, } from "../embed.js";
|
|
2
|
+
const VUE_PROP_NAMES = [
|
|
3
|
+
"integratorId",
|
|
4
|
+
"partnerId",
|
|
5
|
+
"theme",
|
|
6
|
+
"network",
|
|
7
|
+
"defaultFrom",
|
|
8
|
+
"defaultTo",
|
|
9
|
+
"defaultFromAsset",
|
|
10
|
+
"defaultToAsset",
|
|
11
|
+
"defaultMaxSlippageBps",
|
|
12
|
+
"recipientAddress",
|
|
13
|
+
"integratorFeeBps",
|
|
14
|
+
"client",
|
|
15
|
+
"initialQuote",
|
|
16
|
+
"initialOrder",
|
|
17
|
+
"onQuote",
|
|
18
|
+
"onSlippageChange",
|
|
19
|
+
"onSwapComplete",
|
|
20
|
+
"onOrderSubmitted",
|
|
21
|
+
"onError",
|
|
22
|
+
"style",
|
|
23
|
+
];
|
|
24
|
+
const VUE_EMIT_NAMES = [
|
|
25
|
+
"quote",
|
|
26
|
+
"swapComplete",
|
|
27
|
+
"orderSubmitted",
|
|
28
|
+
"error",
|
|
29
|
+
"slippageChange",
|
|
30
|
+
];
|
|
31
|
+
function buildVueWidgetProps(ctx) {
|
|
32
|
+
const raw = ctx.$props ?? {};
|
|
33
|
+
const emit = ctx.$emit;
|
|
34
|
+
return {
|
|
35
|
+
...raw,
|
|
36
|
+
onQuote: (quote) => {
|
|
37
|
+
raw.onQuote?.(quote);
|
|
38
|
+
emit?.("quote", quote);
|
|
39
|
+
},
|
|
40
|
+
onSwapComplete: (order) => {
|
|
41
|
+
raw.onSwapComplete?.(order);
|
|
42
|
+
emit?.("swapComplete", order);
|
|
43
|
+
},
|
|
44
|
+
onOrderSubmitted: (order) => {
|
|
45
|
+
raw.onOrderSubmitted?.(order);
|
|
46
|
+
emit?.("orderSubmitted", order);
|
|
47
|
+
},
|
|
48
|
+
onError: (error) => {
|
|
49
|
+
raw.onError?.(error);
|
|
50
|
+
emit?.("error", error);
|
|
51
|
+
},
|
|
52
|
+
onSlippageChange: (maxSlippageBps) => {
|
|
53
|
+
raw.onSlippageChange?.(maxSlippageBps);
|
|
54
|
+
emit?.("slippageChange", maxSlippageBps);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a typed Vue >= 3 component backed by `mountEdelSwapWidget` with Shadow DOM
|
|
60
|
+
* CSS isolation and zero runtime dependency on `vue`.
|
|
61
|
+
*
|
|
62
|
+
* Pass Vue's `h` render helper for runtime-only builds (Vite default):
|
|
63
|
+
* `const SwapWidget = createVueSwapWidget(h);`
|
|
64
|
+
*/
|
|
65
|
+
export function createVueSwapWidget(h, mountOptions = {}) {
|
|
66
|
+
const component = {
|
|
67
|
+
name: "EdelSwapWidget",
|
|
68
|
+
props: VUE_PROP_NAMES,
|
|
69
|
+
emits: VUE_EMIT_NAMES,
|
|
70
|
+
mounted() {
|
|
71
|
+
if (!this.$el)
|
|
72
|
+
return;
|
|
73
|
+
this._edelWidget = mountEdelSwapWidget(this.$el, buildVueWidgetProps(this), {
|
|
74
|
+
shadowDom: true,
|
|
75
|
+
...mountOptions,
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
updated() {
|
|
79
|
+
this._edelWidget?.update(buildVueWidgetProps(this));
|
|
80
|
+
},
|
|
81
|
+
beforeUnmount() {
|
|
82
|
+
this._edelWidget?.unmount();
|
|
83
|
+
this._edelWidget = null;
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
if (h) {
|
|
87
|
+
component.render = () => h("div", { class: "edel-swap-widget-vue-host" });
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
component.template = '<div class="edel-swap-widget-vue-host"></div>';
|
|
91
|
+
}
|
|
92
|
+
return component;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Ready-to-register Vue >= 3 component definition.
|
|
96
|
+
* For runtime-only Vite builds (without the Vue template compiler), prefer
|
|
97
|
+
* `createVueSwapWidget(h)` or the `vEdelSwapWidget` directive.
|
|
98
|
+
*/
|
|
99
|
+
export const EdelSwapWidgetVue = createVueSwapWidget();
|
|
100
|
+
/**
|
|
101
|
+
* Creates a Vue >= 3 custom directive (`v-edel-swap-widget="props"`) that works in
|
|
102
|
+
* both runtime-only and full Vue builds with zero dependency on `vue`.
|
|
103
|
+
*/
|
|
104
|
+
export function createVueSwapWidgetDirective(mountOptions = {}) {
|
|
105
|
+
const instances = new WeakMap();
|
|
106
|
+
return {
|
|
107
|
+
mounted(el, binding) {
|
|
108
|
+
const mounted = mountEdelSwapWidget(el, binding.value ?? {}, {
|
|
109
|
+
shadowDom: true,
|
|
110
|
+
...mountOptions,
|
|
111
|
+
});
|
|
112
|
+
instances.set(el, mounted);
|
|
113
|
+
},
|
|
114
|
+
updated(el, binding) {
|
|
115
|
+
instances.get(el)?.update(binding.value ?? {});
|
|
116
|
+
},
|
|
117
|
+
unmounted(el) {
|
|
118
|
+
instances.get(el)?.unmount();
|
|
119
|
+
instances.delete(el);
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export const vEdelSwapWidget = createVueSwapWidgetDirective();
|
|
124
|
+
export { mountEdelSwapWidget, registerEdelSwapWidgetElement, } from "../embed.js";
|