@cowprotocol/widget-lib 0.22.3 → 1.1.1

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/types.d.ts DELETED
@@ -1,365 +0,0 @@
1
- import { SupportedChainId } from '@cowprotocol/cow-sdk';
2
- import { CowWidgetEventListeners, CowWidgetEventPayloadMap, CowWidgetEvents } from '@cowprotocol/events';
3
- export type { SupportedChainId } from '@cowprotocol/cow-sdk';
4
- export type PerTradeTypeConfig<T> = Partial<Record<TradeType, T>>;
5
- export type PerNetworkConfig<T> = Partial<Record<SupportedChainId, T>>;
6
- export type FlexibleConfig<T> = T | PerNetworkConfig<T> | PerTradeTypeConfig<T> | PerTradeTypeConfig<PerNetworkConfig<T>> | PerNetworkConfig<PerTradeTypeConfig<T>>;
7
- export declare enum WidgetMethodsEmit {
8
- ACTIVATE = "ACTIVATE",
9
- UPDATE_HEIGHT = "UPDATE_HEIGHT",
10
- SET_FULL_HEIGHT = "SET_FULL_HEIGHT",
11
- EMIT_COW_EVENT = "EMIT_COW_EVENT",
12
- PROVIDER_RPC_REQUEST = "PROVIDER_RPC_REQUEST",
13
- INTERCEPT_WINDOW_OPEN = "INTERCEPT_WINDOW_OPEN"
14
- }
15
- export declare enum WidgetMethodsListen {
16
- UPDATE_PARAMS = "UPDATE_PARAMS",
17
- UPDATE_APP_DATA = "UPDATE_APP_DATA",
18
- PROVIDER_RPC_RESPONSE = "PROVIDER_RPC_RESPONSE",
19
- PROVIDER_ON_EVENT = "PROVIDER_ON_EVENT"
20
- }
21
- export interface CowSwapWidgetProps {
22
- params: CowSwapWidgetParams;
23
- provider?: EthereumProvider;
24
- listeners?: CowWidgetEventListeners;
25
- }
26
- export interface JsonRpcRequest {
27
- id: number;
28
- method: string;
29
- params: unknown[];
30
- }
31
- export interface EthereumProvider {
32
- /**
33
- * Subscribes to Ethereum-related events.
34
- * @param event - The event to subscribe to.
35
- * @param args - Arguments for the event.
36
- */
37
- on(event: string, args: unknown): void;
38
- /**
39
- * Sends a JSON-RPC request to the Ethereum provider and returns the response.
40
- * @param params - JSON-RPC request parameters.
41
- * @returns A promise that resolves with the response.
42
- */
43
- request<T>(params: JsonRpcRequest): Promise<T>;
44
- }
45
- export type CowSwapTheme = 'dark' | 'light';
46
- /**
47
- *Trade asset parameters, for example:
48
- * { asset: 'WBTC', amount: 12 }
49
- * or
50
- * { asset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' } // USDC
51
- */
52
- interface TradeAsset {
53
- /** The asset symbol or identifier. */
54
- asset: string;
55
- /**
56
- * The amount of the asset (optional).
57
- * If specified, represents the quantity or value of the asset.
58
- */
59
- amount?: string;
60
- }
61
- export type ForcedOrderDeadline = FlexibleConfig<number>;
62
- export declare enum TradeType {
63
- SWAP = "swap",
64
- LIMIT = "limit",
65
- /**
66
- * Currently it means only TWAP orders.
67
- * But in the future it can be extended to support other order types.
68
- */
69
- ADVANCED = "advanced",
70
- YIELD = "yield"
71
- }
72
- /**
73
- * The partner fee
74
- */
75
- export interface PartnerFee {
76
- /**
77
- * The fee in basis points (BPS). One basis point is equivalent to 0.01% (1/100th of a percent)
78
- */
79
- bps: FlexibleConfig<number>;
80
- /**
81
- * The Ethereum address of the partner to receive the fee.
82
- */
83
- recipient: FlexibleConfig<string>;
84
- }
85
- /**
86
- * ERC-20 token information
87
- */
88
- export type TokenInfo = {
89
- chainId: number;
90
- address: string;
91
- name: string;
92
- decimals: number;
93
- symbol: string;
94
- logoURI?: string;
95
- };
96
- export declare const WIDGET_PALETTE_COLORS: readonly ["primary", "background", "paper", "text", "danger", "warning", "alert", "info", "success"];
97
- export type CowSwapWidgetPaletteColors = (typeof WIDGET_PALETTE_COLORS)[number];
98
- export type CowSwapWidgetPaletteParams = {
99
- [K in CowSwapWidgetPaletteColors]: string;
100
- };
101
- export type CowSwapWidgetPalette = {
102
- baseTheme: CowSwapTheme;
103
- } & CowSwapWidgetPaletteParams;
104
- export interface CowSwapWidgetSounds {
105
- /**
106
- * The sound to play when the order is executed. Defaults to world wide famous CoW Swap moooooooooo!
107
- * Alternatively, you can use a URL to a custom sound file, or set to null to disable the sound.
108
- */
109
- postOrder?: string | null;
110
- /**
111
- * The sound to play when the order is executed. Defaults to world wide famous CoW Swap happy moooooooooo!
112
- * Alternatively, you can use a URL to a custom sound file, or set to null to disable the sound.
113
- */
114
- orderExecuted?: string | null;
115
- /**
116
- * The sound to play when the order is executed. Defaults to world wide famous CoW Swap unhappy moooooooooo!
117
- * Alternatively, you can use a URL to a custom sound file, or set to null to disable the sound.
118
- */
119
- orderError?: string | null;
120
- }
121
- export interface CowSwapWidgetImages {
122
- /**
123
- * The image to display when the orders table is empty (no orders yet). It defaults to "Yoga CoW" image.
124
- * Alternatively, you can use a URL to a custom image file, or set to null to disable the image.
125
- */
126
- emptyOrders?: string | null;
127
- }
128
- export interface CowSwapWidgetContent {
129
- feeLabel?: string;
130
- feeTooltipMarkdown?: string;
131
- }
132
- export interface SlippageConfig {
133
- /** Minimum slippage in basis points (e.g., 10 = 0.1%) */
134
- min?: number;
135
- /** Maximum slippage in basis points (e.g., 5000 = 50%) - 5000 is max value for dApp */
136
- max?: number;
137
- /** Default slippage value in basis points (e.g., 50 = 0.5%) - min <= defaultValue <= max */
138
- defaultValue?: number;
139
- }
140
- export type FlexibleSlippageConfig = FlexibleConfig<SlippageConfig>;
141
- export interface CowSwapWidgetParams {
142
- /**
143
- * The unique identifier of the widget consumer.
144
- * Please fill the for to let us know a little about you: https://cowprotocol.typeform.com/to/rONXaxHV
145
- */
146
- appCode: string;
147
- /**
148
- * The width of the widget in pixels. Default: 400px
149
- */
150
- width?: string;
151
- /**
152
- * The height of the widget in pixels. Default: 600px
153
- */
154
- height?: string;
155
- /**
156
- * The maximum height of the widget in pixels. Default: body.offsetHeight
157
- */
158
- maxHeight?: number;
159
- /**
160
- * Network ID.
161
- */
162
- chainId?: SupportedChainId;
163
- /**
164
- * An id of a network to bridge the output token.
165
- */
166
- targetChainId?: number;
167
- /**
168
- * The token lists urls to use in the widget
169
- */
170
- tokenLists?: string[];
171
- /**
172
- * Swap, Limit or Advanced (Twap).
173
- */
174
- tradeType?: TradeType;
175
- /**
176
- * The base url of the widget implementation
177
- * The parameter can have the URL directly, or an object with the environment property,
178
- * The base URL will default to the production environment if not specified, so it will use https://swap.cow.fi by default.
179
- */
180
- baseUrl?: string;
181
- /**
182
- * Sell token, and optionally the amount.
183
- */
184
- sell?: TradeAsset;
185
- /**
186
- * Buy token, and optionally the amount.
187
- */
188
- buy?: TradeAsset;
189
- /**
190
- * Forced order deadline in minutes. When set, user's won't be able to edit the deadline.
191
- *
192
- * Either a single value applied to each individual order type accordingly or an optional individual value per order type.
193
- *
194
- * The app will use the appropriated min/max value per order type.
195
- */
196
- forcedOrderDeadline?: ForcedOrderDeadline;
197
- /**
198
- * Enables the ability to switch between trade types in the widget.
199
- */
200
- enabledTradeTypes?: TradeType[];
201
- /**
202
- * The partner fee
203
- *
204
- * Please contact https://cowprotocol.typeform.com/to/rONXaxHV
205
- */
206
- partnerFee?: PartnerFee;
207
- /**
208
- * Disables cross-chain swaps (bridging)
209
- * Defaults to false.
210
- */
211
- disableCrossChainSwap?: boolean;
212
- /**
213
- * Disables showing the confirmation modal you get after posting an order.
214
- * Defaults to false.
215
- */
216
- disablePostedOrderConfirmationModal?: boolean;
217
- /**
218
- * Disables showing the progress bar after a SWAP order is placed.
219
- * The SWAP progress bar offers a transparent view into CoW Protocol's unique solution finding mechanism.
220
- * If you wish to not show it, set `disableProgressBar` to `true`.
221
- *
222
- * Defaults to false.
223
- */
224
- disableProgressBar?: boolean;
225
- /**
226
- * Disables showing the toast messages.
227
- * Some UI might want to disable it and subscribe to WidgetMethodsEmit.ON_TOAST_MESSAGE event to handle the toast messages itself.
228
- * Defaults to false.
229
- */
230
- disableToastMessages?: boolean;
231
- /**
232
- * Option to hide the logo in the widget.
233
- */
234
- hideLogo?: boolean;
235
- /**
236
- * Option to hide the network selector in the widget.
237
- */
238
- hideNetworkSelector?: boolean;
239
- /**
240
- * Option to hide bridge info
241
- */
242
- hideBridgeInfo?: boolean;
243
- /**
244
- * Option to hide orders table on LIMIT and TWAP forms.
245
- *
246
- * Warning! When `true`, users won't be able to see their LIMIT/TWAP order status or history, neither they'll be able to cancel active orders.
247
- */
248
- hideOrdersTable?: boolean;
249
- /**
250
- * Defines the widget mode.
251
- * - `true` (standalone mode): The widget is standalone, so it will use its own Ethereum provider. The user can connect from within the widget.
252
- * - `false` (dapp mode): The widget is embedded in a dapp which is responsible for providing the Ethereum provider. Therefore, there won't be a connect button in the widget as this should happen in the host app.
253
- *
254
- * Defaults to standalone.
255
- */
256
- standaloneMode?: boolean;
257
- /**
258
- * The theme of the widget UI.
259
- */
260
- theme?: CowSwapTheme | CowSwapWidgetPalette;
261
- /**
262
- * Customizable images for the widget.
263
- */
264
- images?: CowSwapWidgetImages;
265
- /**
266
- * Sounds configuration for the app.
267
- */
268
- sounds?: CowSwapWidgetSounds;
269
- /**
270
- * In case when widget does not support some tokens, you can provide a list of tokens to be used in the widget
271
- */
272
- customTokens?: TokenInfo[];
273
- /**
274
- * Customizable labels and content for the widget.
275
- */
276
- content?: CowSwapWidgetContent;
277
- /**
278
- * Customizable slippage settings for the widget.
279
- */
280
- slippage?: FlexibleSlippageConfig;
281
- }
282
- export interface WidgetMethodsEmitPayloadMap {
283
- [WidgetMethodsEmit.ACTIVATE]: void;
284
- [WidgetMethodsEmit.EMIT_COW_EVENT]: EmitCowEventPayload<CowWidgetEvents>;
285
- [WidgetMethodsEmit.UPDATE_HEIGHT]: UpdateWidgetHeightPayload;
286
- [WidgetMethodsEmit.SET_FULL_HEIGHT]: SetWidgetFullHeightPayload;
287
- [WidgetMethodsEmit.PROVIDER_RPC_REQUEST]: ProviderRpcRequestPayload;
288
- [WidgetMethodsEmit.INTERCEPT_WINDOW_OPEN]: WindowOpenPayload;
289
- }
290
- export interface WidgetMethodsListenPayloadMap {
291
- [WidgetMethodsListen.UPDATE_APP_DATA]: UpdateAppDataPayload;
292
- [WidgetMethodsListen.UPDATE_PARAMS]: UpdateParamsPayload;
293
- [WidgetMethodsListen.PROVIDER_RPC_RESPONSE]: ProviderRpcResponsePayload;
294
- [WidgetMethodsListen.PROVIDER_ON_EVENT]: ProviderOnEventPayload;
295
- }
296
- export type WidgetEventsPayloadMap = WidgetMethodsEmitPayloadMap & WidgetMethodsListenPayloadMap;
297
- export type WidgetMethodsEmitPayloads = WidgetMethodsEmitPayloadMap[WidgetMethodsEmit];
298
- export type WidgetMethodsListenPayloads = WidgetMethodsListenPayloadMap[WidgetMethodsListen];
299
- export type CowSwapWidgetAppParams = Omit<CowSwapWidgetParams, 'theme'>;
300
- export interface UpdateParamsPayload {
301
- urlParams: {
302
- pathname: string;
303
- search: string;
304
- };
305
- appParams: CowSwapWidgetAppParams;
306
- hasProvider: boolean;
307
- }
308
- export interface UpdateAppDataPayload {
309
- metaData?: {
310
- appCode: string;
311
- };
312
- }
313
- export interface UpdateWidgetHeightPayload {
314
- height?: number;
315
- }
316
- export interface SetWidgetFullHeightPayload {
317
- isUpToSmall?: boolean;
318
- }
319
- export interface EmitCowEventPayload<T extends CowWidgetEvents> {
320
- event: T;
321
- payload: CowWidgetEventPayloadMap[T];
322
- }
323
- export type WidgetMethodsEmitListener<T extends WidgetMethodsEmit> = T extends WidgetMethodsEmit ? {
324
- event: T;
325
- handler: WidgetMethodHandler<T>;
326
- } : never;
327
- export type WidgetMethodHandler<T extends WidgetMethodsEmit> = (payload: WidgetMethodsEmitPayloadMap[T]) => void;
328
- export interface ProviderRpcRequestPayload {
329
- rpcRequest: JsonRpcRequestMessage;
330
- }
331
- export interface WindowOpenPayload {
332
- href: string | URL;
333
- target: string;
334
- rel: string;
335
- }
336
- export interface JsonRpcRequestMessage {
337
- jsonrpc: '2.0';
338
- id?: number;
339
- method: string;
340
- params: unknown[];
341
- }
342
- export interface BaseJsonRpcResponseMessage {
343
- id: number;
344
- jsonrpc: '2.0';
345
- }
346
- export interface JsonRpcSucessfulResponseMessage<TResult = unknown> extends BaseJsonRpcResponseMessage {
347
- result: TResult;
348
- }
349
- export interface JsonRpcError<TData = unknown> {
350
- code: number;
351
- message: string;
352
- data?: TData;
353
- }
354
- export interface JsonRpcErrorResponseMessage<TErrorData = unknown> extends BaseJsonRpcResponseMessage {
355
- error: JsonRpcError<TErrorData>;
356
- }
357
- export type ProviderRpcResponsePayload = {
358
- rpcResponse: JsonRpcResponse;
359
- };
360
- export type JsonRpcResponse = JsonRpcRequestMessage | JsonRpcErrorResponseMessage | JsonRpcSucessfulResponseMessage;
361
- export interface ProviderOnEventPayload {
362
- event: string;
363
- params: unknown;
364
- }
365
- export type WindowListener = (event: MessageEvent<unknown>) => void;
package/urlUtils.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { CowSwapWidgetParams } from './types';
2
- export declare function buildWidgetUrl(params: Partial<CowSwapWidgetParams>): string;
3
- export declare function buildWidgetPath(params: Partial<CowSwapWidgetParams>): string;
4
- export declare function buildWidgetUrlQuery(params: Partial<CowSwapWidgetParams>): URLSearchParams;
@@ -1,3 +0,0 @@
1
- import { IframeTransport } from '@cowprotocol/iframe-transport';
2
- import { WidgetEventsPayloadMap } from './types';
3
- export declare const widgetIframeTransport: IframeTransport<WidgetEventsPayloadMap>;