@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/src/types.ts ADDED
@@ -0,0 +1,458 @@
1
+ import type { SupportedChainId } from '@cowprotocol/cow-sdk'
2
+ import { CowWidgetEventListeners, CowWidgetEventPayloadMap, CowWidgetEvents } from '@cowprotocol/events'
3
+
4
+ export type { SupportedChainId } from '@cowprotocol/cow-sdk'
5
+
6
+ export type PerTradeTypeConfig<T> = Partial<Record<TradeType, T>>
7
+
8
+ export type PerNetworkConfig<T> = Partial<Record<SupportedChainId, T>>
9
+
10
+ export type FlexibleConfig<T> =
11
+ | T
12
+ | PerNetworkConfig<T>
13
+ | PerTradeTypeConfig<T>
14
+ | PerTradeTypeConfig<PerNetworkConfig<T>>
15
+ | PerNetworkConfig<PerTradeTypeConfig<T>>
16
+
17
+ export enum WidgetMethodsEmit {
18
+ ACTIVATE = 'ACTIVATE',
19
+ UPDATE_HEIGHT = 'UPDATE_HEIGHT',
20
+ SET_FULL_HEIGHT = 'SET_FULL_HEIGHT',
21
+ EMIT_COW_EVENT = 'EMIT_COW_EVENT',
22
+ PROVIDER_RPC_REQUEST = 'PROVIDER_RPC_REQUEST',
23
+ INTERCEPT_WINDOW_OPEN = 'INTERCEPT_WINDOW_OPEN',
24
+ }
25
+
26
+ export enum WidgetMethodsListen {
27
+ UPDATE_PARAMS = 'UPDATE_PARAMS',
28
+ UPDATE_APP_DATA = 'UPDATE_APP_DATA',
29
+ PROVIDER_RPC_RESPONSE = 'PROVIDER_RPC_RESPONSE',
30
+ PROVIDER_ON_EVENT = 'PROVIDER_ON_EVENT',
31
+ }
32
+
33
+ export interface CowSwapWidgetProps {
34
+ params: CowSwapWidgetParams
35
+ provider?: EthereumProvider
36
+ listeners?: CowWidgetEventListeners
37
+ }
38
+
39
+ export interface JsonRpcRequest {
40
+ id: number
41
+ method: string
42
+ params: unknown[]
43
+ }
44
+
45
+ // https://eips.ethereum.org/EIPS/eip-1193
46
+ export interface EthereumProvider {
47
+ /**
48
+ * Subscribes to Ethereum-related events.
49
+ * @param event - The event to subscribe to.
50
+ * @param args - Arguments for the event.
51
+ */
52
+ on(event: string, args: unknown): void
53
+
54
+ /**
55
+ * Sends a JSON-RPC request to the Ethereum provider and returns the response.
56
+ * @param params - JSON-RPC request parameters.
57
+ * @returns A promise that resolves with the response.
58
+ */
59
+ request<T>(params: JsonRpcRequest): Promise<T>
60
+ }
61
+
62
+ export type CowSwapTheme = 'dark' | 'light'
63
+
64
+ /**
65
+ *Trade asset parameters, for example:
66
+ * { asset: 'WBTC', amount: 12 }
67
+ * or
68
+ * { asset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' } // USDC
69
+ */
70
+ interface TradeAsset {
71
+ /** The asset symbol or identifier. */
72
+ asset: string
73
+ /**
74
+ * The amount of the asset (optional).
75
+ * If specified, represents the quantity or value of the asset.
76
+ */
77
+ amount?: string
78
+ }
79
+
80
+ export type ForcedOrderDeadline = FlexibleConfig<number>
81
+
82
+ export enum TradeType {
83
+ SWAP = 'swap',
84
+ LIMIT = 'limit',
85
+ /**
86
+ * Currently it means only TWAP orders.
87
+ * But in the future it can be extended to support other order types.
88
+ */
89
+ ADVANCED = 'advanced',
90
+ YIELD = 'yield',
91
+ }
92
+
93
+ /**
94
+ * The partner fee
95
+ */
96
+ export interface PartnerFee {
97
+ /**
98
+ * The fee in basis points (BPS). One basis point is equivalent to 0.01% (1/100th of a percent)
99
+ */
100
+ bps: FlexibleConfig<number>
101
+
102
+ /**
103
+ * The Ethereum address of the partner to receive the fee.
104
+ */
105
+ recipient: FlexibleConfig<string>
106
+ }
107
+
108
+ /**
109
+ * ERC-20 token information
110
+ */
111
+ export type TokenInfo = {
112
+ chainId: number
113
+ address: string
114
+ name: string
115
+ decimals: number
116
+ symbol: string
117
+ logoURI?: string
118
+ }
119
+
120
+ export const WIDGET_PALETTE_COLORS = [
121
+ 'primary',
122
+ 'background',
123
+ 'paper',
124
+ 'text',
125
+ 'danger',
126
+ 'warning',
127
+ 'alert',
128
+ 'info',
129
+ 'success',
130
+ ] as const
131
+
132
+ export type CowSwapWidgetPaletteColors = (typeof WIDGET_PALETTE_COLORS)[number]
133
+
134
+ export type CowSwapWidgetPaletteParams = { [K in CowSwapWidgetPaletteColors]: string }
135
+
136
+ export type CowSwapWidgetPalette = { baseTheme: CowSwapTheme } & CowSwapWidgetPaletteParams
137
+
138
+ export interface CowSwapWidgetSounds {
139
+ /**
140
+ * The sound to play when the order is executed. Defaults to world wide famous CoW Swap moooooooooo!
141
+ * Alternatively, you can use a URL to a custom sound file, or set to null to disable the sound.
142
+ */
143
+ postOrder?: string | null
144
+
145
+ /**
146
+ * The sound to play when the order is executed. Defaults to world wide famous CoW Swap happy moooooooooo!
147
+ * Alternatively, you can use a URL to a custom sound file, or set to null to disable the sound.
148
+ */
149
+ orderExecuted?: string | null
150
+
151
+ /**
152
+ * The sound to play when the order is executed. Defaults to world wide famous CoW Swap unhappy moooooooooo!
153
+ * Alternatively, you can use a URL to a custom sound file, or set to null to disable the sound.
154
+ */
155
+ orderError?: string | null
156
+ }
157
+
158
+ export interface CowSwapWidgetImages {
159
+ /**
160
+ * The image to display when the orders table is empty (no orders yet). It defaults to "Yoga CoW" image.
161
+ * Alternatively, you can use a URL to a custom image file, or set to null to disable the image.
162
+ */
163
+ emptyOrders?: string | null
164
+ }
165
+
166
+ export interface CowSwapWidgetContent {
167
+ feeLabel?: string
168
+ feeTooltipMarkdown?: string
169
+ }
170
+
171
+ export interface SlippageConfig {
172
+ /** Minimum slippage in basis points (e.g., 10 = 0.1%) */
173
+ min?: number
174
+ /** Maximum slippage in basis points (e.g., 5000 = 50%) - 5000 is max value for dApp */
175
+ max?: number
176
+ /** Default slippage value in basis points (e.g., 50 = 0.5%) - min <= defaultValue <= max */
177
+ defaultValue?: number
178
+ }
179
+
180
+ export type FlexibleSlippageConfig = FlexibleConfig<SlippageConfig>
181
+
182
+ export interface CowSwapWidgetParams {
183
+ /**
184
+ * The unique identifier of the widget consumer.
185
+ * Please fill the for to let us know a little about you: https://cowprotocol.typeform.com/to/rONXaxHV
186
+ */
187
+ appCode: string
188
+
189
+ /**
190
+ * The width of the widget in pixels. Default: 400px
191
+ */
192
+ width?: string
193
+ /**
194
+ * The height of the widget in pixels. Default: 600px
195
+ */
196
+ height?: string
197
+
198
+ /**
199
+ * The maximum height of the widget in pixels. Default: body.offsetHeight
200
+ */
201
+ maxHeight?: number
202
+
203
+ /**
204
+ * Network ID.
205
+ */
206
+ chainId?: SupportedChainId
207
+
208
+ /**
209
+ * An id of a network to bridge the output token.
210
+ */
211
+ targetChainId?: number
212
+
213
+ /**
214
+ * The token lists urls to use in the widget
215
+ */
216
+ tokenLists?: string[]
217
+
218
+ /**
219
+ * Swap, Limit or Advanced (Twap).
220
+ */
221
+ tradeType?: TradeType
222
+
223
+ /**
224
+ * The base url of the widget implementation
225
+ * The parameter can have the URL directly, or an object with the environment property,
226
+ * The base URL will default to the production environment if not specified, so it will use https://swap.cow.fi by default.
227
+ */
228
+ baseUrl?: string
229
+
230
+ /**
231
+ * Sell token, and optionally the amount.
232
+ */
233
+ sell?: TradeAsset
234
+
235
+ /**
236
+ * Buy token, and optionally the amount.
237
+ */
238
+ buy?: TradeAsset
239
+
240
+ /**
241
+ * Forced order deadline in minutes. When set, user's won't be able to edit the deadline.
242
+ *
243
+ * Either a single value applied to each individual order type accordingly or an optional individual value per order type.
244
+ *
245
+ * The app will use the appropriated min/max value per order type.
246
+ */
247
+ forcedOrderDeadline?: ForcedOrderDeadline
248
+
249
+ /**
250
+ * Enables the ability to switch between trade types in the widget.
251
+ */
252
+ enabledTradeTypes?: TradeType[]
253
+
254
+ /**
255
+ * The partner fee
256
+ *
257
+ * Please contact https://cowprotocol.typeform.com/to/rONXaxHV
258
+ */
259
+ partnerFee?: PartnerFee
260
+
261
+ /**
262
+ * Disables cross-chain swaps (bridging)
263
+ * Defaults to false.
264
+ */
265
+ disableCrossChainSwap?: boolean
266
+ /**
267
+ * Disables showing the confirmation modal you get after posting an order.
268
+ * Defaults to false.
269
+ */
270
+ disablePostedOrderConfirmationModal?: boolean
271
+
272
+ /**
273
+ * Disables showing the progress bar after a SWAP order is placed.
274
+ * The SWAP progress bar offers a transparent view into CoW Protocol's unique solution finding mechanism.
275
+ * If you wish to not show it, set `disableProgressBar` to `true`.
276
+ *
277
+ * Defaults to false.
278
+ */
279
+ disableProgressBar?: boolean
280
+
281
+ /**
282
+ * Disables showing the toast messages.
283
+ * Some UI might want to disable it and subscribe to WidgetMethodsEmit.ON_TOAST_MESSAGE event to handle the toast messages itself.
284
+ * Defaults to false.
285
+ */
286
+ disableToastMessages?: boolean
287
+
288
+ /**
289
+ * Option to hide the logo in the widget.
290
+ */
291
+ hideLogo?: boolean
292
+
293
+ /**
294
+ * Option to hide the network selector in the widget.
295
+ */
296
+ hideNetworkSelector?: boolean
297
+
298
+ /**
299
+ * Option to hide bridge info
300
+ */
301
+ hideBridgeInfo?: boolean
302
+
303
+ /**
304
+ * Option to hide orders table on LIMIT and TWAP forms.
305
+ *
306
+ * 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.
307
+ */
308
+ hideOrdersTable?: boolean
309
+
310
+ /**
311
+ * Defines the widget mode.
312
+ * - `true` (standalone mode): The widget is standalone, so it will use its own Ethereum provider. The user can connect from within the widget.
313
+ * - `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.
314
+ *
315
+ * Defaults to standalone.
316
+ */
317
+ standaloneMode?: boolean
318
+
319
+ /**
320
+ * The theme of the widget UI.
321
+ */
322
+ theme?: CowSwapTheme | CowSwapWidgetPalette
323
+
324
+ /**
325
+ * Customizable images for the widget.
326
+ */
327
+ images?: CowSwapWidgetImages
328
+
329
+ /**
330
+ * Sounds configuration for the app.
331
+ */
332
+ sounds?: CowSwapWidgetSounds
333
+
334
+ /**
335
+ * In case when widget does not support some tokens, you can provide a list of tokens to be used in the widget
336
+ */
337
+ customTokens?: TokenInfo[]
338
+
339
+ /**
340
+ * Customizable labels and content for the widget.
341
+ */
342
+ content?: CowSwapWidgetContent
343
+
344
+ /**
345
+ * Customizable slippage settings for the widget.
346
+ */
347
+ slippage?: FlexibleSlippageConfig
348
+ }
349
+
350
+ // Define types for event payloads
351
+ export interface WidgetMethodsEmitPayloadMap {
352
+ [WidgetMethodsEmit.ACTIVATE]: void
353
+ [WidgetMethodsEmit.EMIT_COW_EVENT]: EmitCowEventPayload<CowWidgetEvents>
354
+ [WidgetMethodsEmit.UPDATE_HEIGHT]: UpdateWidgetHeightPayload
355
+ [WidgetMethodsEmit.SET_FULL_HEIGHT]: SetWidgetFullHeightPayload
356
+ [WidgetMethodsEmit.PROVIDER_RPC_REQUEST]: ProviderRpcRequestPayload
357
+ [WidgetMethodsEmit.INTERCEPT_WINDOW_OPEN]: WindowOpenPayload
358
+ }
359
+
360
+ export interface WidgetMethodsListenPayloadMap {
361
+ [WidgetMethodsListen.UPDATE_APP_DATA]: UpdateAppDataPayload
362
+ [WidgetMethodsListen.UPDATE_PARAMS]: UpdateParamsPayload
363
+ [WidgetMethodsListen.PROVIDER_RPC_RESPONSE]: ProviderRpcResponsePayload
364
+ [WidgetMethodsListen.PROVIDER_ON_EVENT]: ProviderOnEventPayload
365
+ }
366
+
367
+ export type WidgetEventsPayloadMap = WidgetMethodsEmitPayloadMap & WidgetMethodsListenPayloadMap
368
+
369
+ export type WidgetMethodsEmitPayloads = WidgetMethodsEmitPayloadMap[WidgetMethodsEmit]
370
+ export type WidgetMethodsListenPayloads = WidgetMethodsListenPayloadMap[WidgetMethodsListen]
371
+
372
+ export type CowSwapWidgetAppParams = Omit<CowSwapWidgetParams, 'theme'>
373
+
374
+ export interface UpdateParamsPayload {
375
+ urlParams: {
376
+ pathname: string
377
+ // Contains theme and other query params
378
+ search: string
379
+ }
380
+ appParams: CowSwapWidgetAppParams
381
+ hasProvider: boolean
382
+ }
383
+
384
+ export interface UpdateAppDataPayload {
385
+ metaData?: {
386
+ appCode: string
387
+ }
388
+ }
389
+
390
+ export interface UpdateWidgetHeightPayload {
391
+ height?: number
392
+ }
393
+
394
+ export interface SetWidgetFullHeightPayload {
395
+ isUpToSmall?: boolean
396
+ }
397
+
398
+ export interface EmitCowEventPayload<T extends CowWidgetEvents> {
399
+ event: T
400
+ payload: CowWidgetEventPayloadMap[T]
401
+ }
402
+
403
+ export type WidgetMethodsEmitListener<T extends WidgetMethodsEmit> = T extends WidgetMethodsEmit
404
+ ? { event: T; handler: WidgetMethodHandler<T> }
405
+ : never
406
+
407
+ export type WidgetMethodHandler<T extends WidgetMethodsEmit> = (payload: WidgetMethodsEmitPayloadMap[T]) => void
408
+
409
+ export interface ProviderRpcRequestPayload {
410
+ rpcRequest: JsonRpcRequestMessage
411
+ }
412
+
413
+ export interface WindowOpenPayload {
414
+ href: string | URL
415
+ target: string
416
+ rel: string
417
+ }
418
+
419
+ export interface JsonRpcRequestMessage {
420
+ jsonrpc: '2.0'
421
+ // Optional in the request.
422
+ id?: number
423
+ method: string
424
+ params: unknown[]
425
+ }
426
+
427
+ export interface BaseJsonRpcResponseMessage {
428
+ // Required but null if not identified in request
429
+ id: number
430
+ jsonrpc: '2.0'
431
+ }
432
+
433
+ export interface JsonRpcSucessfulResponseMessage<TResult = unknown> extends BaseJsonRpcResponseMessage {
434
+ result: TResult
435
+ }
436
+
437
+ export interface JsonRpcError<TData = unknown> {
438
+ code: number
439
+ message: string
440
+ data?: TData
441
+ }
442
+
443
+ export interface JsonRpcErrorResponseMessage<TErrorData = unknown> extends BaseJsonRpcResponseMessage {
444
+ error: JsonRpcError<TErrorData>
445
+ }
446
+
447
+ export type ProviderRpcResponsePayload = {
448
+ rpcResponse: JsonRpcResponse
449
+ }
450
+
451
+ export type JsonRpcResponse = JsonRpcRequestMessage | JsonRpcErrorResponseMessage | JsonRpcSucessfulResponseMessage
452
+
453
+ export interface ProviderOnEventPayload {
454
+ event: string
455
+ params: unknown
456
+ }
457
+
458
+ export type WindowListener = (event: MessageEvent<unknown>) => void
@@ -0,0 +1,88 @@
1
+ import { TradeType } from './types'
2
+ import { buildWidgetUrl } from './urlUtils'
3
+
4
+ const chainId = 1
5
+ const tradeType = TradeType.SWAP
6
+
7
+ // TODO: fix these tests! uncommenting to unblock a hotfix
8
+ // TODO: Break down this large function into smaller functions
9
+
10
+ describe.skip('buildWidgetUrl', () => {
11
+ describe('env', () => {
12
+ it('local', () => {
13
+ const url = buildWidgetUrl({ chainId, tradeType, baseUrl: 'http://localhost:3000' })
14
+ expect(url).toEqual('http://localhost:3000/#/1/widget/swap/?')
15
+ })
16
+ it('prod', () => {
17
+ const url = buildWidgetUrl({ chainId, tradeType, baseUrl: 'https://swap.cow.fi' })
18
+ expect(url).toEqual('https://swap.cow.fi/#/1/widget/swap/?')
19
+ })
20
+ })
21
+
22
+ describe('chainId', () => {
23
+ it('mainnet', () => {
24
+ const url = buildWidgetUrl({ chainId: 1, tradeType })
25
+ expect(url).toEqual('https://swap.cow.fi/#/1/widget/swap/?')
26
+ })
27
+ it('gnosis chain', () => {
28
+ const url = buildWidgetUrl({ chainId: 100, tradeType })
29
+ expect(url).toEqual('https://swap.cow.fi/#/100/widget/swap/?')
30
+ })
31
+ })
32
+
33
+ describe('theme', () => {
34
+ it('dark', () => {
35
+ const url = buildWidgetUrl({ theme: 'dark', chainId, tradeType })
36
+ expect(url).toEqual('https://swap.cow.fi/#/1/widget/swap/?theme=dark')
37
+ })
38
+ it('light', () => {
39
+ const url = buildWidgetUrl({ theme: 'light', chainId, tradeType })
40
+ expect(url).toEqual('https://swap.cow.fi/#/1/widget/swap/?theme=light')
41
+ })
42
+ })
43
+
44
+ describe('trade assets', () => {
45
+ it('without amounts', () => {
46
+ const url = buildWidgetUrl({
47
+ sell: { asset: 'WETH' },
48
+ buy: { asset: 'COW' },
49
+ chainId,
50
+ tradeType,
51
+ })
52
+ expect(url).toEqual('https://swap.cow.fi/#/1/widget/swap/WETH/COW?')
53
+ })
54
+
55
+ it('with sell amount', () => {
56
+ const url = buildWidgetUrl({
57
+ sell: { asset: 'DAI', amount: '0.1' },
58
+ buy: { asset: 'USDC' },
59
+ chainId,
60
+ tradeType,
61
+ })
62
+ expect(url).toEqual('https://swap.cow.fi/#/1/widget/swap/DAI/USDC?sellAmount=0.1')
63
+ })
64
+
65
+ it('with buy amount', () => {
66
+ const url = buildWidgetUrl({
67
+ sell: { asset: 'DAI' },
68
+ buy: { asset: 'USDC', amount: '0.1' },
69
+ chainId,
70
+ tradeType,
71
+ })
72
+ expect(url).toEqual('https://swap.cow.fi/#/1/widget/swap/DAI/USDC?buyAmount=0.1')
73
+ })
74
+ })
75
+
76
+ describe('all config', () => {
77
+ it('dark', () => {
78
+ const url = buildWidgetUrl({
79
+ chainId: 100,
80
+ tradeType,
81
+ theme: 'light',
82
+ sell: { asset: 'DAI', amount: '0.1' },
83
+ buy: { asset: 'USDC', amount: '0.1' },
84
+ })
85
+ expect(url).toEqual('https://swap.cow.fi/#/100/widget/swap/DAI/USDC?sellAmount=0.1&buyAmount=0.1&theme=light')
86
+ })
87
+ })
88
+ })
@@ -0,0 +1,66 @@
1
+ import { isCowSwapWidgetPalette } from './themeUtils'
2
+ import { CowSwapWidgetParams, TradeType } from './types'
3
+
4
+ const EMPTY_TOKEN = '_'
5
+
6
+ export function buildWidgetUrl(params: Partial<CowSwapWidgetParams>): string {
7
+ const host = typeof params.baseUrl === 'string' ? params.baseUrl : 'https://swap.cow.fi'
8
+ const path = buildWidgetPath(params)
9
+
10
+ return host + '/#' + path + '?' + buildWidgetUrlQuery(params)
11
+ }
12
+
13
+ export function buildWidgetPath(params: Partial<CowSwapWidgetParams>): string {
14
+ const { chainId = 1, sell, buy, tradeType = TradeType.SWAP } = params
15
+
16
+ const assetsPath = [sell?.asset || EMPTY_TOKEN, buy?.asset || EMPTY_TOKEN].map(encodeURIComponent).join('/')
17
+
18
+ return `/${chainId}/widget/${tradeType}/${assetsPath}`
19
+ }
20
+
21
+ export function buildWidgetUrlQuery(params: Partial<CowSwapWidgetParams>): URLSearchParams {
22
+ const query = new URLSearchParams()
23
+
24
+ return addTargetChainIdToQuery(addThemePaletteToQuery(addTradeAmountsToQuery(query, params), params), params)
25
+ }
26
+
27
+ function addTradeAmountsToQuery(query: URLSearchParams, params: Partial<CowSwapWidgetParams>): URLSearchParams {
28
+ const { sell, buy } = params
29
+
30
+ if (sell?.amount) {
31
+ query.append('sellAmount', sell.amount)
32
+ }
33
+
34
+ if (buy?.amount) {
35
+ query.append('buyAmount', buy.amount)
36
+ }
37
+
38
+ return query
39
+ }
40
+
41
+ function addThemePaletteToQuery(query: URLSearchParams, params: Partial<CowSwapWidgetParams>): URLSearchParams {
42
+ const theme = params.theme
43
+
44
+ if (!theme) {
45
+ query.append('palette', 'null')
46
+ return query
47
+ }
48
+
49
+ if (isCowSwapWidgetPalette(theme)) {
50
+ query.append('palette', encodeURIComponent(JSON.stringify(theme)))
51
+ query.append('theme', theme.baseTheme)
52
+ } else {
53
+ query.append('palette', 'null')
54
+ query.append('theme', theme)
55
+ }
56
+
57
+ return query
58
+ }
59
+
60
+ function addTargetChainIdToQuery(query: URLSearchParams, params: Partial<CowSwapWidgetParams>): URLSearchParams {
61
+ if (params.targetChainId) {
62
+ query.append('targetChainId', params.targetChainId.toString())
63
+ }
64
+
65
+ return query
66
+ }
@@ -0,0 +1,5 @@
1
+ import { IframeTransport } from '@cowprotocol/iframe-transport'
2
+
3
+ import { WidgetEventsPayloadMap } from './types'
4
+
5
+ export const widgetIframeTransport = new IframeTransport<WidgetEventsPayloadMap>('cowSwapWidget')
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "forceConsistentCasingInFileNames": true,
6
+ "strict": true,
7
+ "noImplicitOverride": true,
8
+ "noPropertyAccessFromIndexSignature": true,
9
+ "noImplicitReturns": true,
10
+ "noFallthroughCasesInSwitch": true
11
+ },
12
+ "files": [],
13
+ "include": [],
14
+ "references": [
15
+ {
16
+ "path": "./tsconfig.lib.json"
17
+ },
18
+ {
19
+ "path": "./tsconfig.spec.json"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "declaration": true,
6
+ "types": ["node"]
7
+ },
8
+ "include": ["src/**/*.ts"],
9
+ "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"]
10
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"]
7
+ },
8
+ "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts", "src/lib/widget.ts"]
9
+ }
@@ -1,10 +0,0 @@
1
- import { CowWidgetEventListeners } from '@cowprotocol/events';
2
- export declare class IframeCowEventEmitter {
3
- private contentWindow;
4
- private eventEmitter;
5
- private listeners;
6
- private widgetListener;
7
- constructor(contentWindow: Window, listeners?: CowWidgetEventListeners);
8
- stopListeningIframe(): void;
9
- updateListeners(listeners?: CowWidgetEventListeners): void;
10
- }
@@ -1,8 +0,0 @@
1
- export declare class IframeSafeSdkBridge {
2
- private appWindow;
3
- private iframeWidow;
4
- forwardSdkMessage: (event: MessageEvent<unknown>) => void;
5
- constructor(appWindow: Window, iframeWidow: Window);
6
- private startListening;
7
- stopListening(): void;
8
- }
@@ -1,18 +0,0 @@
1
- import { CowWidgetEventListeners } from '@cowprotocol/events';
2
- import { CowSwapWidgetParams, CowSwapWidgetProps, EthereumProvider } from './types';
3
- /**
4
- * Callback function signature for updating the CoW Swap Widget.
5
- */
6
- export interface CowSwapWidgetHandler {
7
- updateParams: (params: CowSwapWidgetParams) => void;
8
- updateListeners: (newListeners?: CowWidgetEventListeners) => void;
9
- updateProvider: (newProvider?: EthereumProvider) => void;
10
- destroy: () => void;
11
- }
12
- /**
13
- * Generates and injects a CoW Swap Widget into the provided container.
14
- * @param container - The HTML element to inject the widget into.
15
- * @param params - Parameters for configuring the widget.
16
- * @returns A callback function to update the widget with new settings.
17
- */
18
- export declare function createCowSwapWidget(container: HTMLElement, props: CowSwapWidgetProps): CowSwapWidgetHandler;