@tokenflight/swap 0.0.4 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/swap.d.ts ADDED
@@ -0,0 +1,283 @@
1
+ import { QuoteResponse } from '@tokenflight/api';
2
+
3
+ /** Amount change data */
4
+ declare interface AmountChangedData {
5
+ amount: string;
6
+ direction: "from" | "to";
7
+ }
8
+
9
+ /**
10
+ * Boolean HTML attribute — accepts both native booleans and the
11
+ * string equivalents that `parseBooleanProp()` understands.
12
+ */
13
+ declare type BooleanAttribute = boolean | "true" | "false" | "1" | "0" | "yes" | "no" | "";
14
+
15
+ /** Callback interfaces for widget events */
16
+ export declare interface Callbacks {
17
+ onSwapSuccess?(data: SwapSuccessData): void;
18
+ onSwapError?(data: SwapErrorData): void;
19
+ onWalletConnected?(data: WalletConnectedData): void;
20
+ onQuoteReceived?(data: QuoteResponse): void;
21
+ onAmountChanged?(data: AmountChangedData): void;
22
+ /** Called when user clicks Connect Wallet and no walletAdapter is provided */
23
+ onConnectWallet?(): void;
24
+ /** Called when user clicks the connected wallet address (for custom account modal handling) */
25
+ onAccountModal?(): void;
26
+ /** Called when a fiat order is created and the payment widget URL is available */
27
+ onFiatOrderCreated?(data: {
28
+ orderId: string;
29
+ widgetUrl: string;
30
+ }): void;
31
+ /** Called when a fiat order reaches a terminal status */
32
+ onFiatOrderCompleted?(data: {
33
+ orderId: string;
34
+ status: string;
35
+ txHash?: string;
36
+ }): void;
37
+ /** Called when a deposit completes successfully */
38
+ onDepositSuccess?(data: SwapSuccessData): void;
39
+ /** Called when a deposit fails */
40
+ onDepositError?(data: SwapErrorData): void;
41
+ }
42
+
43
+ /** Chain type for multi-chain support */
44
+ declare type ChainType = "evm" | "solana";
45
+
46
+ /**
47
+ * Custom color overrides — keys are CSS variable names.
48
+ * Typed keys provide autocomplete; arbitrary `--tf-*` strings are also accepted.
49
+ *
50
+ * ```ts
51
+ * customColors: {
52
+ * "--tf-primary": "#FF6B00",
53
+ * "--tf-bg": "#1A1A2E",
54
+ * "--tf-button-radius": "4px",
55
+ * "--tf-widget-max-width": "480px",
56
+ * }
57
+ * ```
58
+ */
59
+ export declare type CustomColors = Partial<Record<TfCssVar, string>> & Record<string, string>;
60
+
61
+ /** EVM wallet action via EIP-1193 */
62
+ declare interface EvmWalletAction {
63
+ type: "eip1193_request";
64
+ chainId: number;
65
+ method: string;
66
+ params: unknown[];
67
+ }
68
+
69
+ declare interface ImperativeWidgetOptions<TConfig> {
70
+ container: string | HTMLElement;
71
+ config: TConfig;
72
+ walletAdapter?: IWalletAdapter;
73
+ callbacks?: Callbacks;
74
+ }
75
+
76
+ /** Wallet adapter interface that all adapters must implement */
77
+ export declare interface IWalletAdapter {
78
+ /** Human-readable name */
79
+ readonly name: string;
80
+ /** Icon URL */
81
+ readonly icon?: string;
82
+ /** Supported action types */
83
+ readonly supportedActionTypes: WalletActionType[];
84
+ /** Optional: supported chain IDs — when set, the widget only shows tokens on these chains */
85
+ readonly supportedChainIds?: number[];
86
+ /** Connect the wallet */
87
+ connect(chainType?: ChainType): Promise<void>;
88
+ /** Disconnect the wallet */
89
+ disconnect(): Promise<void>;
90
+ /** Check if connected */
91
+ isConnected(chainType?: ChainType): boolean;
92
+ /** Get the current address */
93
+ getAddress(chainType?: ChainType): Promise<string | null>;
94
+ /** Execute a wallet action */
95
+ executeWalletAction(action: WalletAction): Promise<WalletActionResult>;
96
+ /** Optional: sign a message */
97
+ signMessage?(message: string, chainType?: ChainType): Promise<string>;
98
+ /** Optional: open the wallet's native account/connected modal */
99
+ openAccountModal?(): Promise<void>;
100
+ /** Optional: clean up internal subscriptions and watchers */
101
+ destroy?(): void;
102
+ /** Subscribe to wallet events */
103
+ on(event: WalletEventType, handler: (event: WalletEvent) => void): void;
104
+ /** Unsubscribe from wallet events */
105
+ off(event: WalletEventType, handler: (event: WalletEvent) => void): void;
106
+ }
107
+
108
+ export declare interface RegisterElementsOptions {
109
+ walletAdapter?: IWalletAdapter;
110
+ callbacks?: Callbacks;
111
+ /** Custom CSS variable overrides merged on top of the active theme.
112
+ * Keys are CSS variable names, e.g. `"--tf-primary"`, `"--tf-font-family"`. */
113
+ customColors?: CustomColors;
114
+ /** Default API endpoint for all widget instances. */
115
+ apiEndpoint?: string;
116
+ /** Default theme for all widget instances. */
117
+ theme?: Theme;
118
+ /** Default locale for all widget instances. */
119
+ locale?: SupportedLocale;
120
+ }
121
+
122
+ export declare function registerSwapElement(options?: RegisterElementsOptions): void;
123
+
124
+ /** Solana sign and send transaction action */
125
+ declare interface SolanaSignAndSendAction {
126
+ type: "solana_signAndSendTransaction";
127
+ transaction: string;
128
+ }
129
+
130
+ /** Solana sign transaction action */
131
+ declare interface SolanaSignTransactionAction {
132
+ type: "solana_signTransaction";
133
+ transaction: string;
134
+ }
135
+
136
+ /** Supported locale identifiers. Accepts any string for forward-compat; known values get bundled translations. */
137
+ export declare type SupportedLocale = "en-US" | "zh-CN" | "zh-TW" | "ja-JP" | "ko-KR" | (string & {});
138
+
139
+ /** Data emitted on swap error */
140
+ declare interface SwapErrorData {
141
+ code: string;
142
+ message: string;
143
+ details?: unknown;
144
+ }
145
+
146
+ /** Data emitted on swap success */
147
+ declare interface SwapSuccessData {
148
+ orderId: string;
149
+ fromToken: string;
150
+ toToken: string;
151
+ fromAmount: string;
152
+ toAmount: string;
153
+ txHash: string;
154
+ }
155
+
156
+ /** All first-party CSS custom properties exposed for theming. */
157
+ declare type TfCssVar = "--tf-bg" | "--tf-bg-secondary" | "--tf-bg-elevated" | "--tf-surface" | "--tf-surface-hover" | "--tf-input-bg" | "--tf-glass" | "--tf-text" | "--tf-text-secondary" | "--tf-text-tertiary" | "--tf-text-on-primary" | "--tf-border" | "--tf-border-light" | "--tf-primary" | "--tf-primary-alpha" | "--tf-primary-light" | "--tf-primary-glow" | "--tf-success" | "--tf-success-bg" | "--tf-error" | "--tf-error-bg" | "--tf-error-alpha" | "--tf-warning" | "--tf-warning-bg" | "--tf-shadow" | "--tf-shadow-lg" | "--tf-skeleton" | "--tf-radius-xs" | "--tf-radius-sm" | "--tf-radius" | "--tf-radius-lg" | "--tf-radius-xl" | "--tf-button-radius" | "--tf-widget-max-width" | "--tf-font-family" | "--tf-font-family-mono";
158
+
159
+ /** Visual theme mode. */
160
+ export declare type Theme = "light" | "dark" | "auto";
161
+
162
+ /** Shared configuration fields for both widgets */
163
+ declare interface TokenFlightConfigBase {
164
+ /** HyperStream API endpoint */
165
+ apiEndpoint?: string;
166
+ /** Fiat on-ramp API endpoint (default: https://fiat-preview.hyperstream.dev) */
167
+ fiatApiEndpoint?: string;
168
+ /** Visual theme */
169
+ theme?: Theme;
170
+ /** Locale for i18n */
171
+ locale?: SupportedLocale;
172
+ /** Custom CSS color overrides */
173
+ customColors?: CustomColors;
174
+ /** Optional custom widget title text */
175
+ titleText?: string;
176
+ /** Optional custom widget title image URL */
177
+ titleImageUrl?: string;
178
+ /** Hide top title/header area */
179
+ hideTitle?: boolean;
180
+ /** Hide "Powered by TokenFlight" footer */
181
+ hidePoweredBy?: boolean;
182
+ /** Remove container background (transparent) */
183
+ noBackground?: boolean;
184
+ /** Remove container border and shadow */
185
+ noBorder?: boolean;
186
+ }
187
+
188
+ export declare const TokenFlightSwap: {
189
+ new (options: ImperativeWidgetOptions<TokenFlightSwapConfig>): {
190
+ #dispose: (() => void) | null;
191
+ #unwatchTheme: (() => void) | null;
192
+ #container: HTMLElement;
193
+ #shadowRoot: ShadowRoot | null;
194
+ #config: TokenFlightSwapConfig;
195
+ #walletAdapter?: IWalletAdapter;
196
+ #callbacks?: Callbacks;
197
+ initialize(): void;
198
+ destroy(): void;
199
+ setTheme(theme: Theme): void;
200
+ setCustomColors(colors: CustomColors): void;
201
+ #applyThemeStyles(style: HTMLStyleElement, theme: string): void;
202
+ #setupAutoThemeWatch(style: HTMLStyleElement): void;
203
+ };
204
+ };
205
+
206
+ /** Attributes accepted by `<tokenflight-swap>`. */
207
+ export declare interface TokenFlightSwapAttributes {
208
+ "api-endpoint"?: string;
209
+ "from-token"?: string;
210
+ "to-token"?: string;
211
+ recipient?: string;
212
+ "title-text"?: string;
213
+ "title-image"?: string;
214
+ theme?: Theme;
215
+ locale?: SupportedLocale;
216
+ "csp-nonce"?: string;
217
+ "hide-title"?: BooleanAttribute;
218
+ "hide-powered-by"?: BooleanAttribute;
219
+ "no-background"?: BooleanAttribute;
220
+ "no-border"?: BooleanAttribute;
221
+ }
222
+
223
+ /** Configuration for `<tokenflight-swap>` */
224
+ export declare interface TokenFlightSwapConfig extends TokenFlightConfigBase {
225
+ /** Optional source token */
226
+ fromToken?: TokenIdentifier;
227
+ /** Optional destination token */
228
+ toToken?: TokenIdentifier;
229
+ /** Optional recipient address (for cross-chain swaps to a different address) */
230
+ recipient?: string;
231
+ }
232
+
233
+ export declare interface TokenFlightSwapOptions {
234
+ container: string | HTMLElement;
235
+ config: TokenFlightSwapConfig;
236
+ walletAdapter?: IWalletAdapter;
237
+ callbacks?: Callbacks;
238
+ }
239
+
240
+ /**
241
+ * Flexible token identifier supporting:
242
+ * - Direct object: { chainId: 1, address: "0x..." }
243
+ * - CAIP-10 string: "eip155:1:0x..."
244
+ * - JSON string: '{"chainId":1,"address":"0x..."}'
245
+ */
246
+ declare type TokenIdentifier = string | TokenTarget;
247
+
248
+ /** Token target as chain + address pair */
249
+ declare interface TokenTarget {
250
+ chainId: number;
251
+ address: string;
252
+ }
253
+
254
+ /** Union of all wallet action types */
255
+ declare type WalletAction = EvmWalletAction | SolanaSignTransactionAction | SolanaSignAndSendAction;
256
+
257
+ /** Result of executing a wallet action */
258
+ declare interface WalletActionResult {
259
+ success: boolean;
260
+ data?: unknown;
261
+ error?: string;
262
+ txHash?: string;
263
+ }
264
+
265
+ /** Wallet action types */
266
+ declare type WalletActionType = "eip1193_request" | "solana_signTransaction" | "solana_signAndSendTransaction";
267
+
268
+ /** Data emitted when wallet is connected */
269
+ declare interface WalletConnectedData {
270
+ address: string;
271
+ chainType: string;
272
+ }
273
+
274
+ /** Wallet event payload */
275
+ declare interface WalletEvent {
276
+ type: WalletEventType;
277
+ data?: unknown;
278
+ }
279
+
280
+ /** Wallet event types */
281
+ declare type WalletEventType = "connect" | "disconnect" | "chainChanged" | "accountsChanged";
282
+
283
+ export { }
package/dist/swap.js ADDED
@@ -0,0 +1 @@
1
+ import"./dist-D4PEwqKq.js";import{n as e,t}from"./register-swap-a_E08H4c.js";export{e as TokenFlightSwap,t as registerSwapElement};